Menu
Close

Draw Editable Polygon

Sample Implementation

    
      
      <html>
        <head>
          <title>Draw Editable Polygon</title>
          <meta name="viewport" content="initial-scale=1.0">
          <meta charset="utf-8">
          <style>
          html,
          body,
          #map {
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100vh;
          }
          </style>
               <script src="https://apis.mappls.com/advancedmaps/api/<Token>/map_sdk?layer=vector&v=3.0&polydraw&callback=initMap1"></script>
            </head>
        <body>
                    <div id="map"></div>
                        <script>
        var map, drawData, mark, polyArray;

        function initMap1() {
            map = new mappls.Map("map", {
                center: [28.063811665552436, 78.14155561709754],
                zoomControl: true,
                geolocation: false,
                fullscreenControl: false,
                zoom: 6,
            });

            var geoJSON = {
                "type": "FeatureCollection",
                "features": [{
                        "type": "Feature",
                        "properties": {
                            "class_id": 1,
                            "fill-color": 'red',
                            "fill-opacity": 0.1,
                            "line-color": 'red',
                            "line-width": 5
                        },
                        "geometry": {
                            "type": "Polygon",
                            "coordinates": [
                                [
                                    [76.9073467974041, 28.812799960505487],
                                    [76.80987938023014, 28.653500547082928],
                                    [76.85863941612189, 28.431639818108636],
                                    [76.9827303871715, 28.228848825527592],
                                    [77.29724817663748, 28.111643528457776],
                                    [77.43460456756168, 28.13508388613552],
                                    [77.47448879756053, 28.326383911573373],
                                    [77.61628129429829, 28.45891609604425],
                                    [77.52766263449587, 28.665174250698342],
                                    [77.38144865451238, 28.816678952645034],
                                    [77.12001959325943, 28.921455702045705],
                                    [76.96051754807144, 28.8477343367622],
                                    [76.89848607734564, 28.820563689589775],
                                    [76.90406261845027, 28.812420856507998],
                                ],
                            ]
                        }
                    },
                    {
                        "type": "Feature",
                        "properties": {
                            "class_id": 2,
                            "fill-color": 'blue',
                            "fill-opacity": 0.5,
                            "line-color":'blue',
                    "line-width": 5
                        },
                        "geometry": {
                            "type": "Polygon",
                            "coordinates": [
                                [
                                    [80.20282751526378, 26.94464607699429],
                                    [79.70307131279532, 26.87131098657177],
                                    [79.57655539286986, 26.684944199264876],
                                    [79.53227719202647, 26.509589265197476],
                                    [79.66512553047653, 26.390646330657177],
                                    [80.13325257835271, 26.43597176916667],
                                    [80.60138031970888, 26.175108556689906],
                                    [80.93667095042417, 25.9819152191681],
                                    [81.22133443217245, 26.260236618899086],
                                    [81.76544014579235, 26.486932587122467],
                                    [82.17032198282317, 26.741448433723406],
                                    [81.76543780041692, 26.78098889828263],
                                    [81.25930571794618, 26.893883637523302],
                                    [80.81013983352409, 27.05737802715042],
                                    [80.23445730659859, 26.94464607699429],
                                    [80.20042858229124, 26.945991282767494],
                                ],
                            ]
                        }
                    },
                    {
                        "type": "Feature",
                        "properties": {
                            "class_id": 3,
                            "fill-color": 'green',
                            "fill-opacity": 0.4,
                            "line-color":'green',
                    "line-width": 6
                        },
                        "geometry": {
                            "type": "Polygon",
                            "coordinates": [
                                [
                                    [77.81990309950322, 27.273736358471098],
                                    [77.81619157495328, 27.128489877164455],
                                    [77.9646525569392, 27.062406262881282],
                                    [78.11311993195324, 27.111971857161237],
                                    [78.16879203659909, 27.1978364492944],
                                    [78.06115219522798, 27.375955309280783],
                                    [77.9349603605416, 27.389137984220284],
                                    [77.80876852585527, 27.319911423019818],
                                    [77.82732614860305, 27.27703521414236],
                                    [77.81978580820231, 27.276171216434108],
                                ],
                            ]
                        }
                    },
                    {
                        "type": "Feature",
                        "properties": {
                            "class_id": 4,
                            "fill-color": 'pink',
                            "fill-opacity": 0.5,
                            "line-color": 'pink',
                            "line-width": 5
                        },
                        "geometry": {
                            "type": "Polygon",
                            "coordinates": [
                                [
                                    [
                                        74.78603093691197,
                                        29.79188796518352
                                    ],
                                    [
                                        74.78603093691197,
                                        29.339520263856514
                                    ],
                                    [
                                        75.27309969944119,
                                        29.339520263856514
                                    ],
                                    [
                                        75.27309969944119,
                                        29.79188796518352
                                    ],
                                    [
                                        74.78603093691197,
                                        29.79188796518352
                                    ]
                                ]
                            ],
                        }
                    }
                ]
            }

            map.on('load', (e) => {
                mark = new mappls.Marker({
                    map: map,
                    position: {
                        "lat": 28.007104102028336,
                        "lng": 80.95821963490391
                    },
                    fitbounds: false,
                    icon_url: 'https://apis.mapmyindia.com/map_v3/1.png',
                    draggable: true
                });
                mark.addListener('dragend', function(e) {
                    drawData.checkPosition(polyArray, mark.getPosition(), function(data) {
                        console.log(data);
                    })
                });

                mappls.polygonDraw({
                    map: map,
                    data: geoJSON
                }, function(data) {
                    drawData = data;
                    drawData.control(true);
                    polyArray = drawData.data?.geometry.coordinates[0];
                    /* console.log(data); */

                    drawData.checkPosition(polyArray, mark.getPosition(), function(data) {
                        console.log(data);
                    })

                    /* drawData.set(parm.data); */
                    /* for new data set or data update */
                });
            });
        }
    </script>
        </body>
      </html>
      
      
      
    
  
Call at Mappls
Request Call Back

Personalisation SDK, by Mappls, is India's first O2O engagement tool that can 3X your customer engagement, retention and conversion.

There's so much that Mappls MapmyIndia can do for your enterprise or individual requirements. Explore our website to learn more or request a callback/email if you'd like us to connect with you.

or