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 document.title = xhr.getResponseHeader('X-Page-Title');
53 .find('link[type="application/atom+xml"]')
57 .append(content.filter('link[type="application/atom+xml"]'));
59 $('#sidebar_content').html(content.not('link[type="application/atom+xml"]'));
69 $(document).ready(function () {
70 var params = OSM.mapParams();
72 var map = new L.OSM.Map("map", {
77 map.attributionControl.setPrefix('');
79 map.updateLayers(params.layers);
81 map.on("baselayerchange", function (e) {
82 if (map.getZoom() > e.layer.options.maxZoom) {
83 map.setView(map.getCenter(), e.layer.options.maxZoom, { reset: true });
87 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
89 L.OSM.zoom({position: position})
95 title: I18n.t('javascripts.map.locate.title'),
96 popup: I18n.t('javascripts.map.locate.popup')
100 var sidebar = L.OSM.sidebar('#map-ui')
105 layers: map.baseLayers,
128 if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
129 initializeNotes(map);
130 if (params.layers.indexOf(map.noteLayer.options.code) >= 0) {
131 map.addLayer(map.noteLayer);
134 initializeBrowse(map);
135 if (params.layers.indexOf(map.dataLayer.options.code) >= 0) {
136 map.addLayer(map.dataLayer);
140 $('.leaflet-control .control-button').tooltip({placement: 'left', container: 'body'});
142 map.on('moveend layeradd layerremove', function() {
144 map.getCenter().wrap(),
149 var expiry = new Date();
150 expiry.setYear(expiry.getFullYear() + 10);
151 $.cookie("_osm_location", cookieContent(map), { expires: expiry });
155 map.on('layeradd', function (e) {
156 if (e.layer.options) {
157 var goal = OSM.PIWIK.goals[e.layer.options.keyid];
160 $('body').trigger('piwikgoal', goal);
167 map.fitBounds(params.bounds);
169 map.setView([params.lat, params.lon], params.zoom);
172 var marker = L.marker([0, 0], {icon: getUserIcon()});
175 marker.setLatLng([params.mlat, params.mlon]).addTo(map);
178 $("#homeanchor").on("click", function(e) {
181 var data = $(this).data(),
182 center = L.latLng(data.lat, data.lon);
184 map.setView(center, data.zoom);
185 marker.setLatLng(center).addTo(map);
188 $("a[data-editor=remote]").click(function(e) {
189 remoteEditHandler(map.getBounds());
193 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
194 remoteEditHandler(map.getBounds());
197 if (OSM.params().edit_help) {
202 title: I18n.t('javascripts.edit_help')
206 $('body').one('click', function() {
207 $('#editanchor').tooltip('hide');
211 OSM.Index = function(map) {
214 page.pushstate = function() {
215 $("#content").addClass("overlay-sidebar");
216 map.invalidateSize({pan: false})
217 .panBy([-350, 0], {animate: false});
220 page.load = function() {
221 return map.getState();
224 page.popstate = function() {
225 $("#content").addClass("overlay-sidebar");
226 map.invalidateSize({pan: false});
229 page.unload = function() {
230 map.panBy([350, 0], {animate: false});
231 $("#content").removeClass("overlay-sidebar");
232 map.invalidateSize({pan: false});
238 OSM.Browse = function(map, type) {
241 page.pushstate = page.popstate = function(path, id) {
242 OSM.loadSidebarContent(path, function() {
247 page.load = function(path, id) {
248 map.addObject({type: type, id: parseInt(id)});
251 page.unload = function() {
258 var history = OSM.History(map);
260 OSM.router = OSM.Router(map, {
262 "/search": OSM.Search(map),
263 "/export": OSM.Export(map),
264 "/note/new": OSM.NewNote(map),
265 "/history/friends": history,
266 "/history/nearby": history,
268 "/user/:display_name/history": history,
269 "/note/:id": OSM.Note(map),
270 "/node/:id(/history)": OSM.Browse(map, 'node'),
271 "/way/:id(/history)": OSM.Browse(map, 'way'),
272 "/relation/:id(/history)": OSM.Browse(map, 'relation'),
273 "/changeset/:id": OSM.Browse(map, 'changeset')
278 $(document).on("click", "a", function(e) {
279 if (e.isDefaultPrevented() || e.isPropagationStopped()) return;
280 if (this.host === window.location.host && OSM.router.route(this.pathname + this.search + this.hash)) e.preventDefault();
283 $(".search_form").on("submit", function(e) {
285 $("header").addClass("closed");
286 var query = $(this).find("input[name=query]").val();
288 OSM.router.route("/search?query=" + encodeURIComponent(query) + OSM.formatHash(map));
290 OSM.router.route("/" + OSM.formatHash(map));
294 $(".describe_location").on("click", function(e) {
296 var precision = zoomPrecision(map.getZoom());
297 OSM.router.route("/search?query=" + encodeURIComponent(
298 map.getCenter().lat.toFixed(precision) + "," +
299 map.getCenter().lng.toFixed(precision)));