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('');
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({code: 'N'});
54 map.dataLayer = new L.OSM.DataLayer(null);
56 $("#sidebar").on("opened closed", function () {
60 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
62 L.OSM.zoom({position: position})
65 L.control.locate({position: position})
68 var sidebar = L.OSM.sidebar('#map-ui')
84 getShortUrl: getShortUrl,
98 map.on('moveend layeradd layerremove', updateLocation);
100 map.markerLayer = L.layerGroup().addTo(map);
102 if (!params.object_zoom) {
104 var bbox = L.latLngBounds([params.minlat, params.minlon],
105 [params.maxlat, params.maxlon]);
117 map.setView([params.lat, params.lon], params.zoom);
122 var foundLayer = false;
123 for (var i = 0; i < layers.length; i++) {
124 if (params.layers.indexOf(layers[i].options.code) >= 0) {
125 map.addLayer(layers[i]);
128 map.removeLayer(layers[i]);
132 map.addLayer(layers[0]);
137 L.marker([params.mlat, params.mlon], {icon: getUserIcon()}).addTo(map.markerLayer);
141 addObjectToMap(params.object, map, { zoom: params.object_zoom });
144 $("body").on("click", "a.set_position", setPositionLink(map));
146 $("a[data-editor=remote]").click(function(e) {
147 remoteEditHandler(map.getBounds());
151 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
152 remoteEditHandler(map.getBounds());
155 $("#search_form").submit(submitSearch(map));
158 if ($("#query").val()) {
159 $("#search_form").submit();
162 // Focus the search field for browsers that don't support
163 // the HTML5 'autofocus' attribute
164 if (!("autofocus" in document.createElement("input"))) {
168 initializeExport(map);
169 initializeBrowse(map);
170 initializeNotes(map);
173 function updateLocation() {
174 updatelinks(this.getCenter().wrap(),
176 this.getLayersCode(),
177 this.getBounds().wrap());
179 var expiry = new Date();
180 expiry.setYear(expiry.getFullYear() + 10);
181 $.cookie("_osm_location", cookieContent(this), { expires: expiry });
184 function setPositionLink(map) {
186 var data = $(this).data(),
187 center = L.latLng(data.lat, data.lon);
189 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
190 map.fitBounds([[data.minLat, data.minLon],
191 [data.maxLat, data.maxLon]]);
193 map.setView(center, data.zoom);
196 if (data.type && data.id) {
197 addObjectToMap(data, map, { zoom: true, style: { opacity: 0.2, fill: false } });
200 map.markerLayer.clearLayers();
201 L.marker(center, {icon: getUserIcon()}).addTo(map.markerLayer);
203 return e.preventDefault();
207 function submitSearch(map) {
209 var bounds = map.getBounds();
211 $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
212 $("#sidebar_content").load($(this).attr("action"), {
213 query: $("#query").val(),
214 minlon: bounds.getWest(),
215 minlat: bounds.getSouth(),
216 maxlon: bounds.getEast(),
217 maxlat: bounds.getNorth()
220 return e.preventDefault();