Google.maps.event.trigger does not start when a map is reloaded

I have a project using Google maps api v3, and I use google.maps.event.triggerto call or launch the listener that is created when the map loads. In this case, I install the listener when I click on the polygon, so when I click on the polygon, the corresponding window opens and is google.maps.event.triggerinstalled on another function block in the same javascript file. It works well when the entire web program restarts. But when I reload the map, or the map is reinitialized with a polygon with the same variable object, the syntax google.maps.event.triggerdoes not start. This is my function that usesgoogle.maps.event.trigger

 function callInfoPoly(nomor){
    alert(polygon[nomor].getPath().getAt(0));
    google.maps.event.trigger(polygon[nomor], "click");
    }

the warning works well, this means that the variable contains a polygon object, but google.maps.event.triggerdoes not start.

+1
source share
1 answer

When you look at the console after starting the click, you will see an error message:

Uncaught TypeError: Cannot read property 'vertex' of undefined 

This undefined object is a PolyMouseEvent . This object will be passed to the click callback when a real click occurs. But when you start the click programmatically, this object is missing, which causes the error above (and somehow stops the binding of the click listener after reinitializing the map).

: pass an empty object as an argument for a click callback when soft pressed:

google.maps.event.trigger(polygon[nomor], "click", {});

Demo: http://jsfiddle.net/doktormolle/jVFN2/

+7
source

Source: https://habr.com/ru/post/1536530/


All Articles