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 for (var i = layers.length - 1; i >= 0; i--) {
55 if (i === 0 || params.layers.indexOf(layers[i].options.code) >= 0) {
56 map.addLayer(layers[i]);
61 map.noteLayer = new L.LayerGroup();
62 map.noteLayer.options = {code: 'N'};
64 map.dataLayer = new L.OSM.DataLayer(null);
65 map.dataLayer.options.code = 'D';
67 $("#sidebar").on("opened closed", function () {
71 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
73 L.OSM.zoom({position: position})
79 title: I18n.t('javascripts.map.locate.title'),
80 popup: I18n.t('javascripts.map.locate.popup')
84 var sidebar = L.OSM.sidebar('#map-ui')
112 $('.leaflet-control .control-button').tooltip({placement: 'left', container: 'body'});
114 map.on('moveend layeradd layerremove', updateLocation);
117 map.on('layeradd', function (e) {
118 if (e.layer.options) {
119 var goal = OSM.PIWIK.goals[e.layer.options.keyid];
122 $('body').trigger('piwikgoal', goal);
128 var marker = L.marker([0, 0], {icon: getUserIcon()});
130 if (!params.object_zoom) {
132 map.fitBounds(params.bounds);
134 map.setView([params.lat, params.lon], params.zoom);
139 L.rectangle(params.box, {
147 marker.setLatLng([params.mlat, params.mlon]).addTo(map);
151 map.addObject(params.object, { zoom: params.object_zoom });
154 $("#homeanchor").on("click", function(e) {
157 var data = $(this).data(),
158 center = L.latLng(data.lat, data.lon);
160 map.setView(center, data.zoom);
161 marker.setLatLng(center).addTo(map);
164 $("a[data-editor=remote]").click(function(e) {
165 remoteEditHandler(map.getBounds());
169 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
170 remoteEditHandler(map.getBounds());
173 if (OSM.params().edit_help) {
178 title: I18n.t('javascripts.edit_help')
182 $('body').one('click', function() {
183 $('#editanchor').tooltip('hide');
187 initializeSearch(map);
188 initializeExport(map);
189 initializeBrowse(map, params);
190 initializeNotes(map, params);
193 function updateLocation() {
194 updatelinks(this.getCenter().wrap(),
196 this.getLayersCode(),
197 this.getBounds().wrap());
199 var expiry = new Date();
200 expiry.setYear(expiry.getFullYear() + 10);
201 $.cookie("_osm_location", cookieContent(this), { expires: expiry });
203 // Trigger hash update on layer changes.
204 this.hash.onMapMove();