You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by matthalstead October 17, 2023
I would like to be able to add and remove GeoJSON layers dynamically, initially I thought I could represent each of the layers I want to work with in either an array of layers or as specific explicitly defined layers within the <Maplibre> element.
This works ok for rendering them and then hiding them based on an update to the layers defined in data, but when I add one back in, e.g. set data.layer_1 back to a Geo JSON object, I get the following error:
style.ts:773 Uncaught (in promise) Error: Source "layer_1" already exists.
at ae.addSource (style.ts:773:19)
at Ua.Map.addSource (map.ts:1928:20)
at $$self.$$.update (GeoJSON.svelte:22:10)
at init (Component.js:144:5)
at new GeoJSON (GeoJSON.svelte:58:31)
at create_if_block_2 (Map.svelte:47:56)
at Object.update [as p] (Map.svelte:46:25)
at update_slot_base (utils.js:203:8)
at Object.update [as p] (MapLibre.svelte:208:26)
at Object.update [as p] (MapLibre.svelte:207:30)
I suspect that I need to remove GeoJSON layers through an API call instead to a bound map instance, but I don't seem to be able to find out how. Are there any examples of dynamically adding and removing layers?
The text was updated successfully, but these errors were encountered:
dimfeld
changed the title
Dynamic update of GeoJSON layers
Sources not properly torn down
Oct 18, 2023
Discussed in #86
Originally posted by matthalstead October 17, 2023
I would like to be able to add and remove GeoJSON layers dynamically, initially I thought I could represent each of the layers I want to work with in either an array of layers or as specific explicitly defined layers within the
<Maplibre>
element.e.g.
or (which I am using at the moment - the following contains the whole script,
data
is provided by the parent through props)This works ok for rendering them and then hiding them based on an update to the layers defined in
data
, but when I add one back in, e.g. setdata.layer_1
back to a Geo JSON object, I get the following error:I suspect that I need to remove GeoJSON layers through an API call instead to a bound map instance, but I don't seem to be able to find out how. Are there any examples of dynamically adding and removing layers?
The text was updated successfully, but these errors were encountered: