1 //= require leaflet/dist/leaflet-src
2 //= require leaflet.osm
6 window.onload = function () {
7 if (navigator.languages) {
8 I18n.locale = navigator.languages[0];
9 } else if (navigator.language) {
10 I18n.locale = navigator.language;
13 var query = (window.location.search || '?').substr(1),
16 var pairs = query.split('&');
17 for (var i = 0; i < pairs.length; i++) {
18 var parts = pairs[i].split('=');
19 args[parts[0]] = decodeURIComponent(parts[1] || '');
23 <% if Settings.key?(:tile_cdn_url) %>
24 url: <%= Settings.tile_cdn_url.to_json %>
28 var thunderforestOptions = {
29 <% if Settings.key?(:thunderforest_key) %>
30 apikey: <%= Settings.thunderforest_key.to_json %>
34 var map = L.map("map");
35 map.attributionControl.setPrefix('');
36 map.removeControl(map.attributionControl);
38 if (!args.layer || args.layer === "mapnik" || args.layer === "osmarender" || args.layer === "mapquest") {
39 new L.OSM.Mapnik(mapnikOptions).addTo(map);
40 } else if (args.layer === "cyclemap" || args.layer === "cycle map") {
41 new L.OSM.CycleMap(thunderforestOptions).addTo(map);
42 } else if (args.layer === "transportmap") {
43 new L.OSM.TransportMap(thunderforestOptions).addTo(map);
44 } else if (args.layer === "opnvkarte") {
45 new L.OSM.OPNVKarte().addTo(map);
46 } else if (args.layer === "hot") {
47 new L.OSM.HOT().addTo(map);
51 L.marker(args.marker.split(','), {icon: L.icon({
52 iconUrl: <%= asset_path('leaflet/dist/images/marker-icon.png').to_json %>,
53 iconSize: new L.Point(25, 41),
54 iconAnchor: new L.Point(12, 41),
55 shadowUrl: <%= asset_path('leaflet/dist/images/marker-shadow.png').to_json %>,
56 shadowSize: new L.Point(41, 41)
61 var bbox = args.bbox.split(',');
62 map.fitBounds([L.latLng(bbox[1], bbox[0]),
63 L.latLng(bbox[3], bbox[2])]);
68 map.addControl(new L.Control.OSMReportAProblem());
71 L.Control.OSMReportAProblem = L.Control.Attribution.extend({
73 position: 'bottomright',
74 prefix: '<a href="http://www.openstreetmap.org/fixthemap?lat={x}&lon={y}&zoom={z}" target="_blank">'+I18n.t('javascripts.embed.report_problem')+'</a>'
77 onAdd: function (map) {
78 var container = L.Control.Attribution.prototype.onAdd.call(this, map);
80 map.on('moveend', this._update, this);
85 _update: function () {
86 L.Control.Attribution.prototype._update.call(this);
88 this._container.innerHTML =
89 this._container.innerHTML
90 .replace('{x}', this._map.getCenter().lat)
91 .replace('{y}', this._map.getCenter().lng)
92 .replace('{z}', this._map.getZoom());