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})
74 L.control.locate({position: position})
77 var sidebar = L.OSM.sidebar('#map-ui')
105 map.on('moveend layeradd layerremove', updateLocation);
107 var marker = L.marker([0, 0], {icon: getUserIcon()});
109 if (!params.object_zoom) {
111 map.fitBounds(params.bounds);
113 map.setView([params.lat, params.lon], params.zoom);
118 L.rectangle(params.box, {
126 marker.setLatLng([params.mlat, params.mlon]).addTo(map);
130 map.addObject(params.object, { zoom: params.object_zoom });
133 $("#homeanchor").on("click", function(e) {
136 var data = $(this).data(),
137 center = L.latLng(data.lat, data.lon);
139 map.setView(center, data.zoom);
140 marker.setLatLng(center).addTo(map);
143 $("a[data-editor=remote]").click(function(e) {
144 remoteEditHandler(map.getBounds());
148 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
149 remoteEditHandler(map.getBounds());
152 initializeSearch(map);
153 initializeExport(map);
154 initializeBrowse(map, params);
155 initializeNotes(map, params);
158 function updateLocation() {
159 updatelinks(this.getCenter().wrap(),
161 this.getLayersCode(),
162 this.getBounds().wrap());
164 var expiry = new Date();
165 expiry.setYear(expiry.getFullYear() + 10);
166 $.cookie("_osm_location", cookieContent(this), { expires: expiry });
168 // Trigger hash update on layer changes.
169 this.hash.onMapMove();