문제

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);
            });
        }
    });
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top