2016-05-23 9 views
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' 
}); 

マップがレンダリングを完了したかどうかを確認する方法がわかりません。上記のコードはマップをレンダリングしている間にエラーを返します。別のstackoverflowのmapboxの質問から答えを見つけmapがqueryRenderedFeaturesの準備が整っているかチェックしてください。

enter image description here

答えて

1

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

EDIT:Mapboxは、もはや問題:)

を自分のコードを変更しません
関連する問題