OpenLayers 3设置阻力图的敏感度 [英] openlayers 3 set sensitivity on drag map
本文介绍了OpenLayers 3设置阻力图的敏感度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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()])
提前感谢您的帮助。
推荐答案
我换了一种方式,对我有好处:
if(typeof limit=='undefined')limit=10;
map.on('pointerdown', function(evt){
console.log('down')
app.toD=evt.pixel;
})
map.on('pointerup', 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<limit) {
console.log('Click event');
var event = document.createEvent("MouseEvents");
var x= app.toD[0]+((app.toD[0]-app.toU[0])/2).toFixed(0);
var y= app.toD[1]+((app.toD[1]-app.toU[1])/2).toFixed(0);
event.initMouseEvent("click", true, true, window,0, x, y, x, y, false, false, false, false, 0, null);
event.pixel = [x, y];
map.dispatchEvent(event);
}
console.log(delta);
})
这篇关于OpenLayers 3设置阻力图的敏感度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文