【发布时间】:2017-04-29 08:01:57
【问题描述】:
我正在尝试在 ol3 考虑单击事件以移动事件之前设置一个限制像素,代码见下文。我做错了,因为我的代码无法再拖动地图了。
window.app = {};
app.Drag = function() {
ol.interaction.Pointer.call(this, {
handleDownEvent: app.Drag.prototype.handleDownEvent,
handleUpEvent: app.Drag.prototype.handleUpEvent
});
}
ol.inherits(app.Drag, ol.interaction.Pointer);
app.Drag.prototype.handleDownEvent = function(evt) {
app.toD=evt.pixel;
console.log('Down');
return true;
};
app.Drag.prototype.handleUpEvent = function(evt) {
app.toU=evt.pixel;
console.log('up');
delta=Math.sqrt(Math.pow(Math.abs(app.toU[0]-app.toD[0]),2)+Math.pow(Math.abs(app.toU[1]-app.toD[1]),2))
if (delta<10) {
console.log('Click event');
var event = document.createEvent("MouseEvents");
event.initMouseEvent("click", true, true, window,0, app.toD[0], app.toD[1], app.toD[0], app.toD[1], false, false, false, false, 0, null);
map.dispatchEvent(event.initMouseEvent);
}
console.log(delta);
};
map.getInteractions().extend([new app.Drag()])
提前感谢您的帮助。
【问题讨论】:
标签: openlayers-3 drag threshold