Menu
Close

Pulsing Marker

Sample Implementation

    
      
      <html>
        <head>
          <title>Pulsing Marker</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>
        function initMap1() {
            var map = new mappls.Map("map", {
                center: [28.61, 77.23],
                zoomControl: true,
                location: true,
                zoom: 4,
            });

            const size = 200;

            const pulsingDot = {
                width: size,
                height: size,
                data: new Uint8Array(size * size * 4),

                onAdd: function() {
                    const canvas = document.createElement("canvas");
                    canvas.width = this.width;
                    canvas.height = this.height;
                    this.context = canvas.getContext("2d");
                },

                render: function() {
                    const duration = 1000;
                    const t = (performance.now() % duration) / duration;

                    const radius = (size / 2) * 0.3;
                    const outerRadius = (size / 2) * 0.7 * t + radius;
                    const context = this.context;

                    context.clearRect(0, 0, this.width, this.height);
                    context.beginPath();
                    context.arc(
                        this.width / 2,
                        this.height / 2,
                        outerRadius,
                        0,
                        Math.PI * 2
                    );
                    context.fillStyle = `rgba(255, 200, 200, ${1 - t})`;
                    context.fill();

                    context.beginPath();
                    context.arc(
                        this.width / 2,
                        this.height / 2,
                        radius,
                        0,
                        Math.PI * 2
                    );
                    context.fillStyle = "rgba(255, 100, 100, 1)";
                    context.strokeStyle = "white";
                    context.lineWidth = 2 + 4 * (1 - t);
                    context.fill();
                    context.stroke();

                    this.data = context.getImageData(
                        0,
                        0,
                        this.width,
                        this.height
                    ).data;

                    map.triggerRepaint();

                    return true;
                },
            };

            map.on("load", () => {
                map.addImage("pulsing-dot", pulsingDot, {
                    pixelRatio: 2
                });

                map.addSource("dot-point", {
                    type: "geojson",
                    data: {
                        type: "FeatureCollection",
                        features: [{
                            type: "Feature",
                            geometry: {
                                type: "Point",
                                coordinates: [77.23, 28.61],
                            },
                        }, ],
                    },
                });
                map.addLayer({
                    id: "layer-with-pulsing-dot",
                    type: "symbol",
                    source: "dot-point",
                    layout: {
                        "icon-image": "pulsing-dot",
                    },
                });
            });
        }
    </script>
        </body>
      </html>
      
      
      
    
  
Call at Mappls
Product release

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

Boost your businesses with Mappls’ industry-leading optimisation APIs and SDKs to bring the best and most efficient ways to deliver goods, save time and increase profits.

or