使用军械测量/Openlayers API拖动标记 [英] Dragging markers with Ordnance Survey/Openlayers api

查看:119
本文介绍了使用军械测量/Openlayers API拖动标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个网站链接文本使用基于OpenLayers的Ordnance Survey(我认为这称为OpenSpace)产生的api.我已经准备好了,因此您可以单击地图以添加标记,然后我希望能够单击标记并将其拖动到地图周围.是否有使用OpenSpace或OpenLayers api做到这一点的简单方法.

I've created a site link text using the api produced by the Ordnance Survey (I think this is called OpenSpace) which is based on OpenLayers. I've got it so you can click on the map to add a marker and I want to then be able to click on the markers and drag it around the map. Is there a simple way to do this using either the OpenSpace or OpenLayers apis.

推荐答案

OpenLayers api允许您将标记和要素添加到地图.如果您添加功能而不是标记,则可以通过添加以下代码使它们可拖动.

The OpenLayers api allows you to add Markers and Features to the map. If you add Features rather than Markers you can make them draggable by adding the following code.

var vectorLayer = new OpenLayers.Layer.Vector("Vector Layer");
var osMap = new OpenSpace.Map('map');
osMap.addLayer(vectorLayer);

var modifyFeaturesControl = new OpenLayers.Control.ModifyFeature(vectorLayer);
modifyFeaturesControl.mode = OpenLayers.Control.ModifyFeature.RESHAPE;
osMap.addControl(modifyFeaturesControl);
modifyFeaturesControl.activate();

这将允许您在地图上拖动要素.如果要在拖动功能时添加自定义行为,可以在vectorLayer上注册侦听器.例如,在修改(拖动和释放)功能后注册侦听器,您需要使用以下代码.

This will allow you to drag features around a map. If you want to add custom behavior when feature's are dragged you can register listeners on the vectorLayer. For example to register a listener when features are modifed (i.e. dragged and released) you need to use the following code.

vectorLayer.events.register('featuremodified', vectorLayer, function(feature) {
   //custom behavior
});

有关可以收听以查看OpenLayers api doc的事件的完整列表,请参见

For a full list of the events that can be listened to see the OpenLayers api doc OpenLayers api doc

这篇关于使用军械测量/Openlayers API拖动标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆