]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/dashboard.js
Merge remote-tracking branch 'upstream/pull/6064'
[rails.git] / app / assets / javascripts / dashboard.js
1 //= require leaflet.locate
2
3 $(function () {
4   const defaultHomeZoom = 12;
5   let map;
6
7   if ($("#map").length) {
8     map = L.map("map", {
9       attributionControl: false,
10       zoomControl: false
11     }).addLayer(new L.OSM.Mapnik());
12
13     const position = $("html").attr("dir") === "rtl" ? "topleft" : "topright";
14
15     L.OSM.zoom({ position }).addTo(map);
16
17     L.OSM.locate({ position }).addTo(map);
18
19     if (OSM.home) {
20       map.setView([OSM.home.lat, OSM.home.lon], defaultHomeZoom);
21     } else {
22       map.setView([0, 0], 0);
23     }
24
25     $("[data-user]").each(function () {
26       const user = $(this).data("user");
27       if (user.lon && user.lat) {
28         L.marker([user.lat, user.lon], { icon: OSM.getMarker({ icon: user.icon }) }).addTo(map)
29           .bindPopup(user.description, { minWidth: 200 });
30       }
31     });
32   }
33 });