1
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'
});

Its not clear to me how I can check if map has completed rendering. The above code will give error while still rendering the map.

enter image description here

4

1 回答 1

1

Found answer from another stackoverflow mapbox question.

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'
});

Not sure but I think mapbox should check it instead in there queryRenderedFeatures.

https://github.com/mapbox/mapbox-gl-js/issues/2614

EDIT: Mapbox changed their code no longer a problem :)

于 2016-05-23T21:31:49.287 回答