mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

addSource geojson with "null" data renders previous geojson

Open pomm0 opened this issue 1 year ago • 0 comments

mapbox-gl-js version: 3.7.0

browser: Chrome for Linux: Version 129.0.6668.100 (Official Build) (64-bit)

Steps to Trigger Behavior

  1. Add valid mapbox access token to jsfiddle
  2. See the orange polygon which gets initialized with geojson data and is rendered properly. Script will remove and add the source + layer every couple of seconds with geojson data null:

https://github.com/user-attachments/assets/3ef19542-3094-4944-8aa8-fdf77701742c

Adding a empty featureCollection instead of null is behaving as expected:

map.addSource('my-source', {
   type: 'geojson',
   data: data ?? {
      type: 'FeatureCollection',
      features: []
   }
});

https://github.com/user-attachments/assets/418554cc-08b1-4ad7-bf28-149503e2f5c5

Should passing null as data work?

Link to Demonstration

https://jsfiddle.net/ogy2xwsc/

Expected Behavior

It renders nothing, since passed geojson data is null.

Actual Behavior

It renders previous existing geojson.

pomm0 avatar Oct 15 '24 09:10 pomm0