我不知道 API 提供的可能性。
如果您必须处理多个事件(并且需要在 API 调用中跳过它们),另一种解决方案可能是在 API 调用之前禁用所有事件(从而删除它们)并在 API 调用完成后重新启用它们。
看看我的示例代码:
<!DOCTYPE html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map_canvas {
margin: 0;
padding: 0;
height: 100%;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
function initialize() {
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(51.518998, -0.148315),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
var changeListener;
function handleMapChange() {
console.log("Handle map change done by user!");
}
function zoomOut(mouseEvent) {
// disable all events that should not get fired
disableUserEvents();
// do API call
map.setZoom(map.getZoom() - 1);
// re-enable temporary disabled events when API operation finished
google.maps.event.addListenerOnce(map, "idle", enableUserEvents);
}
function disableUserEvents() {
console.log("disable User Events");
google.maps.event.removeListener(changeListener);
changeListener = undefined;
}
function enableUserEvents() {
console.log("enable User Events");
changeListener = google.maps.event.addListener(map, "idle", handleMapChange);
}
// enable user triggered events
enableUserEvents();
// the following rightclick listener will trigger an API call (zoomOut)
google.maps.event.addListener(map, "rightclick", zoomOut);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map_canvas"></div>
</body>