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 window.onload = function () {
15 var query = (window.location.search || '?').slice(1),
18 var pairs = query.split('&');
19 for (var i = 0; i < pairs.length; i++) {
20 var parts = pairs[i].split('=');
21 args[parts[0]] = decodeURIComponent(parts[1] || '');
25 <% if Settings.key?(:tile_cdn_url) %>
26 url: <%= Settings.tile_cdn_url.to_json %>
30 var thunderforestOptions = {
31 <% if Settings.key?(:thunderforest_key) %>
32 apikey: <%= Settings.thunderforest_key.to_json %>
36 var map = L.map("map");
37 map.attributionControl.setPrefix('');
38 map.removeControl(map.attributionControl);
40 if (args.layer === "cyclosm") {
41 new L.OSM.CyclOSM().addTo(map);
42 } else if (args.layer === "cyclemap" || args.layer === "cycle map") {
43 new L.OSM.CycleMap(thunderforestOptions).addTo(map);
44 } else if (args.layer === "transportmap") {
45 new L.OSM.TransportMap(thunderforestOptions).addTo(map);
46 } else if (args.layer === "hot") {
47 new L.OSM.HOT().addTo(map);
49 new L.OSM.Mapnik(mapnikOptions).addTo(map);
53 L.marker(args.marker.split(','), {icon: L.icon({
54 iconUrl: <%= asset_path('leaflet/dist/images/marker-icon.png').to_json %>,
55 iconSize: new L.Point(25, 41),
56 iconAnchor: new L.Point(12, 41),
57 shadowUrl: <%= asset_path('leaflet/dist/images/marker-shadow.png').to_json %>,
58 shadowSize: new L.Point(41, 41)
63 var bbox = args.bbox.split(',');
64 map.fitBounds([L.latLng(bbox[1], bbox[0]),
65 L.latLng(bbox[3], bbox[2])]);
70 map.addControl(new L.Control.OSMReportAProblem());
73 L.Control.OSMReportAProblem = L.Control.Attribution.extend({
75 position: 'bottomright',
76 prefix: '<a href="https://www.openstreetmap.org/fixthemap?lat={x}&lon={y}&zoom={z}" target="_blank">'+I18n.t('javascripts.embed.report_problem')+'</a>'
79 onAdd: function (map) {
80 var container = L.Control.Attribution.prototype.onAdd.call(this, map);
82 map.on('moveend', this._update, this);
87 _update: function () {
88 L.Control.Attribution.prototype._update.call(this);
90 this._container.innerHTML =
91 this._container.innerHTML
92 .replace('{x}', this._map.getCenter().lat)
93 .replace('{y}', this._map.getCenter().lng)
94 .replace('{z}', this._map.getZoom());