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 defined?(THUNDERFOREST_KEY) %>
24 apikey: <%= 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 === "hot") {
39 new L.OSM.HOT().addTo(map);
43 L.marker(args.marker.split(','), {icon: L.icon({
44 iconUrl: <%= asset_path('images/marker-icon.png').to_json %>,
45 iconSize: new L.Point(25, 41),
46 iconAnchor: new L.Point(12, 41),
47 shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>,
48 shadowSize: new L.Point(41, 41)
53 var bbox = args.bbox.split(',');
54 map.fitBounds([L.latLng(bbox[1], bbox[0]),
55 L.latLng(bbox[3], bbox[2])]);
60 map.addControl(new L.Control.OSMReportAProblem());
63 L.Control.OSMReportAProblem = L.Control.Attribution.extend({
65 position: 'bottomright',
66 prefix: '<a href="http://www.openstreetmap.org/fixthemap?lat={x}&lon={y}&zoom={z}" target="_blank">'+I18n.t('javascripts.embed.report_problem')+'</a>'
69 onAdd: function (map) {
70 var container = L.Control.Attribution.prototype.onAdd.call(this, map);
72 map.on('moveend', this._update, this);
77 _update: function () {
78 L.Control.Attribution.prototype._update.call(this);
80 this._container.innerHTML =
81 this._container.innerHTML
82 .replace('{x}', this._map.getCenter().lat)
83 .replace('{y}', this._map.getCenter().lng)
84 .replace('{z}', this._map.getZoom());