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) {
37 .load(path, function(a, b, xhr) {
38 clearTimeout(loaderTimeout);
39 $('#sidebar_loader').hide();
40 if (xhr.getResponseHeader('X-Page-Title')) {
41 document.title = xhr.getResponseHeader('X-Page-Title');
50 $(document).ready(function () {
51 var params = OSM.mapParams();
53 var map = new L.OSM.Map("map", {
58 map.attributionControl.setPrefix('');
60 map.updateLayers(params.layers);
62 map.on("baselayerchange", function (e) {
63 if (map.getZoom() > e.layer.options.maxZoom) {
64 map.setView(map.getCenter(), e.layer.options.maxZoom, { reset: true });
68 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
70 L.OSM.zoom({position: position})
76 title: I18n.t('javascripts.map.locate.title'),
77 popup: I18n.t('javascripts.map.locate.popup')
81 var sidebar = L.OSM.sidebar('#map-ui')
86 layers: map.baseLayers,
109 if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
110 initializeNotes(map);
111 if (params.layers.indexOf(map.noteLayer.options.code) >= 0) {
112 map.addLayer(map.noteLayer);
115 initializeBrowse(map);
116 if (params.layers.indexOf(map.dataLayer.options.code) >= 0) {
117 map.addLayer(map.dataLayer);
121 $('.leaflet-control .control-button').tooltip({placement: 'left', container: 'body'});
123 map.on('moveend layeradd layerremove', function() {
125 map.getCenter().wrap(),
130 var expiry = new Date();
131 expiry.setYear(expiry.getFullYear() + 10);
132 $.cookie("_osm_location", cookieContent(map), { expires: expiry });
136 map.on('layeradd', function (e) {
137 if (e.layer.options) {
138 var goal = OSM.PIWIK.goals[e.layer.options.keyid];
141 $('body').trigger('piwikgoal', goal);
148 map.fitBounds(params.bounds);
150 map.setView([params.lat, params.lon], params.zoom);
153 var marker = L.marker([0, 0], {icon: getUserIcon()});
156 marker.setLatLng([params.mlat, params.mlon]).addTo(map);
159 $("#homeanchor").on("click", function(e) {
162 var data = $(this).data(),
163 center = L.latLng(data.lat, data.lon);
165 map.setView(center, data.zoom);
166 marker.setLatLng(center).addTo(map);
169 $("a[data-editor=remote]").click(function(e) {
170 remoteEditHandler(map.getBounds());
174 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
175 remoteEditHandler(map.getBounds());
178 if (OSM.params().edit_help) {
183 title: I18n.t('javascripts.edit_help')
187 $('body').one('click', function() {
188 $('#editanchor').tooltip('hide');
192 OSM.Index = function(map) {
195 page.pushstate = function(path) {
196 $("#content").addClass("overlay-sidebar");
197 map.invalidateSize({pan: false})
198 .panBy([-300, 0], {animate: false});
199 OSM.loadSidebarContent(path);
202 page.popstate = function(path) {
203 $("#content").addClass("overlay-sidebar");
204 map.invalidateSize({pan: false});
205 OSM.loadSidebarContent(path);
208 page.unload = function() {
209 map.panBy([300, 0], {animate: false});
210 $("#content").removeClass("overlay-sidebar");
211 map.invalidateSize({pan: false});
217 OSM.Browse = function(map) {
220 page.pushstate = page.popstate = function(path, type, id) {
221 OSM.loadSidebarContent(path, function() {
222 page.load(path, type, id);
226 page.load = function(path, type, id) {
227 if (OSM.STATUS === 'api_offline' || OSM.STATUS === 'database_offline') return;
229 map.addObject({type: type, id: parseInt(id)}, {zoom: window.location.hash == ""});
232 page.unload = function() {
239 var history = OSM.History(map),
240 note = OSM.Note(map);
242 OSM.route = OSM.Router(map, {
244 "/search": OSM.Search(map),
245 "/export": OSM.Export(map),
247 "/new_note": OSM.NewNote(map),
248 "/user/:display_name/edits": history,
249 "/browse/friends": history,
250 "/browse/nearby": history,
251 "/browse/note/:id": note,
252 "/browse/:type/:id(/history)": OSM.Browse(map)
255 $(document).on("click", "a", function(e) {
256 if (e.isDefaultPrevented() || e.isPropagationStopped()) return;
257 if (this.host === window.location.host && OSM.route(this.pathname + this.search + this.hash)) e.preventDefault();
260 $(".search_form").on("submit", function(e) {
262 $("header").addClass("closed");
263 OSM.route("/search?query=" + encodeURIComponent($(this).find("input[name=query]").val()) + OSM.formatHash(map));
266 $(".describe_location").on("click", function(e) {
268 var precision = zoomPrecision(map.getZoom());
269 OSM.route("/search?query=" + encodeURIComponent(
270 map.getCenter().lat.toFixed(precision) + "," +
271 map.getCenter().lng.toFixed(precision)));