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 || args.layer === "mapnik" || args.layer === "osmarender" || args.layer === "mapquest") {
41 new L.OSM.Mapnik(mapnikOptions).addTo(map);
42 } else if (args.layer === "cyclosm") {
43 new L.OSM.CyclOSM().addTo(map);
44 } else if (args.layer === "cyclemap" || args.layer === "cycle map") {
45 new L.OSM.CycleMap(thunderforestOptions).addTo(map);
46 } else if (args.layer === "transportmap") {
47 new L.OSM.TransportMap(thunderforestOptions).addTo(map);
48 } else if (args.layer === "opnvkarte") {
49 new L.OSM.OPNVKarte().addTo(map);
50 } else if (args.layer === "hot") {
51 new L.OSM.HOT().addTo(map);
55 L.marker(args.marker.split(','), {icon: L.icon({
56 iconUrl: <%= asset_path('leaflet/dist/images/marker-icon.png').to_json %>,
57 iconSize: new L.Point(25, 41),
58 iconAnchor: new L.Point(12, 41),
59 shadowUrl: <%= asset_path('leaflet/dist/images/marker-shadow.png').to_json %>,
60 shadowSize: new L.Point(41, 41)
65 var bbox = args.bbox.split(',');
66 map.fitBounds([L.latLng(bbox[1], bbox[0]),
67 L.latLng(bbox[3], bbox[2])]);
72 map.addControl(new L.Control.OSMReportAProblem());
75 L.Control.OSMReportAProblem = L.Control.Attribution.extend({
77 position: 'bottomright',
78 prefix: '<a href="https://www.openstreetmap.org/fixthemap?lat={x}&lon={y}&zoom={z}" target="_blank">'+I18n.t('javascripts.embed.report_problem')+'</a>'
81 onAdd: function (map) {
82 var container = L.Control.Attribution.prototype.onAdd.call(this, map);
84 map.on('moveend', this._update, this);
89 _update: function () {
90 L.Control.Attribution.prototype._update.call(this);
92 this._container.innerHTML =
93 this._container.innerHTML
94 .replace('{x}', this._map.getCenter().lat)
95 .replace('{y}', this._map.getCenter().lng)
96 .replace('{z}', this._map.getZoom());