<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Dealing with events</title>
        
        <link href="https://tiles.locationiq.com/v3/libs/leaflet/1.8.0/leaflet.css" rel="stylesheet" type="text/css"/>
        <script type="text/javascript" src="https://tiles.locationiq.com/v3/libs/leaflet/1.8.0/leaflet.js"></script>
        <script type="text/javascript" src="https://tiles.locationiq.com/v3/js/liq-styles-ctrl-leaflet.js?v=0.1.8"></script>
        
        <style type="text/css">
            body {
                margin: 0;
            }
            #map {
                width: 100vw;
                height: 100vh;
            }
        </style>
    </head>

    <body>
        <div id='map'></div>
        <script type="text/javascript">
            // Maps access token goes here
            var key = 'pk.aa7f5d0539c5675b7f3429402939d8fa';

            // Add layers that we need to the map
            var streets = L.tileLayer.Unwired({key: key, scheme: "streets"});

            // Initialize the map
            var map = L.map('map', {
                center: [39.73, -104.99], // Map loads with this location as center
                zoom: 14,
                scrollWheelZoom: false,
                layers: [streets]         // Show 'streets' by default
            });

            // Add the 'scale' control
            L.control.scale().addTo(map);

            // Add the 'layers' control
            L.control.layers({
                "Streets": streets
            }).addTo(map);

            // Add a 'marker'
            var marker = L.marker([39.723, -104.985], { draggable: true })
                .addTo(map)
                .bindPopup("<b>Hello world!</b><br>I am a popup.")
                .openPopup();

            // Add a 'circle'
            var circle = L.circle([39.73, -104.997], {
                color: 'red',
                fillColor: '#f03',
                fillOpacity: 0.5,
                radius: 500
            }).addTo(map).bindPopup("I am a circle.");

            // Add a 'polygon'
            var polygon = L.polygon([
                [39.726, -104.980],
                [39.734, -104.982],
                [39.739, -104.971]
            ]).addTo(map).bindPopup("I am a polygon.");

            var popup = L.popup()
                .setLatLng([39.7236, -104.985]);

            // onMapClick function to popup co-ordinates, Map click listener
            function onMapClick(e) {
                popup
                    .setLatLng(e.latlng)
                    .setContent("You clicked the map at " + e.latlng.toString())
                    .openOn(map);
            }

            map.on('click', onMapClick);
        </script>
    </body>
</html>