diff --git a/src/components/VMapbox.vue b/src/components/VMapbox.vue
index 117d14e..f313702 100644
--- a/src/components/VMapbox.vue
+++ b/src/components/VMapbox.vue
@@ -14,6 +14,7 @@
diff --git a/src/components/v-mapbox-layer.js b/src/components/v-mapbox-layer.js
index c3a67d7..99039b9 100644
--- a/src/components/v-mapbox-layer.js
+++ b/src/components/v-mapbox-layer.js
@@ -1,7 +1,7 @@
export default {
name: 'v-mapbox-layer',
- inject: ['getMap'],
+ inject: [ 'getMapMethods' ],
render: () => null,
@@ -10,71 +10,44 @@ export default {
type: Object,
default: () => ({})
},
-
- // Allows to place a layer before another
before: {
type: String,
default: undefined
}
},
- data: () => ({
- isInitialized: false
- }),
-
methods: {
- deferredMountedTo() {
- if(!this.isInitialized) {
- this.renderLayer();
- this.isInitialized = true;
- }
- },
-
- renderLayer() {
- this.removeLayer();
- this.addLayer();
- },
-
addLayer() {
- const map = this.getMap();
- map.addLayer(this.options, this.before);
+ const mapMethods = this.getMapMethods()
+ mapMethods.addLayer(this.options, this.before)
},
removeLayer() {
- const map = this.getMap();
- if(map) {
- const layerId = this.options.id;
- const layer = map.getLayer(layerId);
- if(layer) {
- const layerSource = layer.source;
- map.removeLayer(layerId);
- if(layerSource && !map.getStyle().layers.some(({ source }) => source === layerSource)) {
- map.removeSource(layerSource);
- }
- }
- }
+ const mapMethods = this.getMapMethods()
+ const layerId = this.options.id
+ mapMethods.removeLayer(layerId)
+ },
+
+ updateLayer() {
+ const mapMethods = this.getMapMethods()
+ mapMethods.updateLayer(this.options)
},
},
mounted() {
- const map = this.getMap();
- // We can immediately initialize if we have the map ready
- if(map && map.isStyleLoaded()) {
- this.renderLayer();
- this.isInitialized = true;
- }
+ this.addLayer()
},
destroyed() {
- this.removeLayer();
+ this.removeLayer()
},
watch: {
options: {
deep: true,
handler() {
- this.renderLayer();
+ this.updateLayer()
}
}
}
-};
+}
diff --git a/src/stories/index.stories.js b/src/stories/index.stories.js
index f204a02..4d9a2d1 100644
--- a/src/stories/index.stories.js
+++ b/src/stories/index.stories.js
@@ -160,10 +160,10 @@ const sortingTemplate = `
style="height: 300px;"
:center="[0, 0]"
>
-
-
+
+
`
diff --git a/src/utils/helpers.js b/src/utils/helpers.js
new file mode 100644
index 0000000..0cc758e
--- /dev/null
+++ b/src/utils/helpers.js
@@ -0,0 +1 @@
+export const uniqueInArrayById = (arr1, arr2) => arr1.filter(({ id }) => !arr2.some(el => el.id === id))