Jim*_*mmy 4 mapbox mapbox-gl-js
我从 Mapbox 中获取了这个演示:
https://docs.mapbox.com/mapbox-gl-js/example/hover-styles/
Run Code Online (Sandbox Code Playgroud)
我放入我自己的 GeoJson 文件来替换演示文件,代码在这里:
https://codepen.io/hiven/pen/rNYdvdg?editors=1112
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
Error: The feature id parameter must be provided.
Run Code Online (Sandbox Code Playgroud)
我无法理解这是什么意思,因为此代码段中提供了功能 ID:
map.addLayer({
'id': 'state-borders',
'type': 'line',
'source': 'states',
'layout': {},
'paint': {
'line-color': '#627BC1',
'line-width': 2
}
});
Run Code Online (Sandbox Code Playgroud)
jsc*_*tro 15
您必须添加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
});
Run Code Online (Sandbox Code Playgroud)