我在查找爲什麼mouseover
事件對mapbox gl不起作用時遇到了一些麻煩。似乎無法讓mouseover事件與mapbox一起工作
map.on('load', function() {
var geoJson = '{
"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": [
{
"type": "Feature",
"properties": {
...
},
"geometry": {
"type": "Point",
"coordinates": [
-118.6059,
34.1829
]
}
}]
}';
map.addSource('someData', {
type: 'geojson',
data: geoJson,
cluster: true,
clusterMaxZoom: 14
});
map.addLayer({
'id': 'unclustered-markers',
'type': 'symbol',
'source': 'someData',
'layout': {
'icon-image': 'circle-11'
}
});
});
使部件工作,座標顯示在集羣內的地圖上。但是,當我嘗試mouseover
事件時,沒有任何反應。
map.on('mouseover',function(e) {
console.log(e); // nothing is logged when I hover over the map or the points
var features = map.queryRenderedFeatures(e.point, { layers: ['unclustered-markers'] });
...
});
如果我改變事件click
那麼該事件被記錄到控制檯當我點擊地圖上。
哦哇哇哈哈感謝您指出了!我不敢相信我做到了。出於某種原因,我一直在觀察或考慮鼠標懸停....謝謝 –
嚴格地說,'mousemove'與'mouseover'不一樣。 –