admin管理员组文章数量:1277475
I'm using OpenLayers 2.13. I want to detect mousedown
, mousemove
, mouseup
events while mouse is over OpenLayers.Map
, so I wrote the following code.
var map = new OpenLayers.Map("map",{controls:[
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.ArgParser(),
new OpenLayers.Control.Attribution()
]});
var events = map.events;
events.register("mousedown",map,function(e){
console.log("mousedown");
});
events.register("mousemove",map,function(e){
console.log("mousemove");
});
events.register("mouseup",map,function(e){
console.log("mouseup");
});
As a result, mousemove
and mouseup
is detected but no mousedown
s.
It says here that mousemove
and mouseup
is supported but mousedown
is not. Is there any hacks I can apply to detect mousedown
events without modifying OpenLayers script?
I'm using OpenLayers 2.13. I want to detect mousedown
, mousemove
, mouseup
events while mouse is over OpenLayers.Map
, so I wrote the following code.
var map = new OpenLayers.Map("map",{controls:[
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.ArgParser(),
new OpenLayers.Control.Attribution()
]});
var events = map.events;
events.register("mousedown",map,function(e){
console.log("mousedown");
});
events.register("mousemove",map,function(e){
console.log("mousemove");
});
events.register("mouseup",map,function(e){
console.log("mouseup");
});
As a result, mousemove
and mouseup
is detected but no mousedown
s.
It says here that mousemove
and mouseup
is supported but mousedown
is not. Is there any hacks I can apply to detect mousedown
events without modifying OpenLayers script?
4 Answers
Reset to default 8Add the 4th argument as true
.
var events = map.events;
events.register("mousedown",map,function(e){
console.log("mousedown");
return true;
},true); // This argument is new
There are several event listeners already listening the mousedown
event. One of them will eat the event when [map drag start] is detected, so the mousedown
event will never reach the last listener.
Without the 4th argument, events.register()
will add the listener to the end of the event-listening chain. With the 4th argument, it will add it to the first.
There is also a registerPriority() which adds to the front of the list:
http://dev.openlayers/docs/files/OpenLayers/Events-js.html#OpenLayers.Events.registerPriority
if you using open layer API > 5 then us can use below code
map.on('pointerdown', function(){
console.log("mousedown");
});
Simple way to make it:
map.events.listeners.mousedown.unshift({
func: function(){
// code
}
});
本文标签: javascriptHow to get mousedown event on OpenLayersMapStack Overflow
版权声明:本文标题:javascript - How to get `mousedown` event on OpenLayers.Map? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741274849a2369670.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论