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")
51 for (var i = layers.length - 1; i >= 0; i--) {
52 if (i === 0 || params.layers.indexOf(layers[i].options.code) >= 0) {
53 map.addLayer(layers[i]);
58 map.noteLayer = new L.LayerGroup();
59 map.noteLayer.options = {code: 'N'};
61 map.dataLayer = new L.OSM.DataLayer(null);
62 map.dataLayer.options.code = 'D';
64 $("#sidebar").on("opened closed", function () {
68 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
70 L.OSM.zoom({position: position})
73 L.control.locate({position: position})
76 var sidebar = L.OSM.sidebar('#map-ui')
104 map.on('moveend layeradd layerremove', updateLocation);
106 map.markerLayer = L.layerGroup().addTo(map);
108 if (!params.object_zoom) {
110 map.fitBounds(params.bounds);
112 map.setView([params.lat, params.lon], params.zoom);
117 L.rectangle(params.box, {
125 L.marker([params.mlat, params.mlon], {icon: getUserIcon()}).addTo(map.markerLayer);
129 map.addObject(params.object, { zoom: params.object_zoom });
132 $("body").on("click", "a.set_position", setPositionLink(map));
134 $("a[data-editor=remote]").click(function(e) {
135 remoteEditHandler(map.getBounds());
139 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
140 remoteEditHandler(map.getBounds());
143 $("#search_form").submit(submitSearch(map));
146 if ($("#query").val()) {
147 $("#search_form").submit();
150 // Focus the search field for browsers that don't support
151 // the HTML5 'autofocus' attribute
152 if (!("autofocus" in document.createElement("input"))) {
156 initializeExport(map);
157 initializeBrowse(map, params);
158 initializeNotes(map, params);
161 function updateLocation() {
162 updatelinks(this.getCenter().wrap(),
164 this.getLayersCode(),
165 this.getBounds().wrap());
167 var expiry = new Date();
168 expiry.setYear(expiry.getFullYear() + 10);
169 $.cookie("_osm_location", cookieContent(this), { expires: expiry });
171 // Trigger hash update on layer changes.
172 this.hash.onMapMove();
175 function setPositionLink(map) {
177 var data = $(this).data(),
178 center = L.latLng(data.lat, data.lon);
180 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
181 map.fitBounds([[data.minLat, data.minLon],
182 [data.maxLat, data.maxLon]]);
184 map.setView(center, data.zoom);
187 if (data.type && data.id) {
188 map.addObject(data, { zoom: false, style: { opacity: 0.2, fill: false } });
191 map.markerLayer.clearLayers();
192 L.marker(center, {icon: getUserIcon()}).addTo(map.markerLayer);
194 return e.preventDefault();
198 function submitSearch(map) {
200 var bounds = map.getBounds();
202 $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
203 $("#sidebar_content").load($(this).attr("action"), {
204 query: $("#query").val(),
205 minlon: bounds.getWest(),
206 minlat: bounds.getSouth(),
207 maxlon: bounds.getEast(),
208 maxlat: bounds.getNorth()
211 return e.preventDefault();