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);
208 page.popstate = function(path) {
209 $("#content").addClass("overlay-sidebar");
210 map.invalidateSize({pan: false});
211 OSM.loadSidebarContent(path);
214 page.unload = function() {
215 map.panBy([300, 0], {animate: false});
216 $("#content").removeClass("overlay-sidebar");
217 map.invalidateSize({pan: false});
223 OSM.Browse = function(map) {
226 page.pushstate = page.popstate = function(path, type, id) {
227 OSM.loadSidebarContent(path, function() {
228 page.load(path, type, id);
232 page.load = function(path, type, id) {
233 map.addObject({type: type, id: parseInt(id)});
236 page.unload = function() {
243 var history = OSM.History(map),
244 note = OSM.Note(map);
246 OSM.route = OSM.Router(map, {
248 "/search": OSM.Search(map),
249 "/export": OSM.Export(map),
251 "/new_note": OSM.NewNote(map),
252 "/user/:display_name/edits": history,
253 "/browse/friends": history,
254 "/browse/nearby": history,
255 "/browse/note/:id": note,
256 "/browse/:type/:id(/history)": OSM.Browse(map)
259 $(document).on("click", "a", function(e) {
260 if (e.isDefaultPrevented() || e.isPropagationStopped()) return;
261 if (this.host === window.location.host && OSM.route(this.pathname + this.search + this.hash)) e.preventDefault();
264 $(".search_form").on("submit", function(e) {
266 $("#header").addClass("closed");
267 var query = $(this).find("input[name=query]").val();
269 OSM.route("/search?query=" + encodeURIComponent(query) + OSM.formatHash(map));
271 OSM.route("/" + OSM.formatHash(map));
275 $(".describe_location").on("click", function(e) {
277 var precision = zoomPrecision(map.getZoom());
278 OSM.route("/search?query=" + encodeURIComponent(
279 map.getCenter().lat.toFixed(precision) + "," +
280 map.getCenter().lng.toFixed(precision)));