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 thunderforestOptions = {
22 <% if defined?(THUNDERFOREST_KEY) %>
23 apikey: <%= THUNDERFOREST_KEY.to_json %>
27 var map = L.map("map");
28 map.attributionControl.setPrefix('');
29 map.removeControl(map.attributionControl);
31 if (!args.layer || args.layer === "mapnik" || args.layer === "osmarender" || args.layer === "mapquest") {
32 new L.OSM.Mapnik().addTo(map);
33 } else if (args.layer === "cyclemap" || args.layer === "cycle map") {
34 new L.OSM.CycleMap(thunderforestOptions).addTo(map);
35 } else if (args.layer === "transportmap") {
36 new L.OSM.TransportMap(thunderforestOptions).addTo(map);
37 } else if (args.layer === "hot") {
38 new L.OSM.HOT().addTo(map);
42 L.marker(args.marker.split(','), {icon: L.icon({
43 iconUrl: <%= asset_path('images/marker-icon.png').to_json %>,
44 iconSize: new L.Point(25, 41),
45 iconAnchor: new L.Point(12, 41),
46 shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>,
47 shadowSize: new L.Point(41, 41)
52 var bbox = args.bbox.split(',');
53 map.fitBounds([L.latLng(bbox[1], bbox[0]),
54 L.latLng(bbox[3], bbox[2])]);
59 map.addControl(new L.Control.OSMReportAProblem());
62 L.Control.OSMReportAProblem = L.Control.Attribution.extend({
64 position: 'bottomright',
65 prefix: '<a href="http://www.openstreetmap.org/fixthemap?lat={x}&lon={y}&zoom={z}" target="_blank">'+I18n.t('javascripts.embed.report_problem')+'</a>'
68 onAdd: function (map) {
69 var container = L.Control.Attribution.prototype.onAdd.call(this, map);
71 map.on('moveend', this._update, this);
76 _update: function () {
77 L.Control.Attribution.prototype._update.call(this);
79 this._container.innerHTML =
80 this._container.innerHTML
81 .replace('{x}', this._map.getCenter().lat)
82 .replace('{y}', this._map.getCenter().lng)
83 .replace('{z}', this._map.getZoom());