2 //= require leaflet.sidebar
3 //= require leaflet.customzoom
4 //= require leaflet.locate
5 //= require leaflet.layers
6 //= require leaflet.key
7 //= require leaflet.note
8 //= require leaflet.share
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('');
28 name: I18n.t("javascripts.map.base.standard")
31 attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
34 name: I18n.t("javascripts.map.base.cycle_map")
36 new L.OSM.TransportMap({
37 attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
39 keyid: "transportmap",
40 name: I18n.t("javascripts.map.base.transport_map")
42 new L.OSM.MapQuestOpen({
43 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'>",
46 name: I18n.t("javascripts.map.base.mapquest")
52 map.noteLayer = new L.LayerGroup({code: 'N'});
53 map.dataLayer = new L.OSM.DataLayer(null);
55 $("#map").on("resized", function () {
59 L.control.customZoom({position: 'topright'})
62 L.control.locate({position: 'topright'})
65 var sidebar = L.OSM.sidebar('#map-ui');
84 getShortUrl: getShortUrl,
93 map.on('moveend layeradd layerremove', updateLocation);
95 map.markerLayer = L.layerGroup().addTo(map);
97 if (!params.object_zoom) {
99 var bbox = L.latLngBounds([params.minlat, params.minlon],
100 [params.maxlat, params.maxlon]);
112 map.setView([params.lat, params.lon], params.zoom);
117 var foundLayer = false;
118 for (var i = 0; i < layers.length; i++) {
119 if (params.layers.indexOf(layers[i].options.code) >= 0) {
120 map.addLayer(layers[i]);
123 map.removeLayer(layers[i]);
127 map.addLayer(layers[0]);
132 L.marker([params.mlat, params.mlon], {icon: getUserIcon()}).addTo(map.markerLayer);
136 addObjectToMap(params.object, map, { zoom: params.object_zoom });
141 $("body").on("click", "a.set_position", setPositionLink(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 $(window).resize(handleResize);
154 $("#search_form").submit(submitSearch(map));
157 if ($("#query").val()) {
158 $("#search_form").submit();
161 // Focus the search field for browsers that don't support
162 // the HTML5 'autofocus' attribute
163 if (!("autofocus" in document.createElement("input"))) {
167 initializeExport(map);
168 initializeBrowse(map);
169 initializeNotes(map);
172 function updateLocation() {
173 updatelinks(this.getCenter().wrap(),
175 this.getLayersCode(),
176 this.getBounds().wrap(), {});
178 var expiry = new Date();
179 expiry.setYear(expiry.getFullYear() + 10);
180 $.cookie("_osm_location", cookieContent(this), { expires: expiry });
183 function setPositionLink(map) {
185 var data = $(this).data(),
186 center = L.latLng(data.lat, data.lon);
188 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
189 map.fitBounds([[data.minLat, data.minLon],
190 [data.maxLat, data.maxLon]]);
192 map.setView(center, data.zoom);
195 if (data.type && data.id) {
196 addObjectToMap(data, map, { zoom: true, style: { opacity: 0.2, fill: false } });
199 map.markerLayer.clearLayers();
200 L.marker(center, {icon: getUserIcon()}).addTo(map.markerLayer);
202 return e.preventDefault();
206 function submitSearch(map) {
208 var bounds = map.getBounds();
210 $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
211 $("#sidebar_content").load($(this).attr("action"), {
212 query: $("#query").val(),
213 minlon: bounds.getWestLng(),
214 minlat: bounds.getSouthLat(),
215 maxlon: bounds.getEastLng(),
216 maxlat: bounds.getNorthLat()
219 return e.preventDefault();