Question

I have setup the Drawing Manager, and I can easily draw polygon using it. Now I want to add a Info-box on this drawn polygon. I used the below code, but it seems it's not working as no Info-box results.

    drawingManager.setMap(map);
    google.maps.event.addListener(drawingManager, 'overlaycomplete', function(event) {
        if (event.type != google.maps.drawing.OverlayType.MARKER) {
            var reason = prompt("Please Mention the reason for this obstuction");
            var authority = prompt("Please Mention the authority involved");

            var infowindow = new google.maps.InfoWindow({
                content: reason + ", Raised by " + authority,
                width: "50px"
            });
            google.maps.event.addListener(event.overlay,'mouseover',function(){
                infowindow.open(map,event.overlay);
            });
            google.maps.event.addListener(event.overlay,'mouseout',function(){
                infowindow.close(map,event.overlay);
            });
        }
    });
Was it helpful?

Solution

Since, you are asking for Polygon. You do not have to use overlay object. You can directly use Polygon object to draw shapes as well as listen the polygon complete option.

Following is the demo which will enable you to draw polygon shape and will produce a infoWindow at the middle of the polygon shape which you have drawn.

Working Demo.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top