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
17 $(document).ready(function () {
18 var params = OSM.mapParams();
20 var map = new L.OSM.Map("map", {
25 map.attributionControl.setPrefix('');
27 map.updateLayers(params.layers);
29 map.on("baselayerchange", function (e) {
30 if (map.getZoom() > e.layer.options.maxZoom) {
31 map.setView(map.getCenter(), e.layer.options.maxZoom, { reset: true });
35 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
37 L.OSM.zoom({position: position})
43 title: I18n.t('javascripts.map.locate.title'),
44 popup: I18n.t('javascripts.map.locate.popup')
48 var sidebar = L.OSM.sidebar('#map-ui')
53 layers: map.baseLayers,
76 if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
78 if (params.layers.indexOf(map.noteLayer.options.code) >= 0) {
79 map.addLayer(map.noteLayer);
82 initializeBrowse(map);
83 if (params.layers.indexOf(map.dataLayer.options.code) >= 0) {
84 map.addLayer(map.dataLayer);
88 $('.leaflet-control .control-button').tooltip({placement: 'left', container: 'body'});
90 map.on('moveend layeradd layerremove', function() {
92 map.getCenter().wrap(),
97 var expiry = new Date();
98 expiry.setYear(expiry.getFullYear() + 10);
99 $.cookie("_osm_location", cookieContent(map), { expires: expiry });
103 map.on('layeradd', function (e) {
104 if (e.layer.options) {
105 var goal = OSM.PIWIK.goals[e.layer.options.keyid];
108 $('body').trigger('piwikgoal', goal);
115 map.fitBounds(params.bounds);
117 map.setView([params.lat, params.lon], params.zoom);
120 var marker = L.marker([0, 0], {icon: getUserIcon()});
123 marker.setLatLng([params.mlat, params.mlon]).addTo(map);
126 $("#homeanchor").on("click", function(e) {
129 var data = $(this).data(),
130 center = L.latLng(data.lat, data.lon);
132 map.setView(center, data.zoom);
133 marker.setLatLng(center).addTo(map);
136 $("a[data-editor=remote]").click(function(e) {
137 remoteEditHandler(map.getBounds());
141 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
142 remoteEditHandler(map.getBounds());
145 if (OSM.params().edit_help) {
150 title: I18n.t('javascripts.edit_help')
154 $('body').one('click', function() {
155 $('#editanchor').tooltip('hide');
159 OSM.Index = function(map) {
162 function loadContent(path) {
163 $('#sidebar_content').load(path + "?xhr=1", function(a, b, xhr) {
164 if (xhr.getResponseHeader('X-Page-Title')) {
165 document.title = xhr.getResponseHeader('X-Page-Title');
170 page.pushstate = function(path) {
171 $("#content").addClass("overlay-sidebar");
172 map.invalidateSize({pan: false})
173 .panBy([-300, 0], {animate: false});
177 page.popstate = function(path) {
178 $("#content").addClass("overlay-sidebar");
179 map.invalidateSize({pan: false});
183 page.unload = function() {
184 map.panBy([300, 0], {animate: false});
185 $("#content").removeClass("overlay-sidebar");
186 map.invalidateSize({pan: false});
192 OSM.Browse = function(map) {
195 page.pushstate = page.popstate = function(path, type, id) {
196 $('#sidebar_content').load(path + "?xhr=1", function(a, b, xhr) {
197 if (xhr.getResponseHeader('X-Page-Title')) {
198 document.title = xhr.getResponseHeader('X-Page-Title');
200 page.load(path, type, id);
204 page.load = function(path, type, id) {
205 if (OSM.STATUS === 'api_offline' || OSM.STATUS === 'database_offline') return;
207 map.addObject({type: type, id: parseInt(id)}, {zoom: window.location.hash == ""});
210 page.unload = function() {
217 var history = OSM.History(map),
218 note = OSM.Note(map);
220 OSM.route = OSM.Router(map, {
222 "/search": OSM.Search(map),
223 "/export": OSM.Export(map),
225 "/new_note": OSM.NewNote(map),
226 "/user/:display_name/edits": history,
227 "/browse/friends": history,
228 "/browse/nearby": history,
229 "/browse/note/:id": note,
230 "/browse/:type/:id(/history)": OSM.Browse(map)
233 $(document).on("click", "a", function(e) {
234 if (e.isDefaultPrevented() || e.isPropagationStopped()) return;
235 if (this.host === window.location.host && OSM.route(this.pathname + this.search + this.hash)) e.preventDefault();
238 $(".search_form").on("submit", function(e) {
240 $("header").addClass("closed");
241 OSM.route("/search?query=" + encodeURIComponent($(this).find("input[name=query]").val()) + OSM.formatHash(map));
244 $(".describe_location").on("click", function(e) {
246 var precision = zoomPrecision(map.getZoom());
247 OSM.route("/search?query=" + encodeURIComponent(
248 map.getCenter().lat.toFixed(precision) + "," +
249 map.getCenter().lng.toFixed(precision)));