Polygon events on google maps with javascript

0

I need to capture the event of DWELL , ENTER , LEAVE of the polygons, and you can add them to the map with the following code:

this.map.addPolygon({
    points: geofence,
    strokeColor: '#FF0000',
    strokeOpacity: 0.8,
    strokeWeight: 2,
    fillColor: '#FF0000',
    fillOpacity: 0.35,
    draggable: true,
    geodesic: true
});

Now I am not able to add to listen to incoming, outgoing and moving events within this area.

How to do this ??

I use the most recent version of google maps or v3 . It is being developed in ionic 3

I basically need to do this

link

no javascript

    
asked by anonymous 10.01.2018 / 16:59

1 answer

0

To add events to a polygon, you can save the reference to the polygon and assign an event using addListener

For example:

var polygonCoords = [
    {lat: 25.774, lng: -80.190},
    {lat: 18.466, lng: -66.118},
    {lat: 32.321, lng: -64.757},
    {lat: 25.774, lng: -80.190}
];

//Guarda a referencia ao polígono.
var polygon = new google.maps.Polygon({
   paths: polygonCoords,
   strokeColor: '#FF0000',
   strokeOpacity: 0.8,
   strokeWeight: 2,
   fillColor: '#FF0000',
   fillOpacity: 0.35
}); 

//EVENTO
polygon.addListener('mouseout', function() {
   //Faça algo aqui
})

Full example link: click here

I used the mouseout event as an example. Here at link you can identify all possible events:

    
12.01.2018 / 13:45