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() {
202 $("#content").addClass("overlay-sidebar");
203 map.invalidateSize({pan: false})
204 .panBy([-350, 0], {animate: false});
207 page.load = function() {
208 return map.getState();
211 page.popstate = function() {
212 $("#content").addClass("overlay-sidebar");
213 map.invalidateSize({pan: false});
216 page.unload = function() {
217 map.panBy([350, 0], {animate: false});
218 $("#content").removeClass("overlay-sidebar");
219 map.invalidateSize({pan: false});
225 OSM.Browse = function(map) {
228 page.pushstate = page.popstate = function(path, type, id) {
229 OSM.loadSidebarContent(path, function() {
230 page.load(path, type, id);
234 page.load = function(path, type, id) {
235 map.addObject({type: type, id: parseInt(id)});
238 page.unload = function() {
245 var history = OSM.History(map);
247 OSM.route = OSM.Router(map, {
249 "/search": OSM.Search(map),
250 "/export": OSM.Export(map),
251 "/new_note": OSM.NewNote(map),
253 "/user/:display_name/edits": history,
254 "/browse/friends": history,
255 "/browse/nearby": history,
256 "/browse/note/:id": OSM.Note(map),
257 "/browse/:type/:id(/history)": OSM.Browse(map)
262 $(document).on("click", "a", function(e) {
263 if (e.isDefaultPrevented() || e.isPropagationStopped()) return;
264 if (this.host === window.location.host && OSM.route(this.pathname + this.search + this.hash)) e.preventDefault();
267 $(".search_form").on("submit", function(e) {
269 $("header").addClass("closed");
270 var query = $(this).find("input[name=query]").val();
272 OSM.route("/search?query=" + encodeURIComponent(query) + OSM.formatHash(map));
274 OSM.route("/" + OSM.formatHash(map));
278 $(".describe_location").on("click", function(e) {
280 var precision = zoomPrecision(map.getZoom());
281 OSM.route("/search?query=" + encodeURIComponent(
282 map.getCenter().lat.toFixed(precision) + "," +
283 map.getCenter().lng.toFixed(precision)));