2 //= require leaflet.osm
4 window.onload = function () {
5 var query = (window.location.search || '?').substr(1),
8 var pairs = query.split('&');
9 for (var i = 0; i < pairs.length; i++) {
10 var parts = pairs[i].split('=');
11 args[parts[0]] = decodeURIComponent(parts[1] || '');
14 var map = L.map("map");
15 map.attributionControl.setPrefix('');
16 map.removeControl(map.attributionControl);
18 if (!args.layer || args.layer === "mapnik" || args.layer === "osmarender") {
19 new L.OSM.Mapnik().addTo(map);
20 } else if (args.layer === "cyclemap" || args.layer === "cycle map") {
21 new L.OSM.CycleMap().addTo(map);
22 } else if (args.layer === "transportmap") {
23 new L.OSM.TransportMap().addTo(map);
24 } else if (args.layer === "mapquest") {
25 new L.OSM.MapQuestOpen().addTo(map);
26 } else if (args.layer === "hot") {
27 new L.OSM.HOT().addTo(map);
31 L.marker(args.marker.split(','), {icon: L.icon({
32 iconUrl: <%= asset_path('images/marker-icon.png').to_json %>,
33 iconSize: new L.Point(25, 41),
34 iconAnchor: new L.Point(12, 41),
35 shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>,
36 shadowSize: new L.Point(41, 41)
41 var bbox = args.bbox.split(',');
42 map.fitBounds([L.latLng(bbox[1], bbox[0]),
43 L.latLng(bbox[3], bbox[2])]);
47 (new L.Control.OSMReportAProblem({})).addTo(map);
50 L.Control.OSMReportAProblem = L.Control.Attribution.extend({
52 position: 'bottomright',
53 prefix: '<a href="http://www.openstreetmap.org/fixthemap?lat={x}&lon={y}&zoom={z}">Report a problem</a>'
55 _layerAdd: function(e)
57 if (e.layer.getAttribution) {
58 this.addAttribution(e.layer.getAttribution());
61 _layerRemove: function(e)
63 if (e.layer.getAttribution) {
64 this.removeAttribution(e.layer.getAttribution());
67 onAdd: function (map) {
68 this._container = L.DomUtil.create('div', 'leaflet-control-attribution');
69 L.DomEvent.disableClickPropagation(this._container);
71 // TODO ugly, refactor
72 for (var i in map._layers) {
73 if (map._layers[i].getAttribution) {
74 this.addAttribution(map._layers[i].getAttribution());
79 map.on('moveend', this._update, this);
80 map.on('layeradd', this._layerAdd, this);
81 map.on('layerremove', this._layerRemove, this);
83 return this._container;
85 _update: function () {
86 if (!this._map) { return; }
90 for (var i in this._attributions) {
91 if (this._attributions[i]) {
96 var prefixAndAttribs = [];
98 if (this.options.prefix) {
99 prefixAndAttribs.push(this.options.prefix);
101 if (attribs.length) {
102 prefixAndAttribs.push(attribs.join(', '));
105 this._container.innerHTML = prefixAndAttribs.join(' | ').replace('{x}', this._map.getCenter().lat).replace('{y}', this._map.getCenter().lng).replace('{z}', this._map.getZoom());