简体   繁体   English

OpenLayers悬停时高亮显示功能,然后单击选择

[英]OpenLayers highlight feature on hover and select on click

I'm using OpenLayers to display a map and to provide some drawing features. 我正在使用OpenLayers来显示地图并提供一些绘图功能。 I also added two SelectFeatures to the vector layer I want to draw on. 我还向要绘制的矢量层添加了两个SelectFeatures。 One for highlighting a drawn feature by hover it and one for selecting a feature by clicking on it. 一种用于通过悬停突出显示绘制的特征,另一种用于通过单击选择特征。
I used this example to realize this. 我用这个例子来实现这一点。

The problem is, that this solution doesn't really work (even in the given example). 问题是,该解决方案实际上无法工作(即使在给定的示例中)。
If I draw a new feature I can highlight it by putting the cursor on it but can't select it with a click. 如果我绘制了一个新功能,则可以通过将光标放在它上来突出显示它,但是不能单击选择它。 (Same in the example, the given features work fine, but after drawing a new one the select-by-click function doesn't react anymore) (在示例中相同,给定的功能可以正常工作,但是在绘制了一个新功能之后,按一下选择功能不再起作用)

Is there any alternative solution to realize this except the official example? 除了官方示例,是否还有其他解决方案可以实现这一目标?

此示例 4个月前进行了修改 ,由于描述的混乱,排除了编辑工具栏。

I was able to get something like this working. 我能够得到类似的工作。 You need to activate the controls in a specific order: 您需要按特定顺序激活控件:

highlightControl.activate();
selectControl.activate();
dragControl.activate();

Hover events aren't handled by the Drag and Pan Controller, so they try the select controller, which doesn't use them either, passing them up to the highlight controller. 悬停事件不是由“拖放”控制器处理的,因此它们尝试不使用它们的select控制器,将它们传递给高亮控制器。 Similarly, click events aren't handled by the drag controller, but are handled by the select controller. 同样,点击事件不是由拖动控制器处理的,而是由选择控制器处理的。 Finally, drag events are dealt with by the drag controller. 最后,拖动事件由拖动控制器处理。 The last to be activated is the first to be "consulted". 最后激活的是第一个被“咨询”的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM