2 //= require leaflet.sidebar
3 //= require leaflet.locate
4 //= require leaflet.layers
5 //= require leaflet.key
6 //= require leaflet.note
7 //= require leaflet.share
8 //= require index/search
9 //= require index/browse
10 //= require index/export
11 //= require index/notes
13 $(document).ready(function () {
14 var params = OSM.mapParams();
16 var map = L.map("map", {
21 map.attributionControl.setPrefix('');
23 map.hash = L.hash(map);
25 var copyright = I18n.t('javascripts.map.copyright', {copyright_url: '/copyright'});
29 attribution: copyright,
32 name: I18n.t("javascripts.map.base.standard")
35 attribution: copyright + ". Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
38 name: I18n.t("javascripts.map.base.cycle_map")
40 new L.OSM.TransportMap({
41 attribution: copyright + ". Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
43 keyid: "transportmap",
44 name: I18n.t("javascripts.map.base.transport_map")
46 new L.OSM.MapQuestOpen({
47 attribution: copyright + ". Tiles courtesy of <a href='http://www.mapquest.com/' target='_blank'>MapQuest</a> <img src='http://developer.mapquest.com/content/osm/mq_logo.png'>",
50 name: I18n.t("javascripts.map.base.mapquest")
54 for (var i = layers.length - 1; i >= 0; i--) {
55 if (i === 0 || params.layers.indexOf(layers[i].options.code) >= 0) {
56 map.addLayer(layers[i]);
61 map.noteLayer = new L.LayerGroup();
62 map.noteLayer.options = {code: 'N'};
64 map.dataLayer = new L.OSM.DataLayer(null);
65 map.dataLayer.options.code = 'D';
67 $("#sidebar").on("opened closed", function () {
71 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
73 L.OSM.zoom({position: position})
79 title: I18n.t('javascripts.map.locate.title'),
80 popup: I18n.t('javascripts.map.locate.popup')
84 var sidebar = L.OSM.sidebar('#map-ui')
112 $('.leaflet-control .control-button').tooltip({placement: 'left', container: 'body'});
114 map.on('moveend layeradd layerremove', updateLocation);
116 var marker = L.marker([0, 0], {icon: getUserIcon()});
118 if (!params.object_zoom) {
120 map.fitBounds(params.bounds);
122 map.setView([params.lat, params.lon], params.zoom);
127 L.rectangle(params.box, {
135 marker.setLatLng([params.mlat, params.mlon]).addTo(map);
139 map.addObject(params.object, { zoom: params.object_zoom });
142 $("#homeanchor").on("click", function(e) {
145 var data = $(this).data(),
146 center = L.latLng(data.lat, data.lon);
148 map.setView(center, data.zoom);
149 marker.setLatLng(center).addTo(map);
152 $("a[data-editor=remote]").click(function(e) {
153 remoteEditHandler(map.getBounds());
157 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
158 remoteEditHandler(map.getBounds());
161 initializeSearch(map);
162 initializeExport(map);
163 initializeBrowse(map, params);
164 initializeNotes(map, params);
167 function updateLocation() {
168 updatelinks(this.getCenter().wrap(),
170 this.getLayersCode(),
171 this.getBounds().wrap());
173 var expiry = new Date();
174 expiry.setYear(expiry.getFullYear() + 10);
175 $.cookie("_osm_location", cookieContent(this), { expires: expiry });
177 // Trigger hash update on layer changes.
178 this.hash.onMapMove();