1 //= depend_on settings.yml
2 //= depend_on settings.local.yml
3 //= require leaflet/dist/leaflet-src
4 //= require leaflet.osm
8 if (navigator.languages) {
9 I18n.locale = navigator.languages[0];
10 } else if (navigator.language) {
11 I18n.locale = navigator.language;
14 I18n.default_locale = <%= I18n.default_locale.to_json %>;
15 I18n.fallbacks = true;
17 window.onload = function () {
18 var query = (window.location.search || "?").slice(1),
21 var pairs = query.split("&");
22 for (var i = 0; i < pairs.length; i++) {
23 var parts = pairs[i].split("=");
24 args[parts[0]] = decodeURIComponent(parts[1] || "");
28 <% if Settings.key?(:tile_cdn_url) %>
29 url: <%= Settings.tile_cdn_url.to_json %>
33 var thunderforestOptions = {
34 <% if Settings.key?(:thunderforest_key) %>
35 apikey: <%= Settings.thunderforest_key.to_json %>
39 var map = L.map("map");
40 map.attributionControl.setPrefix("");
41 map.removeControl(map.attributionControl);
43 if (args.layer === "cyclosm") {
44 new L.OSM.CyclOSM().addTo(map);
45 } else if (args.layer === "cyclemap" || args.layer === "cycle map") {
46 new L.OSM.CycleMap(thunderforestOptions).addTo(map);
47 } else if (args.layer === "transportmap") {
48 new L.OSM.TransportMap(thunderforestOptions).addTo(map);
49 } else if (args.layer === "hot") {
50 new L.OSM.HOT().addTo(map);
52 new L.OSM.Mapnik(mapnikOptions).addTo(map);
56 L.marker(args.marker.split(","), { icon: L.icon({
57 iconUrl: <%= asset_path('leaflet/dist/images/marker-icon.png').to_json %>,
58 iconSize: new L.Point(25, 41),
59 iconAnchor: new L.Point(12, 41),
60 shadowUrl: <%= asset_path('leaflet/dist/images/marker-shadow.png').to_json %>,
61 shadowSize: new L.Point(41, 41)
66 var bbox = args.bbox.split(",");
68 L.latLng(bbox[1], bbox[0]),
69 L.latLng(bbox[3], bbox[2])
75 map.addControl(new L.Control.OSMReportAProblem());
78 L.Control.OSMReportAProblem = L.Control.Attribution.extend({
80 position: "bottomright",
81 prefix: "<a href=\"https://www.openstreetmap.org/fixthemap?lat={x}&lon={y}&zoom={z}\" target=\"_blank\">" + I18n.t("javascripts.embed.report_problem") + "</a>"
84 onAdd: function (map) {
85 var container = L.Control.Attribution.prototype.onAdd.call(this, map);
87 map.on("moveend", this._update, this);
92 _update: function () {
93 L.Control.Attribution.prototype._update.call(this);
95 this._container.innerHTML =
96 this._container.innerHTML
97 .replace("{x}", this._map.getCenter().lat)
98 .replace("{y}", this._map.getCenter().lng)
99 .replace("{z}", this._map.getZoom());