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();
45 $('#sidebar_content').html(xhr.responseText);
46 if (xhr.getResponseHeader('X-Page-Title')) {
47 document.title = xhr.getResponseHeader('X-Page-Title');
57 $(document).ready(function () {
58 var params = OSM.mapParams();
60 var map = new L.OSM.Map("map", {
65 map.attributionControl.setPrefix('');
67 map.updateLayers(params.layers);
69 map.on("baselayerchange", function (e) {
70 if (map.getZoom() > e.layer.options.maxZoom) {
71 map.setView(map.getCenter(), e.layer.options.maxZoom, { reset: true });
75 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
77 L.OSM.zoom({position: position})
83 title: I18n.t('javascripts.map.locate.title'),
84 popup: I18n.t('javascripts.map.locate.popup')
88 var sidebar = L.OSM.sidebar('#map-ui')
93 layers: map.baseLayers,
116 if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
117 initializeNotes(map);
118 if (params.layers.indexOf(map.noteLayer.options.code) >= 0) {
119 map.addLayer(map.noteLayer);
122 initializeBrowse(map);
123 if (params.layers.indexOf(map.dataLayer.options.code) >= 0) {
124 map.addLayer(map.dataLayer);
128 $('.leaflet-control .control-button').tooltip({placement: 'left', container: 'body'});
130 map.on('moveend layeradd layerremove', function() {
132 map.getCenter().wrap(),
137 var expiry = new Date();
138 expiry.setYear(expiry.getFullYear() + 10);
139 $.cookie("_osm_location", cookieContent(map), { expires: expiry });
143 map.on('layeradd', function (e) {
144 if (e.layer.options) {
145 var goal = OSM.PIWIK.goals[e.layer.options.keyid];
148 $('body').trigger('piwikgoal', goal);
155 map.fitBounds(params.bounds);
157 map.setView([params.lat, params.lon], params.zoom);
160 var marker = L.marker([0, 0], {icon: getUserIcon()});
163 marker.setLatLng([params.mlat, params.mlon]).addTo(map);
166 $("#homeanchor").on("click", function(e) {
169 var data = $(this).data(),
170 center = L.latLng(data.lat, data.lon);
172 map.setView(center, data.zoom);
173 marker.setLatLng(center).addTo(map);
176 $("a[data-editor=remote]").click(function(e) {
177 remoteEditHandler(map.getBounds());
181 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
182 remoteEditHandler(map.getBounds());
185 if (OSM.params().edit_help) {
190 title: I18n.t('javascripts.edit_help')
194 $('body').one('click', function() {
195 $('#editanchor').tooltip('hide');
199 OSM.Index = function(map) {
202 page.pushstate = function() {
203 $("#content").addClass("overlay-sidebar");
204 map.invalidateSize({pan: false})
205 .panBy([-350, 0], {animate: false});
208 page.load = function() {
209 return map.getState();
212 page.popstate = function() {
213 $("#content").addClass("overlay-sidebar");
214 map.invalidateSize({pan: false});
217 page.unload = function() {
218 map.panBy([350, 0], {animate: false});
219 $("#content").removeClass("overlay-sidebar");
220 map.invalidateSize({pan: false});
226 OSM.Browse = function(map) {
229 page.pushstate = page.popstate = function(path, type, id) {
230 OSM.loadSidebarContent(path, function() {
231 page.load(path, type, id);
235 page.load = function(path, type, id) {
236 map.addObject({type: type, id: parseInt(id)});
239 page.unload = function() {
246 var history = OSM.History(map);
248 OSM.router = OSM.Router(map, {
250 "/search": OSM.Search(map),
251 "/export": OSM.Export(map),
252 "/new_note": OSM.NewNote(map),
254 "/user/:display_name/edits": history,
255 "/browse/friends": history,
256 "/browse/nearby": history,
257 "/browse/note/:id": OSM.Note(map),
258 "/browse/:type/:id(/history)": OSM.Browse(map)
263 $(document).on("click", "a", function(e) {
264 if (e.isDefaultPrevented() || e.isPropagationStopped()) return;
265 if (this.host === window.location.host && OSM.router.route(this.pathname + this.search + this.hash)) e.preventDefault();
268 $(".search_form").on("submit", function(e) {
270 $("header").addClass("closed");
271 var query = $(this).find("input[name=query]").val();
273 OSM.router.route("/search?query=" + encodeURIComponent(query) + OSM.formatHash(map));
275 OSM.router.route("/" + OSM.formatHash(map));
279 $(".describe_location").on("click", function(e) {
281 var precision = zoomPrecision(map.getZoom());
282 OSM.router.route("/search?query=" + encodeURIComponent(
283 map.getCenter().lat.toFixed(precision) + "," +
284 map.getCenter().lng.toFixed(precision)));