开发者

OpenLayers: mixing fixed and draggable features

开发者 https://www.devze.com 2023-03-28 04:51 出处:网络
I\'m trying to create an OpenLayers UI with two basic capabilities: there are fixed features on the map, and users get additional information on the page (not popups on the map) when they hover over

I'm trying to create an OpenLayers UI with two basic capabilities:

  • there are fixed features on the map, and users get additional information on the page (not popups on the map) when they hover over a fixed feature;

  • there is one draggable reference point, which a user can move around the map.

I've currently got each of these working independently. I have two vector layers, one for fixed features and one for the draggable feature. The first layer has a OL.Control.SelectFeature control with {hover:true}, the second has a OL.Control.DragFeature control. However, when I enable the DragFeature control, the SelectFeature control no longer gets any events when I mouse over the fixed features. Conversely, if I raise the z-index of the fixed-features layer (as suggested here) the draggable feature cannot be dragged. That suggests that only the topmost layer is available to user interaction.

I assume I'm making a fairly basic mistake here. How do I allow the user to interact with the features on two layers? Or, alternatively, is there a better way of designing the user experience I outllned above?

The other alternative I can see is that I put both types of feature on one layer, and somehow prevent the fixed features from responding to drag interaction. However, looking through the OpenLayers API, I can't see any obvious way of getti开发者_高级运维ng the DragFeature control to abandon a drag interaction once intiated by the user.


OK, found a solution to this: the SelectFeature control needs to be attached to both layers, and the hover event handler then checks to see if the feature is selectable. The draggable feature remains on a separate layer, so it is the only draggable object. This posting was helpful in figuring out the answer.

0

精彩评论

暂无评论...
验证码 换一张
取 消