使标记可拖动和可点击
我有一个矢量图层,用于将标记显示为地图上的要素,但现在我所做的,它们是可拖动或可单击的。我该怎么做才能同时获得两者?
/*** Init Drag Marker
*/
var dragFeature = new OpenLayers.Control.DragFeature(layerTrackMarker,
{'onComplete': updateMarker}
);
map.addControl(dragFeature);
dragFeature.activate();
/*** Init Click Marker
*/
var clickFeature = new OpenLayers.Control.SelectFeature(layerTrackMarker,
{}
);
map.addControl(clickFeature);
layerTrackMarker.events.on({
"featureselected": function(e) {
var markerId = e.feature.geometry.id;
removeMarker(markerId);
/* ToDo: show context menu */
},
"featureunselected": function(e) {
/* ToDo: hide context menu */
}
});
clickFeature.activate();
I have a vector-layer for displaying markers as features on my map, but now mather, what I do, they are eighter draggable or clickable. What can I do to get both?
/*** Init Drag Marker
*/
var dragFeature = new OpenLayers.Control.DragFeature(layerTrackMarker,
{'onComplete': updateMarker}
);
map.addControl(dragFeature);
dragFeature.activate();
/*** Init Click Marker
*/
var clickFeature = new OpenLayers.Control.SelectFeature(layerTrackMarker,
{}
);
map.addControl(clickFeature);
layerTrackMarker.events.on({
"featureselected": function(e) {
var markerId = e.feature.geometry.id;
removeMarker(markerId);
/* ToDo: show context menu */
},
"featureunselected": function(e) {
/* ToDo: hide context menu */
}
});
clickFeature.activate();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有测试过,但是这样的东西行不通吗?
编辑:如果没有实际拖动,则 onComplete 不会触发。这是jsFiddle的工作代码
: http://jsfiddle.net/reKRr/5/
编辑:这是不那么老套的做法
I didn't test it, but wouldn't something like this work?
Edit: onComplete doesn't fire if there was no actual drag. Here's the working code
jsFiddle: http://jsfiddle.net/reKRr/5/
EDIT: this is the less hacky way of doing it