main.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. var map = L.map('map').setView([44.5000, 11.3447], 13);
  2. L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/toner-background/{z}/{x}/{y}.{ext}', {
  3. attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
  4. subdomains: 'abcd',
  5. maxZoom: 15,
  6. minZoom: 12,
  7. ext: 'png'
  8. }).addTo(map);;
  9. var geojsonMarkerOptions = {
  10. radius: 8,
  11. fillColor: "#fb1f4f",
  12. color: "#000",
  13. weight: 1,
  14. opacity: 1,
  15. fillOpacity: 0.94
  16. };
  17. var request = new XMLHttpRequest();
  18. request.open('GET', './map.geojson', true);
  19. request.onload = function() {
  20. if (request.status >= 200 && request.status < 400) {
  21. L.geoJSON(JSON.parse(request.responseText), {
  22. pointToLayer: function (feature, latlng) {
  23. return L.circleMarker(latlng, geojsonMarkerOptions);
  24. },
  25. onEachFeature: (feature, layer) => {
  26. if (feature.properties && feature.properties.name) {
  27. layer.bindPopup("<h1>"+feature.properties.name+"</h1>"+feature.properties.description.replace("\n","<br><br>"));
  28. }
  29. }
  30. }).addTo(map);
  31. } else {
  32. console.log("error: "+request)
  33. }
  34. };
  35. request.onerror = function() {
  36. console.log("error: "+request)
  37. };
  38. request.send();