Javascript 地图盒GeoJson标记在缩放更改时消失
我有一套大约750个制造商将显示在Mapbox上,样式设置为“此处”地图。问题是,在样式从常规单色更改为自定义“此处”样式后,标记现在在任何屏幕事件中都会消失,无论是缩放、移动还是模式拖动 标记都不见了。因为我们处理了很多标记,所以将它们呈现为HTML元素(它们不会消失)并不具有性能 我使用react map gl实现映射,但使用原始函数添加标记,使用geoJSON。我在下面附上了呈现标记的代码Javascript 地图盒GeoJson标记在缩放更改时消失,javascript,reactjs,maps,mapbox,geojson,Javascript,Reactjs,Maps,Mapbox,Geojson,我有一套大约750个制造商将显示在Mapbox上,样式设置为“此处”地图。问题是,在样式从常规单色更改为自定义“此处”样式后,标记现在在任何屏幕事件中都会消失,无论是缩放、移动还是模式拖动 标记都不见了。因为我们处理了很多标记,所以将它们呈现为HTML元素(它们不会消失)并不具有性能 我使用react map gl实现映射,但使用原始函数添加标记,使用geoJSON。我在下面附上了呈现标记的代码 function renderMarkers() { let accumulator: an
function renderMarkers() {
let accumulator: any = []
markers.forEach((marker: MarkerInfo, index: number) => {
accumulator.push({
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [
marker.lng,
marker.lat
]
},
'properties': {
'title': `mapbox-${index}`
}
})
})
let map = mapRef
if (map && map.current) {
map = map.current.getMap()
map.on('load', function () {
map.loadImage('https://docs.mapbox.com/mapbox-gl-js/assets/custom_marker.png', (error: any, image: any) => {
if (error) throw error;
map.addImage('custom-marker', image);
map.addSource('points', {
'type': 'geojson',
'data': {
'type': 'FeatureCollection',
'features': accumulator
}
});
map.addLayer({
'id': 'points',
'type': 'symbol',
'source': 'points',
'layout': {
'icon-image': 'custom-marker',
"icon-size": 0.6,
"icon-allow-overlap": true,
}
});
})
})
}
}
对于贴图渲染,它使用样式设置为bellow的基本react map gl贴图渲染
{
'version': 8,
'sources': {
'raster-tiles': {
'type': 'raster',
'tiles': [
`https://2.base.maps.ls.hereapi.com/maptile/2.1/maptile/newest/${mapStyle}/{z}/{x}/{y}/512/png8?apiKey=${hereApiKey}&ppi=320`
],
'tileSize': 256,
}
},
'layers': [
{
'id': 'simple-tiles',
'type': 'raster',
'source': 'raster-tiles',
'minzoom': 0,
'maxzoom': 22
}
]
}