Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapbox Feature ID parameter missing

I took this demo from mapbox:

https://docs.mapbox.com/mapbox-gl-js/example/hover-styles/

I put in my own GeoJson file in replacement of the demo one, the code is here:

https://codepen.io/hiven/pen/rNYdvdg?editors=1112

The error I get is:

Error: The feature id parameter must be provided.

I can't understand what this is saying, as a feature ID is provided here in this snippet:

   map.addLayer({
        'id': 'state-borders',
        'type': 'line',
        'source': 'states',
        'layout': {},
        'paint': {
            'line-color': '#627BC1',
            'line-width': 2
        }
    });
like image 420
Jimmy Avatar asked Jun 08 '26 13:06

Jimmy


1 Answers

You have to add generateId: true to your addSource method params.

map.addSource('states', {
            'type': 'geojson',
            'data': 'https://hiven.github.io/map2/hexagons.geojson',                         
            'generateId': true //This ensures that all features have unique IDs           
        });
like image 119
jscastro Avatar answered Jun 10 '26 11:06

jscastro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!