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" || args.layer === "mapquest") {
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 === "hot") {
32 new L.OSM.HOT().addTo(map);
36 L.marker(args.marker.split(','), {icon: L.icon({
37 iconUrl: <%= asset_path('images/marker-icon.png').to_json %>,
38 iconSize: new L.Point(25, 41),
39 iconAnchor: new L.Point(12, 41),
40 shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>,
41 shadowSize: new L.Point(41, 41)
46 var bbox = args.bbox.split(',');
47 map.fitBounds([L.latLng(bbox[1], bbox[0]),
48 L.latLng(bbox[3], bbox[2])]);
53 map.addControl(new L.Control.OSMReportAProblem());
56 L.Control.OSMReportAProblem = L.Control.Attribution.extend({
58 position: 'bottomright',
59 prefix: '<a href="http://www.openstreetmap.org/fixthemap?lat={x}&lon={y}&zoom={z}" target="_blank">'+I18n.t('javascripts.embed.report_problem')+'</a>'
62 onAdd: function (map) {
63 var container = L.Control.Attribution.prototype.onAdd.call(this, map);
65 map.on('moveend', this._update, this);
70 _update: function () {
71 L.Control.Attribution.prototype._update.call(this);
73 this._container.innerHTML =
74 this._container.innerHTML
75 .replace('{x}', this._map.getCenter().lat)
76 .replace('{y}', this._map.getCenter().lng)
77 .replace('{z}', this._map.getZoom());