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);
30 name: I18n.t("javascripts.map.base.standard")
33 attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
36 name: I18n.t("javascripts.map.base.cycle_map")
38 new L.OSM.TransportMap({
39 attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
41 keyid: "transportmap",
42 name: I18n.t("javascripts.map.base.transport_map")
44 new L.OSM.MapQuestOpen({
45 attribution: "Tiles courtesy of <a href='http://www.mapquest.com/' target='_blank'>MapQuest</a> <img src='http://developer.mapquest.com/content/osm/mq_logo.png'>",
48 name: I18n.t("javascripts.map.base.mapquest")
52 for (var i = layers.length - 1; i >= 0; i--) {
53 if (i === 0 || params.layers.indexOf(layers[i].options.code) >= 0) {
54 map.addLayer(layers[i]);
59 map.noteLayer = new L.LayerGroup();
60 map.noteLayer.options = {code: 'N'};
62 map.dataLayer = new L.OSM.DataLayer(null);
63 map.dataLayer.options.code = 'D';
65 $("#sidebar").on("opened closed", function () {
69 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
71 L.OSM.zoom({position: position})
76 title: I18n.t('javascripts.map.locate.title')
79 var sidebar = L.OSM.sidebar('#map-ui')
107 $('.leaflet-control .control-button').tooltip({placement: 'left', container: 'body'});
109 map.on('moveend layeradd layerremove', updateLocation);
111 var marker = L.marker([0, 0], {icon: getUserIcon()});
113 if (!params.object_zoom) {
115 map.fitBounds(params.bounds);
117 map.setView([params.lat, params.lon], params.zoom);
122 L.rectangle(params.box, {
130 marker.setLatLng([params.mlat, params.mlon]).addTo(map);
134 map.addObject(params.object, { zoom: params.object_zoom });
137 $("#homeanchor").on("click", function(e) {
140 var data = $(this).data(),
141 center = L.latLng(data.lat, data.lon);
143 map.setView(center, data.zoom);
144 marker.setLatLng(center).addTo(map);
147 $("a[data-editor=remote]").click(function(e) {
148 remoteEditHandler(map.getBounds());
152 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
153 remoteEditHandler(map.getBounds());
156 initializeSearch(map);
157 initializeExport(map);
158 initializeBrowse(map, params);
159 initializeNotes(map, params);
162 function updateLocation() {
163 updatelinks(this.getCenter().wrap(),
165 this.getLayersCode(),
166 this.getBounds().wrap());
168 var expiry = new Date();
169 expiry.setYear(expiry.getFullYear() + 10);
170 $.cookie("_osm_location", cookieContent(this), { expires: expiry });
172 // Trigger hash update on layer changes.
173 this.hash.onMapMove();