Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone,

How can i clear drawing manager and allow user to draw one polygon at once

My code goes here

C#
$(".PolygonAdd").click(function (e) {
             var drawingManager = new google.maps.drawing.DrawingManager({
                 drawingMode: google.maps.drawing.OverlayType.POLYGON,
                 drawingControl: false,
                 drawingControlOptions: {
                     position: google.maps.ControlPosition.TOP_RIGHT,
                     drawingModes: [google.maps.drawing.OverlayType.POLYGON]
                 },
                 polygonOptions: {
                     id: "New Polygon",
                     fillColor: #1EA448,
                     fillOpacity: 0.3,
                     strokeColor: #1EA448,
                     strokeOpacity: 0.6,
                     strokeWeight: 4,
                     clickable: true,
                     zIndex: 1,
                     editable: true
                 }
             });

             drawingManager.setMap(map);
             google.maps.event.addListener(drawingManager, 'overlaycomplete', function (e) {
                 if (e.type != google.maps.drawing.OverlayType.MARKER) {
                     drawingManager.setDrawingMode(null);
                     //drawingManager.setOptions({
                     //    drawingControl: false
                     //});
                 }
                 NewPolygon = e.overlay;
                 NewPolygon.type = e.type;
                 Polygons[0] = NewPolygon;
                 google.maps.event.addListener(NewPolygon, 'click', function () {
                     setSelection(this);
                 });

                 drawingManager.setDrawingMode(null);
             });
         });&lt;/pre&gt;</pre>



If i click "PolygonAdd" multiple times, I can able to draw polygon multiple times with the tool but this should not happen.

I should able to reset drawing manager. How Can i do this??? Please help me with this

Thanks in advance....
Posted
Updated 4-Dec-14 18:00pm
v2
Comments
Kornfeld Eliyahu Peter 4-Dec-14 5:26am    
This may help you: https://developers.google.com/maps/documentation/javascript/examples/polyline-remove
07405 4-Dec-14 5:34am    
It doesn't work... It is not the concept of removing polygon, I just don't want to draw multiple polygons at a time. I want to clear drawing manager once polygon is completed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900