2 //= require leaflet.osm
3 //= require i18n/translations
5 window.onload = function () {
6 if (navigator.languages) {
7 I18n.locale = navigator.languages[0];
8 } else if (navigator.language) {
9 I18n.locale = navigator.language;
12 var query = (window.location.search || '?').substr(1),
15 var pairs = query.split('&');
16 for (var i = 0; i < pairs.length; i++) {
17 var parts = pairs[i].split('=');
18 args[parts[0]] = decodeURIComponent(parts[1] || '');
21 var map = L.map("map");
22 map.attributionControl.setPrefix('');
23 map.removeControl(map.attributionControl);
25 if (!args.layer || args.layer === "mapnik" || args.layer === "osmarender") {
26 new L.OSM.Mapnik().addTo(map);
27 } else if (args.layer === "cyclemap" || args.layer === "cycle map") {
28 new L.OSM.CycleMap().addTo(map);
29 } else if (args.layer === "transportmap") {
30 new L.OSM.TransportMap().addTo(map);
31 } else if (args.layer === "mapquest") {
32 new L.OSM.MapQuestOpen().addTo(map);
33 } else if (args.layer === "hot") {
34 new L.OSM.HOT().addTo(map);
38 L.marker(args.marker.split(','), {icon: L.icon({
39 iconUrl: <%= asset_path('images/marker-icon.png').to_json %>,
40 iconSize: new L.Point(25, 41),
41 iconAnchor: new L.Point(12, 41),
42 shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>,
43 shadowSize: new L.Point(41, 41)
48 var bbox = args.bbox.split(',');
49 map.fitBounds([L.latLng(bbox[1], bbox[0]),
50 L.latLng(bbox[3], bbox[2])]);
55 map.addControl(new L.Control.OSMReportAProblem());
58 L.Control.OSMReportAProblem = L.Control.Attribution.extend({
60 position: 'bottomright',
61 prefix: '<a href="http://www.openstreetmap.org/fixthemap?lat={x}&lon={y}&zoom={z}" target="_blank">Report a problem</a>'
64 onAdd: function (map) {
65 var container = L.Control.Attribution.prototype.onAdd.call(this, map);
67 map.on('moveend', this._update, this);
72 _update: function () {
73 L.Control.Attribution.prototype._update.call(this);
75 this._container.innerHTML =
76 this._container.innerHTML
77 .replace('{x}', this._map.getCenter().lat)
78 .replace('{y}', this._map.getCenter().lng)
79 .replace('{z}', this._map.getZoom());