Menu
Close

GeoJSON Marker with Popup

Sample Implementation

    
      
      <html>
        <head>
          <title>GeoJSON Marker with Popup</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&callback=initMap1" defer async></script>
            </head>
        <body>
                    <div id="map"></div>
                        <script>
        var map;

        function initMap1() {
            map = new mappls.Map('map', {
                center: [28.634058447879994, 77.24407362399711],
                zoom: 12
            });
            const geoData = {
                "type": "FeatureCollection",
                "features": [{
                        "type": "Feature",
                        "properties": {
                            "description": "Lal Quila",
                        },
                        "geometry": {
                            "coordinates": [77.23929467557645, 28.654176198622068],
                            "type": "Point"
                        }
                    },
                    {
                        "type": "Feature",
                        "properties": {
                            "description": "Akshardham Temple",
                        },
                        "geometry": {
                            "coordinates": [77.27730633469929, 28.61253778110617],
                            "type": "Point"
                        }
                    },
                    {
                        "type": "Feature",
                        "properties": {
                            "description": "Connaught Place",
                            "icon": "marker",
                        },
                        "geometry": {
                            "coordinates": [77.21957706796468, 28.632854169068906],
                            "type": "Point"
                        }
                    }
                ]
            }

            map.on("load", () => {
                map.loadImage(
                    'https://apis.mapmyindia.com/map_v3/1.png',
                    (error, image) => {
                        if (error) throw error;
                        map.addImage('marker', image);

                        map.addSource("points", {
                            type: "geojson",
                            data: geoData,
                        });
                        map.addLayer({
                            'id': 'places-layer',
                            'type': "symbol",
                            'source': "points",
                            "layout": {
                                "icon-image": ["coalesce", ["get", "icon"], "common1_blue"],
                            }
                        });
                    },
                )

                map.on('click', 'places-layer', (e) => {
                    var coordinates = e.features[0].geometry.coordinates;
                    var description = e.features[0].properties.description;
                    new mapplsgl.Popup()
                        .setLngLat(coordinates)
                        .setHTML(description)
                        .addTo(map);
                });
            });
        }
    </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