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/browse
9 //= require index/export
10 //= require index/notes
12 $(document).ready(function () {
13 var params = OSM.mapParams();
15 var map = L.map("map", {
20 map.attributionControl.setPrefix('');
22 map.hash = L.hash(map);
29 name: I18n.t("javascripts.map.base.standard")
32 attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
35 name: I18n.t("javascripts.map.base.cycle_map")
37 new L.OSM.TransportMap({
38 attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
40 keyid: "transportmap",
41 name: I18n.t("javascripts.map.base.transport_map")
43 new L.OSM.MapQuestOpen({
44 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'>",
47 name: I18n.t("javascripts.map.base.mapquest")
53 map.noteLayer = new L.LayerGroup();
54 map.noteLayer.options = {code: 'N'};
56 map.dataLayer = new L.OSM.DataLayer(null);
57 map.dataLayer.options.code = 'D';
59 $("#sidebar").on("opened closed", function () {
63 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
65 L.OSM.zoom({position: position})
68 L.control.locate({position: position})
71 var sidebar = L.OSM.sidebar('#map-ui')
99 map.on('moveend layeradd layerremove', updateLocation);
101 map.markerLayer = L.layerGroup().addTo(map);
103 if (!params.object_zoom) {
105 map.fitBounds(params.bounds);
107 map.setView([params.lat, params.lon], params.zoom);
112 L.rectangle(params.box, {
120 var foundLayer = false;
121 for (var i = 0; i < layers.length; i++) {
122 if (params.layers.indexOf(layers[i].options.code) >= 0) {
123 map.addLayer(layers[i]);
126 map.removeLayer(layers[i]);
130 map.addLayer(layers[0]);
135 L.marker([params.mlat, params.mlon], {icon: getUserIcon()}).addTo(map.markerLayer);
139 addObjectToMap(params.object, map, { zoom: params.object_zoom });
142 $("body").on("click", "a.set_position", setPositionLink(map));
144 $("a[data-editor=remote]").click(function(e) {
145 remoteEditHandler(map.getBounds());
149 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
150 remoteEditHandler(map.getBounds());
153 $("#search_form").submit(submitSearch(map));
156 if ($("#query").val()) {
157 $("#search_form").submit();
160 // Focus the search field for browsers that don't support
161 // the HTML5 'autofocus' attribute
162 if (!("autofocus" in document.createElement("input"))) {
166 initializeExport(map);
167 initializeBrowse(map, params);
168 initializeNotes(map, params);
171 function updateLocation() {
172 updatelinks(this.getCenter().wrap(),
174 this.getLayersCode(),
175 this.getBounds().wrap());
177 var expiry = new Date();
178 expiry.setYear(expiry.getFullYear() + 10);
179 $.cookie("_osm_location", cookieContent(this), { expires: expiry });
181 // Trigger hash update on layer changes.
182 this.hash.onMapMove();
185 function setPositionLink(map) {
187 var data = $(this).data(),
188 center = L.latLng(data.lat, data.lon);
190 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
191 map.fitBounds([[data.minLat, data.minLon],
192 [data.maxLat, data.maxLon]]);
194 map.setView(center, data.zoom);
197 if (data.type && data.id) {
198 addObjectToMap(data, map, { zoom: true, style: { opacity: 0.2, fill: false } });
201 map.markerLayer.clearLayers();
202 L.marker(center, {icon: getUserIcon()}).addTo(map.markerLayer);
204 return e.preventDefault();
208 function submitSearch(map) {
210 var bounds = map.getBounds();
212 $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
213 $("#sidebar_content").load($(this).attr("action"), {
214 query: $("#query").val(),
215 minlon: bounds.getWest(),
216 minlat: bounds.getSouth(),
217 maxlon: bounds.getEast(),
218 maxlat: bounds.getNorth()
221 return e.preventDefault();