我在查找为什么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'不一样。 –