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";
58 for (var i = layers.length - 1; i >= 0; i--) {
59 if (layerParam.indexOf(layers[i].options.code) >= 0) {
60 map.addLayer(layers[i]);
61 layersAdded = layersAdded + layers[i].options.code;
62 } else if (i == 0 && layersAdded == "") {
63 map.addLayer(layers[i]);
65 map.removeLayer(layers[i]);
72 $(window).on("hashchange", function () {
73 updateLayers(OSM.mapParams());
76 map.on("baselayerchange", function (e) {
77 if (map.getZoom() > e.layer.options.maxZoom) {
78 map.setView(map.getCenter(), e.layer.options.maxZoom, { reset: true });
82 map.noteLayer = new L.LayerGroup();
83 map.noteLayer.options = {code: 'N'};
85 map.dataLayer = new L.OSM.DataLayer(null);
86 map.dataLayer.options.code = 'D';
88 $("#sidebar").on("opened closed", function () {
92 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
94 L.OSM.zoom({position: position})
100 title: I18n.t('javascripts.map.locate.title'),
101 popup: I18n.t('javascripts.map.locate.popup')
105 var sidebar = L.OSM.sidebar('#map-ui')
133 $('.leaflet-control .control-button').tooltip({placement: 'left', container: 'body'});
135 map.on('moveend layeradd layerremove', updateLocation);
138 map.on('layeradd', function (e) {
139 if (e.layer.options) {
140 var goal = OSM.PIWIK.goals[e.layer.options.keyid];
143 $('body').trigger('piwikgoal', goal);
149 var marker = L.marker([0, 0], {icon: getUserIcon()});
151 if (!params.object_zoom) {
153 map.fitBounds(params.bounds);
155 map.setView([params.lat, params.lon], params.zoom);
160 L.rectangle(params.box, {
168 marker.setLatLng([params.mlat, params.mlon]).addTo(map);
172 map.addObject(params.object, { zoom: params.object_zoom });
175 $("#homeanchor").on("click", function(e) {
178 var data = $(this).data(),
179 center = L.latLng(data.lat, data.lon);
181 map.setView(center, data.zoom);
182 marker.setLatLng(center).addTo(map);
185 $("a[data-editor=remote]").click(function(e) {
186 remoteEditHandler(map.getBounds());
190 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
191 remoteEditHandler(map.getBounds());
194 if (OSM.params().edit_help) {
199 title: I18n.t('javascripts.edit_help')
203 $('body').one('click', function() {
204 $('#editanchor').tooltip('hide');
208 initializeSearch(map);
209 initializeExport(map);
210 initializeBrowse(map, params);
211 initializeNotes(map, params);
214 function updateLocation() {
215 updatelinks(this.getCenter().wrap(),
217 this.getLayersCode(),
218 this.getBounds().wrap());
220 var expiry = new Date();
221 expiry.setYear(expiry.getFullYear() + 10);
222 $.cookie("_osm_location", cookieContent(this), { expires: expiry });
224 // Trigger hash update on layer changes.
225 this.hash.onMapMove();