map.on('mousemove', function (e) {
map.getCanvas().style.cursor = ''
// Need to check if markers layer is ready to query else
// I get Type error the first few seconds when you move the mouse.
var features = map.queryRenderedFeatures(e.point, {layers: ['markers']})
if (!features.length) return;
map.getCanvas().style.cursor = 'pointer'
});
我不清楚如何检查地图是否已完成渲染。上面的代码在渲染地图时会出错。
答案 0 :(得分:1)
从另一个stackoverflow mapbox问题找到答案。
map.on('mousemove', function (e) {
if (!map.loaded()) return;
map.getCanvas().style.cursor = ''
var features = map.queryRenderedFeatures(e.point, {layers: ['markers']})
if (!features.length) return;
map.getCanvas().style.cursor = 'pointer'
});
不确定,但我认为mapbox应该在queryRenderedFeatures中检查它。
https://github.com/mapbox/mapbox-gl-js/issues/2614
编辑:Mapbox更改了他们的代码不再是一个问题:)