简体   繁体   English

如何在Openlayers 3中启用具有“选择”交互功能的“捕捉”

[英]How to enable “Snapping” with “Select” interaction in Openlayers 3

I've developed an application to support drawing something like lines or points and adding some tags on the map using OpenLayers 3. 我开发了一个应用程序来支持绘制线条或点之类的东西,并支持使用OpenLayers 3在地图上添加一些标签。

Many existing functions in OL3 enable me to draw and modify something. OL3中的许多现有功能使我能够绘制和修改某些内容。

But, when I select something I drew, I felt the need of a snapping function to make me select them more easily. 但是,当我选择绘制的内容时,我感到需要一种捕捉功能来使我更轻松地选择它们。

Unfortunately, current OL3 supports the snapping only for the drawing and modifying, like below: 不幸的是,当前的OL3仅支持绘图和修改的捕捉,如下所示:

var draw = ol.interaction.Draw({features: some_features});
var snap = ol.interaction.Snap({featrues: some_features});
map.addInteraction(draw);
map.addInteraction(snap);

Actually, I found that the snapping works by replacing ol.interaction.Draw to ol.interaction.Select , because I can select something I draw if I clicked points apart of them. 实际上,我发现捕捉可以通过将ol.interaction.Draw替换为ol.interaction.Select实现 ,因为如果单击分开的点,则可以选择绘制的东西。 But, the mouse pointer did not snap to them. 但是,鼠标指针没有锁定到它们。

So, How can I implement select interaction with snapping function in OL3? 那么,如何在OL3中实现具有捕捉功能的选择交互?


Added some codes to explain details. 添加了一些代码以解释详细信息。

See the link: https://jsfiddle.net/keltpower0/sej6z2q4/1/ 看到链接: https : //jsfiddle.net/keltpower0/sej6z2q4/1/

After you draw some lines, you should click the very point where lines are placed if you select those lines. 绘制一些线后,如果选择这些线,则应单击放置线的位置。

I want to more easily select those lines with snapping function, like, if I move the mouse pointer near lines, the pointer "automatically" snap to the lines 我想通过捕捉功能更轻松地选择那些行,例如,如果将鼠标指针移到行附近,则指针“自动”捕捉到行

Select with snapping sounds a bit weird to me. 选择带有响亮的声音对我来说有点奇怪。 What about using the hitTolerance option of the select interaction ? 如何使用选择交互的hitTolerance选项?

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

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