gpt4 book ai didi

click - 使标记可拖动和可点击

转载 作者:行者123 更新时间:2023-12-04 14:18:13 24 4
gpt4 key购买 nike

我有一个矢量图层,用于在我的 map 上将标记显示为特征,但是现在我所做的,它们是可拖动或可点击的。我该怎么做才能得到两者?

/*** 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();

最佳答案

我没有测试它,但不会像这样的工作吗?

var dragged = false;
var dragFeature = new OpenLayers.Control.DragFeature(layerTrackMarker, {
onComplete: function(){
if(dragged){
dragCallback();
}else{
clickCallback();
}
},
onStart: function(){
dragged = false;
},
onDrag: function(){
dragged = true;
}
});
map.addControl(dragFeature);
dragFeature.activate();

编辑:如果没有实际阻力,onComplete 不会触发。这是工作代码
var dragged = false;
var dragFeature = new OpenLayers.Control.DragFeature(pointLayer, {
onStart: function(){dragged = false;},
onDrag: function() {dragged = true;}
});

map.addControl(dragFeature);
dragFeature.activate();

map.events.register("mouseup", map , function(e){
if(dragged == true){
alert("dragged");
}else{
alert("clicked");
}
});

jsFiddle: http://jsfiddle.net/reKRr/5/

编辑:这是这样做的不那么hacky的方式
var selectFeature = new OpenLayers.Control.SelectFeature(
pointLayer,
{
onSelect: function(){
alert("selected");
}
}
);

var dragFeature = new OpenLayers.Control.DragFeature(pointLayer, {
onComplete: function(){
alert("drag");
}
});

dragFeature.handlers['drag'].stopDown = false;
dragFeature.handlers['drag'].stopUp = false;
dragFeature.handlers['drag'].stopClick = false;
dragFeature.handlers['feature'].stopDown = false;
dragFeature.handlers['feature'].stopUp = false;
dragFeature.handlers['feature'].stopClick = false;

map.addControls([selectFeature,dragFeature]);

selectFeature.activate();
dragFeature.activate();

关于click - 使标记可拖动和可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6953907/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com