|
| 1 | +<html> |
| 2 | + <head> |
| 3 | + <title>Leaflet on OpenStreetMap</title> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | + <link rel="stylesheet" href="/static/leaflet/leaflet.css" /> |
| 7 | + <script src="/static/leaflet/leaflet.js"></script> |
| 8 | + </head> |
| 9 | + <body> |
| 10 | + <div id="mapid" style="width: 100%; height: 100%;"></div> |
| 11 | + <script> |
| 12 | + 'use strict'; |
| 13 | + function createMap() { |
| 14 | + Promise.all([fetch("/call/map/getInitialCoordinates"), fetch("/call/map/getMapObjects")]) |
| 15 | + .then((values) => values.map(p => p.json())).then((p) => Promise.all(p)) |
| 16 | + .then(([coords, objects]) => { |
| 17 | + var mymap = L.map('mapid').setView([coords.result.fst, coords.result.snd], 13); |
| 18 | + L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { |
| 19 | + maxZoom: 19, |
| 20 | + attribution: '© <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>' |
| 21 | + }).addTo(mymap); |
| 22 | + L.control.scale().addTo(mymap); |
| 23 | + |
| 24 | + objects.result.forEach(item => |
| 25 | + L.marker([item.lat, item.long]) |
| 26 | + .addTo(mymap) |
| 27 | + .bindPopup(item.description)); |
| 28 | + var popup = L.popup(); |
| 29 | + function onMapClick(e) { |
| 30 | + popup.setLatLng(e.latlng) |
| 31 | + .setContent("You clicked the map at " + e.latlng.toString()) |
| 32 | + .openOn(mymap); |
| 33 | + } |
| 34 | + mymap.on('click', onMapClick); |
| 35 | + }); |
| 36 | + } |
| 37 | + |
| 38 | + document.addEventListener("DOMContentLoaded", function () { |
| 39 | + createMap(); |
| 40 | + }); |
| 41 | + </script> |
| 42 | + </body> |
| 43 | +</html> |
0 commit comments