Skip to content

Commit b979d19

Browse files
authored
Merge pull request #1 from johnarban/allow-parent-to-add-layers-directly
provide methods of adding layers to the map.
2 parents b18ac58 + 1b8cd8a commit b979d19

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/components/LocationSelector.vue

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const defaultMapOptions: MapOptions = {
4444
4545
export default defineComponent({
4646
47-
emits: ["place", "update:modelValue", "error"],
47+
emits: ["place", "update:modelValue", "error", "mapReady"],
4848
4949
props: {
5050
activatorColor: {
@@ -122,6 +122,11 @@ export default defineComponent({
122122
geoJsonFiles: {
123123
type: Array as PropType<GeoJSONProp[]>,
124124
default: () => []
125+
},
126+
127+
layers: {
128+
type: Array as PropType<L.Layer[]>,
129+
default: () => []
125130
}
126131
},
127132
@@ -264,6 +269,7 @@ export default defineComponent({
264269
265270
map.attributionControl.setPrefix('<a href="https://leafletjs.com" title="A JavaScript library for interactive maps" target="_blank" rel="noopener noreferrer" >Leaflet</a>');
266271
272+
this.layers.forEach((layer) => layer.addTo(map));
267273
// show the geojson files
268274
this.geoJsonFiles.forEach((geojsonrecord) => {
269275
const url = geojsonrecord.url;
@@ -300,12 +306,26 @@ export default defineComponent({
300306
});
301307
302308
this.map = map;
309+
310+
this.$emit('mapReady');
303311
},
304312
305313
updateValue(value: LocationDeg) {
306314
this.$emit('update:modelValue', value);
307315
},
308316
317+
addLayerToMap(leafletObject: L.Layer) {
318+
if (this.map) {
319+
leafletObject.addTo(this.map as Map);
320+
}
321+
},
322+
323+
removeLayerFromMap(leafletObject: L.Layer) {
324+
if (this.map) {
325+
leafletObject.removeFrom(this.map as Map);
326+
}
327+
},
328+
309329
updateCircle() {
310330
if (this.map) {
311331
this.selectedCircle?.remove();

0 commit comments

Comments
 (0)