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] || '');
22 var thunderforestOptions = {
23 <% if Settings.key?(:thunderforest_key) %>
24 apikey: <%= Settings.thunderforest_key.to_json %>
28 var map = L.map("map");
29 map.attributionControl.setPrefix('');
30 map.removeControl(map.attributionControl);
32 if (!args.layer || args.layer === "mapnik" || args.layer === "osmarender" || args.layer === "mapquest") {
33 new L.OSM.Mapnik().addTo(map);
34 } else if (args.layer === "cyclemap" || args.layer === "cycle map") {
35 new L.OSM.CycleMap(thunderforestOptions).addTo(map);
36 } else if (args.layer === "transportmap") {
37 new L.OSM.TransportMap(thunderforestOptions).addTo(map);
38 } else if (args.layer === "opnvkarte") {
39 new L.OSM.OPNVKarte().addTo(map);
40 } else if (args.layer === "hot") {
41 new L.OSM.HOT().addTo(map);
45 L.marker(args.marker.split(','), {icon: L.icon({
46 iconUrl: <%= asset_path('leaflet/dist/images/marker-icon.png').to_json %>,
47 iconSize: new L.Point(25, 41),
48 iconAnchor: new L.Point(12, 41),
49 shadowUrl: <%= asset_path('leaflet/dist/images/marker-shadow.png').to_json %>,
50 shadowSize: new L.Point(41, 41)
55 var bbox = args.bbox.split(',');
56 map.fitBounds([L.latLng(bbox[1], bbox[0]),
57 L.latLng(bbox[3], bbox[2])]);
62 map.addControl(new L.Control.OSMReportAProblem());
65 L.Control.OSMReportAProblem = L.Control.Attribution.extend({
67 position: 'bottomright',
68 prefix: '<a href="http://www.openstreetmap.org/fixthemap?lat={x}&lon={y}&zoom={z}" target="_blank">'+I18n.t('javascripts.embed.report_problem')+'</a>'
71 onAdd: function (map) {
72 var container = L.Control.Attribution.prototype.onAdd.call(this, map);
74 map.on('moveend', this._update, this);
79 _update: function () {
80 L.Control.Attribution.prototype._update.call(this);
82 this._container.innerHTML =
83 this._container.innerHTML
84 .replace('{x}', this._map.getCenter().lat)
85 .replace('{y}', this._map.getCenter().lng)
86 .replace('{z}', this._map.getZoom());