After some recent update on google Maps Javascript V3 API, I noticed that contextmenu started being shown when i make a rightclick on a marker. Basically the code is
google.maps.event.addListener(marker, 'rightclick', function (event) {
foo(marker);
});
I have already tried the option
google.maps.event.addListener(marker, 'rightclick', function (event) {
deleteMarker(marker);
event.stop();
return false;
});
But the context menu still continue to appear. I also put this on the whole map
$("#map").contextmenu(function (e) {
e.preventDefault();
e.stopPropagation();
return false;
});
And, rightly, contextmenu doesn't appear when clicking on map. How can I stop if also on marker rightclick?
This is an example for the issue: /
After some recent update on google Maps Javascript V3 API, I noticed that contextmenu started being shown when i make a rightclick on a marker. Basically the code is
google.maps.event.addListener(marker, 'rightclick', function (event) {
foo(marker);
});
I have already tried the option
google.maps.event.addListener(marker, 'rightclick', function (event) {
deleteMarker(marker);
event.stop();
return false;
});
But the context menu still continue to appear. I also put this on the whole map
$("#map").contextmenu(function (e) {
e.preventDefault();
e.stopPropagation();
return false;
});
And, rightly, contextmenu doesn't appear when clicking on map. How can I stop if also on marker rightclick?
This is an example for the issue: https://jsfiddle/rnxLum5j/
Share Improve this question edited May 22, 2018 at 9:28 judian 4504 silver badges12 bronze badges asked Mar 3, 2018 at 21:58 emmea90emmea90 3574 silver badges10 bronze badges 1- Please provide a minimal reproducible example that demonstrates your issue. – geocodezip Commented Mar 4, 2018 at 5:29
3 Answers
Reset to default 4Had the same issue and solved it by deferring execution of showing dialog using timeout. In your fiddle change the google.maps.event.addListener to
google.maps.event.addListener(map, 'rightclick', function (ev) {
setTimeout(ShowContextMenuGoolge, 0, ContextMenu, ev);
});
I also have this problem.
I think this is a bug of google maps 'rightclick' event.
I tried to stop propagation and cancel bubbling, but DOM 'contextmenu' event still firing on the open 'context-menu' element!
My solution stopping the event from firing on the context menu element.
var mapCanvas = document.getElementById("map_canvas");
$(mapCanvas).on('contextmenu', '.custom-context-menu', function (e) {
e.stopPropagation();
e.preventDefault();
return false;
});
This is an example for the bug: https://jsfiddle/rnxLum5j/
At the end i solved disabling the context menu on the div in which the map was in instead of the map itself.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745048960a4608268.html
评论列表(0条)