在Google Map API v3中如何区分鼠标左键和右键点击mousedown事件 [英] How to distinguish between left and right mouse click on mousedown event in Google Map API v3
问题描述
Google Map API v3的mousedown事件在左右两侧被触发,我怎样才能确定它是右键单击还是左键单击。
我是新的谷歌地图API,我到现在为止使用虚拟地球API,我可以区分鼠标左键和右键点击,如e.leftMouseButton返回true,如果它是左键点击。
mousedown
简单地使用点击
。对于右键点击事件,您可以通过这种方式捕获右键点击
事件:
google.maps.event.addListener(map,rightclick,function(event){
/ *做点右键点击* /
});
要区分使用 mousedown
事件,您可以使用 event.which
参数。但为此,应该将处理程序添加到DOM元素(画布)中,因为Google API不会在事件对象中提供
选项。
var c = document.getElementById('map-canvas');
google.maps.event.addDomListener(c,mousedown,function(e){
if(e.which === 1){
$(#click))。 text(Left click);
} else if(e.which === 2){
$(#click)。text(Middle click);
} (e.which === 3){
$(#click)。text(right click);
}
});
The mousedown event of Google Map API v3 gets fired on left and right click both, how can I identify whether it is right click or left click.
I am new to Google Map API, I was using Virtual Earth API until now, where I was able to distinguish between left and right mouse click on mouse down like e.leftMouseButton returns true if it is left click.
Instead of mousedown
use simply click
.
For right click event you can catch rightclick
event this way:
google.maps.event.addListener(map, "rightclick", function(event) {
/* do something on right click */
});
To distinguish what button was pressed using mousedown
event you can use event.which
parameter. But for that, the handler should be added to DOM element (canvas), since Google API doesn't provide which
option in event object.
var c = document.getElementById('map-canvas');
google.maps.event.addDomListener(c, "mousedown", function (e) {
if (e.which === 1) {
$("#click").text("Left click");
} else if (e.which === 2) {
$("#click").text("Middle click");
} else if (e.which === 3) {
$("#click").text("Right click");
}
});
这篇关于在Google Map API v3中如何区分鼠标左键和右键点击mousedown事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!