1 //= depend_on settings.yml
2 //= depend_on settings.local.yml
3 //= depend_on layers.yml
4 //= require leaflet/dist/leaflet-src
5 //= require leaflet.osm
9 if (navigator.languages) {
10 OSM.i18n.locale = navigator.languages[0];
11 } else if (navigator.language) {
12 OSM.i18n.locale = navigator.language;
15 OSM.i18n.defaultLocale = <%= I18n.default_locale.to_json %>;
16 OSM.i18n.enableFallback = true;
18 window.onload = function () {
19 const args = new URLSearchParams(location.search);
23 <% if Settings.key?(:tile_cdn_url) %>
24 url: <%= Settings.tile_cdn_url.to_json %>
29 const map = L.map("map");
30 map.attributionControl.setPrefix("");
31 map.removeControl(map.attributionControl);
33 const isDarkTheme = args.get("theme") === "dark" || (args.get("theme") !== "light" && window.matchMedia("(prefers-color-scheme: dark)").matches);
34 const layers = <%= MapLayers::embed_definitions("config/layers.yml").to_json %>;
35 const layerId = (args.get("layer") || "").replaceAll(" ", "");
36 const layerConfig = layers[layerId] || layers.mapnik;
37 let url = (isDarkTheme && layerConfig.urlDark) || layerConfig.url;
38 url = url.replace("{ratio}", "{r}");
39 new L.OSM.TileLayer({ ...layerConfig, ...options[layerId], url }).addTo(map);
41 if (args.has("marker")) {
42 L.marker(args.get("marker").split(","), { icon: L.divIcon({
43 html: "<svg viewBox='0 0 25 40' overflow='visible'><use href='#pin-shadow' /><use href='#pin-dot' color='#0b8ef1' /></svg>",
45 iconAnchor: [12.5, 40]
49 const bbox = (args.get("bbox") || "-180,-90,180,90").split(",");
50 map.fitBounds([[bbox[1], bbox[0]], [bbox[3], bbox[2]]]);
52 map.addControl(new L.Control.OSMReportAProblem());
55 L.Control.OSMReportAProblem = L.Control.Attribution.extend({
57 position: "bottomright",
58 prefix: `<a href="/fixthemap?lat={x}&lon={y}&zoom={z}" target="_blank">${OSM.i18n.t("javascripts.embed.report_problem")}</a>`
61 onAdd: function (map) {
62 const container = L.Control.Attribution.prototype.onAdd.call(this, map);
64 map.on("moveend", this._update, this);
69 _update: function () {
70 L.Control.Attribution.prototype._update.call(this);
72 this._container.innerHTML =
73 this._container.innerHTML
74 .replace("{x}", this._map.getCenter().lat)
75 .replace("{y}", this._map.getCenter().lng)
76 .replace("{z}", this._map.getZoom());