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
13 $(document).ready(function () {
14 var params = OSM.mapParams();
16 var map = L.map("map", {
21 map.attributionControl.setPrefix('');
23 map.hash = L.hash(map);
25 var copyright = I18n.t('javascripts.map.copyright', {copyright_url: '/copyright'});
29 attribution: copyright,
32 name: I18n.t("javascripts.map.base.standard")
35 attribution: copyright + ". Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
38 name: I18n.t("javascripts.map.base.cycle_map")
40 new L.OSM.TransportMap({
41 attribution: copyright + ". Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
43 keyid: "transportmap",
44 name: I18n.t("javascripts.map.base.transport_map")
46 new L.OSM.MapQuestOpen({
47 attribution: copyright + ". Tiles courtesy of <a href='http://www.mapquest.com/' target='_blank'>MapQuest</a> <img src='http://developer.mapquest.com/content/osm/mq_logo.png'>",
50 name: I18n.t("javascripts.map.base.mapquest")
54 function updateLayers(params) {
55 var layerParam = params.layers || "M";
57 for (var i = layers.length - 1; i >= 0; i--) {
58 if (layerParam.indexOf(layers[i].options.code) >= 0) {
59 map.addLayer(layers[i]);
61 map.removeLayer(layers[i]);
68 $(window).on("hashchange", function () {
69 updateLayers(OSM.mapParams());
72 map.noteLayer = new L.LayerGroup();
73 map.noteLayer.options = {code: 'N'};
75 map.dataLayer = new L.OSM.DataLayer(null);
76 map.dataLayer.options.code = 'D';
78 $("#sidebar").on("opened closed", function () {
82 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
84 L.OSM.zoom({position: position})
90 title: I18n.t('javascripts.map.locate.title'),
91 popup: I18n.t('javascripts.map.locate.popup')
95 var sidebar = L.OSM.sidebar('#map-ui')
123 $('.leaflet-control .control-button').tooltip({placement: 'left', container: 'body'});
125 map.on('moveend layeradd layerremove', updateLocation);
128 map.on('layeradd', function (e) {
129 if (e.layer.options) {
130 var goal = OSM.PIWIK.goals[e.layer.options.keyid];
133 $('body').trigger('piwikgoal', goal);
139 var marker = L.marker([0, 0], {icon: getUserIcon()});
141 if (!params.object_zoom) {
143 map.fitBounds(params.bounds);
145 map.setView([params.lat, params.lon], params.zoom);
150 L.rectangle(params.box, {
158 marker.setLatLng([params.mlat, params.mlon]).addTo(map);
162 map.addObject(params.object, { zoom: params.object_zoom });
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 initializeSearch(map);
199 initializeExport(map);
200 initializeBrowse(map, params);
201 initializeNotes(map, params);
204 function updateLocation() {
205 updatelinks(this.getCenter().wrap(),
207 this.getLayersCode(),
208 this.getBounds().wrap());
210 var expiry = new Date();
211 expiry.setYear(expiry.getFullYear() + 10);
212 $.cookie("_osm_location", cookieContent(this), { expires: expiry });
214 // Trigger hash update on layer changes.
215 this.hash.onMapMove();