缺少 Mapbox 要素 ID 参数
Mapbox Feature ID parameter missing
我从 mapbox 获取了这个演示:
https://docs.mapbox.com/mapbox-gl-js/example/hover-styles/
我用自己的 GeoJson 文件替换了演示文件,代码在这里:
https://codepen.io/hiven/pen/rNYdvdg?editors=1112
我得到的错误是:
Error: The feature id parameter must be provided.
我不明白这是什么意思,因为此代码段中提供了功能 ID:
map.addLayer({
'id': 'state-borders',
'type': 'line',
'source': 'states',
'layout': {},
'paint': {
'line-color': '#627BC1',
'line-width': 2
}
});
您必须将 generateId: true
添加到您的 addSource
方法参数中。
map.addSource('states', {
'type': 'geojson',
'data': 'https://hiven.github.io/map2/hexagons.geojson',
'generateId': true //This ensures that all features have unique IDs
});
我从 mapbox 获取了这个演示:
https://docs.mapbox.com/mapbox-gl-js/example/hover-styles/
我用自己的 GeoJson 文件替换了演示文件,代码在这里:
https://codepen.io/hiven/pen/rNYdvdg?editors=1112
我得到的错误是:
Error: The feature id parameter must be provided.
我不明白这是什么意思,因为此代码段中提供了功能 ID:
map.addLayer({
'id': 'state-borders',
'type': 'line',
'source': 'states',
'layout': {},
'paint': {
'line-color': '#627BC1',
'line-width': 2
}
});
您必须将 generateId: true
添加到您的 addSource
方法参数中。
map.addSource('states', {
'type': 'geojson',
'data': 'https://hiven.github.io/map2/hexagons.geojson',
'generateId': true //This ensures that all features have unique IDs
});