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
12 //= require index/history
13 //= require index/note
14 //= require index/new_note
20 OSM.loadSidebarContent = function(path, callback) {
21 clearTimeout(loaderTimeout);
23 loaderTimeout = setTimeout(function() {
24 $('#sidebar_loader').show();
27 // IE<10 doesn't respect Vary: X-Requested-With header, so
28 // prevent caching the XHR response as a full-page URL.
29 if (path.indexOf('?') >= 0) {
41 complete: function(xhr) {
42 clearTimeout(loaderTimeout);
43 $('#sidebar_loader').hide();
44 $('#sidebar_content').html(xhr.responseText);
45 if (xhr.getResponseHeader('X-Page-Title')) {
46 document.title = xhr.getResponseHeader('X-Page-Title');
56 $(document).ready(function () {
57 var params = OSM.mapParams();
59 var map = new L.OSM.Map("map", {
64 map.attributionControl.setPrefix('');
66 map.updateLayers(params.layers);
68 map.on("baselayerchange", function (e) {
69 if (map.getZoom() > e.layer.options.maxZoom) {
70 map.setView(map.getCenter(), e.layer.options.maxZoom, { reset: true });
74 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
76 L.OSM.zoom({position: position})
82 title: I18n.t('javascripts.map.locate.title'),
83 popup: I18n.t('javascripts.map.locate.popup')
87 var sidebar = L.OSM.sidebar('#map-ui')
92 layers: map.baseLayers,
115 if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
116 initializeNotes(map);
117 if (params.layers.indexOf(map.noteLayer.options.code) >= 0) {
118 map.addLayer(map.noteLayer);
121 initializeBrowse(map);
122 if (params.layers.indexOf(map.dataLayer.options.code) >= 0) {
123 map.addLayer(map.dataLayer);
127 $('.leaflet-control .control-button').tooltip({placement: 'left', container: 'body'});
129 map.on('moveend layeradd layerremove', function() {
131 map.getCenter().wrap(),
136 var expiry = new Date();
137 expiry.setYear(expiry.getFullYear() + 10);
138 $.cookie("_osm_location", cookieContent(map), { expires: expiry });
142 map.on('layeradd', function (e) {
143 if (e.layer.options) {
144 var goal = OSM.PIWIK.goals[e.layer.options.keyid];
147 $('body').trigger('piwikgoal', goal);
154 map.fitBounds(params.bounds);
156 map.setView([params.lat, params.lon], params.zoom);
159 var marker = L.marker([0, 0], {icon: getUserIcon()});
162 marker.setLatLng([params.mlat, params.mlon]).addTo(map);
165 $("#homeanchor").on("click", function(e) {
168 var data = $(this).data(),
169 center = L.latLng(data.lat, data.lon);
171 map.setView(center, data.zoom);
172 marker.setLatLng(center).addTo(map);
175 $("a[data-editor=remote]").click(function(e) {
176 remoteEditHandler(map.getBounds());
180 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
181 remoteEditHandler(map.getBounds());
184 if (OSM.params().edit_help) {
189 title: I18n.t('javascripts.edit_help')
193 $('body').one('click', function() {
194 $('#editanchor').tooltip('hide');
198 OSM.Index = function(map) {
201 page.pushstate = function(path) {
202 $("#content").addClass("overlay-sidebar");
203 map.invalidateSize({pan: false})
204 .panBy([-300, 0], {animate: false});
205 OSM.loadSidebarContent(path);
209 page.load = function() {
210 return map.getState();
213 page.popstate = function(path) {
214 $("#content").addClass("overlay-sidebar");
215 map.invalidateSize({pan: false});
216 OSM.loadSidebarContent(path);
219 page.unload = function() {
220 map.panBy([300, 0], {animate: false});
221 $("#content").removeClass("overlay-sidebar");
222 map.invalidateSize({pan: false});
228 OSM.Browse = function(map) {
231 page.pushstate = page.popstate = function(path, type, id) {
232 OSM.loadSidebarContent(path, function() {
233 page.load(path, type, id);
237 page.load = function(path, type, id) {
238 map.addObject({type: type, id: parseInt(id)});
241 page.unload = function() {
248 var history = OSM.History(map),
249 note = OSM.Note(map);
251 OSM.route = OSM.Router(map, {
253 "/search": OSM.Search(map),
254 "/export": OSM.Export(map),
256 "/new_note": OSM.NewNote(map),
257 "/user/:display_name/edits": history,
258 "/browse/friends": history,
259 "/browse/nearby": history,
260 "/browse/note/:id": note,
261 "/browse/:type/:id(/history)": OSM.Browse(map)
266 $(document).on("click", "a", function(e) {
267 if (e.isDefaultPrevented() || e.isPropagationStopped()) return;
268 if (this.host === window.location.host && OSM.route(this.pathname + this.search + this.hash)) e.preventDefault();
271 $(".search_form").on("submit", function(e) {
273 $("header").addClass("closed");
274 var query = $(this).find("input[name=query]").val();
276 OSM.route("/search?query=" + encodeURIComponent(query) + OSM.formatHash(map));
278 OSM.route("/" + OSM.formatHash(map));
282 $(".describe_location").on("click", function(e) {
284 var precision = zoomPrecision(map.getZoom());
285 OSM.route("/search?query=" + encodeURIComponent(
286 map.getCenter().lat.toFixed(precision) + "," +
287 map.getCenter().lng.toFixed(precision)));