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);
44 $('#sidebar_loader').hide();
46 var content = $(xhr.responseText);
48 if (xhr.getResponseHeader('X-Page-Title')) {
49 var title = xhr.getResponseHeader('X-Page-Title');
50 document.title = decodeURIComponent(escape(title));
54 .find('link[type="application/atom+xml"]')
58 .append(content.filter('link[type="application/atom+xml"]'));
60 $('#sidebar_content').html(content.not('link[type="application/atom+xml"]'));
70 $(document).ready(function () {
71 var params = OSM.mapParams();
73 var map = new L.OSM.Map("map", {
78 map.attributionControl.setPrefix('');
80 map.updateLayers(params.layers);
82 map.on("baselayerchange", function (e) {
83 if (map.getZoom() > e.layer.options.maxZoom) {
84 map.setView(map.getCenter(), e.layer.options.maxZoom, { reset: true });
88 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
90 L.OSM.zoom({position: position})
96 title: I18n.t('javascripts.map.locate.title'),
97 popup: I18n.t('javascripts.map.locate.popup')
101 var sidebar = L.OSM.sidebar('#map-ui')
106 layers: map.baseLayers,
129 if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
130 initializeNotes(map);
131 if (params.layers.indexOf(map.noteLayer.options.code) >= 0) {
132 map.addLayer(map.noteLayer);
135 initializeBrowse(map);
136 if (params.layers.indexOf(map.dataLayer.options.code) >= 0) {
137 map.addLayer(map.dataLayer);
141 $('.leaflet-control .control-button').tooltip({placement: 'left', container: 'body'});
143 var expiry = new Date();
144 expiry.setYear(expiry.getFullYear() + 10);
146 map.on('moveend layeradd layerremove', function() {
148 map.getCenter().wrap(),
153 $.cookie("_osm_location", cookieContent(map), { expires: expiry });
156 if ($.cookie('_osm_welcome') == 'hide') {
157 $('.welcome').hide();
160 $('.welcome .close').on('click', function() {
161 $('.welcome').hide();
162 $.cookie("_osm_welcome", 'hide', { expires: expiry });
166 map.on('layeradd', function (e) {
167 if (e.layer.options) {
168 var goal = OSM.PIWIK.goals[e.layer.options.keyid];
171 $('body').trigger('piwikgoal', goal);
178 map.fitBounds(params.bounds);
180 map.setView([params.lat, params.lon], params.zoom);
183 var marker = L.marker([0, 0], {icon: getUserIcon()});
186 marker.setLatLng([params.mlat, params.mlon]).addTo(map);
189 $("#homeanchor").on("click", function(e) {
192 var data = $(this).data(),
193 center = L.latLng(data.lat, data.lon);
195 map.setView(center, data.zoom);
196 marker.setLatLng(center).addTo(map);
199 $("a[data-editor=remote]").click(function(e) {
200 remoteEditHandler(map.getBounds());
204 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
205 remoteEditHandler(map.getBounds());
208 if (OSM.params().edit_help) {
213 title: I18n.t('javascripts.edit_help')
217 $('body').one('click', function() {
218 $('#editanchor').tooltip('hide');
222 OSM.Index = function(map) {
225 page.pushstate = function() {
226 $("#content").addClass("overlay-sidebar");
227 map.invalidateSize({pan: false})
228 .panBy([-350, 0], {animate: false});
231 page.load = function() {
232 return map.getState();
235 page.popstate = function() {
236 $("#content").addClass("overlay-sidebar");
237 map.invalidateSize({pan: false});
240 page.unload = function() {
241 map.panBy([350, 0], {animate: false});
242 $("#content").removeClass("overlay-sidebar");
243 map.invalidateSize({pan: false});
249 OSM.Browse = function(map, type) {
252 page.pushstate = page.popstate = function(path, id) {
253 OSM.loadSidebarContent(path, function() {
258 page.load = function(path, id) {
259 map.addObject({type: type, id: parseInt(id)});
262 page.unload = function() {
269 var history = OSM.History(map);
271 OSM.router = OSM.Router(map, {
273 "/search": OSM.Search(map),
274 "/export": OSM.Export(map),
275 "/note/new": OSM.NewNote(map),
276 "/history/friends": history,
277 "/history/nearby": history,
279 "/user/:display_name/history": history,
280 "/note/:id": OSM.Note(map),
281 "/node/:id(/history)": OSM.Browse(map, 'node'),
282 "/way/:id(/history)": OSM.Browse(map, 'way'),
283 "/relation/:id(/history)": OSM.Browse(map, 'relation'),
284 "/changeset/:id": OSM.Browse(map, 'changeset')
289 $(document).on("click", "a", function(e) {
290 if (e.isDefaultPrevented() || e.isPropagationStopped()) return;
291 if (this.host === window.location.host && OSM.router.route(this.pathname + this.search + this.hash)) e.preventDefault();
294 $(".search_form").on("submit", function(e) {
296 $("header").addClass("closed");
297 var query = $(this).find("input[name=query]").val();
299 OSM.router.route("/search?query=" + encodeURIComponent(query) + OSM.formatHash(map));
301 OSM.router.route("/" + OSM.formatHash(map));
305 $(".describe_location").on("click", function(e) {
307 var precision = zoomPrecision(map.getZoom());
308 OSM.router.route("/search?query=" + encodeURIComponent(
309 map.getCenter().lat.toFixed(precision) + "," +
310 map.getCenter().lng.toFixed(precision)));