Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Quick Start - Leaflet</title>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
- <link rel="stylesheet" href="https://unpkg.com/leaflet@1.4.0/dist/leaflet.css" integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA==" crossorigin=""/>
- <script src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js" integrity="sha512-QVftwZFqvtRNi0ZyCtsznlKSWOStnDORoefr1enyq5mVL4tmKB3S/EnC3rRJcxCPavG10IcrVGSmPh6Qw5lwrg==" crossorigin=""></script>
- </head>
- <body>
- <div id="mapid" style="width: 600px; height: 400px;"></div>
- <script>
- var map = L.map('mapid').setView([ 11,22], 14);
- L.tileLayer(
- 'https://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}'
- , {
- subdomains:['mt0','mt1','mt2','mt3'],
- maxZoom: 18,
- id: 'mapbox.streets'
- }).addTo(map);
- var LeafIcon = L.Icon.extend({
- options: {
- shadowUrl: 'https://leafletjs.com/examples/custom-icons/leaf-shadow.png',
- iconSize: [38, 95],
- shadowSize: [50, 64],
- iconAnchor: [22, 94],
- shadowAnchor: [4, 62],
- popupAnchor: [-3, -76]
- }
- });
- var greenIcon = new LeafIcon({iconUrl: 'https://leafletjs.com/examples/custom-icons/leaf-green.png'}),
- redIcon = new LeafIcon({iconUrl: 'https://leafletjs.com/examples/custom-icons/leaf-red.png'}),
- orangeIcon = new LeafIcon({iconUrl: 'https://leafletjs.com/examples/custom-icons/leaf-orange.png'});
- L.icon = function (options) {
- return new L.Icon(options);
- };
- var marker;
- map.on('click', function (e) {
- if (marker) { // check
- map.removeLayer(marker); // remove
- }
- marker = L.marker(e.latlng,{icon: greenIcon}).addTo(map).bindPopup('<strong>hi</strong><br>h.').openPopup();
- });
- </script>
- </body>
- </html>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement