vue-mapbox icon indicating copy to clipboard operation
vue-mapbox copied to clipboard

How to reload layers after style change?

Open edanweis opened this issue 6 years ago • 1 comments

When map style is changed, layers are removed (even with clearSource: false option) and the new style loads without the previous layer. Geojson features do not display, despite their sources remaining.

mapbox-gl.js?e192:29 Error: The layer 'my-layer' does not exist in the map's style and cannot be queried for features.

Should there be a layer method for reload? Only remove, and move exist currently.

edanweis avatar Oct 22 '19 06:10 edanweis

In case anyone comes across this problem, my workaround:

if(!this.map.getLayer('my-layer-name')){
	this.map.addLayer({
		...this.myLayer,
		id: 'my-layer-name', 
		source: this.geojsonSource
	})
}

edanweis avatar Oct 22 '19 06:10 edanweis