Skip to content

Commit

Permalink
feat: add Control component
Browse files Browse the repository at this point in the history
  • Loading branch information
imIfOu committed Jan 14, 2022
1 parent afa57c8 commit 30fa5b4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/components/control/Control.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script>
import L from 'leaflet';
import {onDestroy, getContext, setContext, onMount} from 'svelte';
export let position = 'topright';
export const getInstance = () => leafletControl;
let leafletControl;
let leafletControlContent;
const getMap = getContext(L.Map);
onMount(()=> {
leafletControl = L.control();
leafletControl.onAdd = () => leafletControlContent
leafletControl.addTo(getMap());
});
$: leafletControl && leafletControl.setPosition(position);
onDestroy(() => {
leafletControl.remove();
});
</script>

<div style="display: none">
<div bind:this={leafletControlContent}>
<slot/>
</div>
</div>
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Map from './components/Map.svelte';
import TileLayer from "./components/TileLayer.svelte";
import Control from "./components/control/Control.svelte";
import Zoom from "./components/control/Zoom.svelte";
import Scale from "./components/control/Scale.svelte";
import Layers from "./components/control/Layers.svelte";
Expand All @@ -23,6 +24,7 @@ import Polyline from "./components/vector/Polyline.svelte";
import Rectangle from "./components/vector/Rectangle.svelte";

export {
Control,
TileLayer,
Zoom,
Scale,
Expand Down

0 comments on commit 30fa5b4

Please sign in to comment.