我有10到15个不同的层,例如汽车、总线、路线等,如果需要的话,我在地图上添加动态的etc.These层,因为所有的层都不存在于地图上。
因此,我显示的信息在单一点击有关层,但我希望当我悬停鼠标在图层上改变鼠标指针样式为‘十字’。
我在鼠标中心事件上写了更改游标样式,但它有时看起来很有效,有时即使鼠标在层上悬停,但光标样式没有改变。
First way:
map.on('mouseenter', (e: any) => {
self.mapInstance.getCanvas().style.cursor = 'crosshair';
});
第二条路:
map.on('mouseenter',(e: any) => {
var features = map.queryRenderedFeatures(e.point,{ layers: ['Car',"Bus"] });
//error let's say any layer still on exist on map
if(features.length)
map.getCanvas().style.cursor = 'crosshair';
});
我的问题
如何获得鼠标悬停在不同层上的光标的更改样式?
发布于 2019-12-05 21:56:31
map.on('mouseenter', 'clusters', () => {
map.getCanvas().style.cursor = 'pointer'
})
map.on('mouseleave', 'clusters', () => {
map.getCanvas().style.cursor = ''
})
这就是如何让它特别地与cluser一起工作,但是代码可能仍然有帮助。
祝你好运!
发布于 2021-05-04 12:40:09
map.on("mouseenter", layer.id, () => {
map.getCanvas().style.cursor = "pointer";
});
map.on("mouseleave", shape.id, () => {
map.getCanvas().style.cursor = "default";
});
您可以向每个层添加自定义事件,例如单击。鼠标事件也是如此。
发布于 2019-04-07 22:16:23
穆斯莫夫怎么样?
//一些填充,因为这样至少需要30个字符才能发布.
https://stackoverflow.com/questions/55560489
复制相似问题