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")
53 attribution: copyright + ". Tiles courtesy of <a href='http://hot.openstreetmap.org/' target='_blank'>Humanitarian OpenStreetMap Team</a>",
56 name: I18n.t("javascripts.map.base.hot")
60 function updateLayers(params) {
61 var layerParam = params.layers || "M";
64 for (var i = layers.length - 1; i >= 0; i--) {
65 if (layerParam.indexOf(layers[i].options.code) >= 0) {
66 map.addLayer(layers[i]);
67 layersAdded = layersAdded + layers[i].options.code;
68 } else if (i == 0 && layersAdded == "") {
69 map.addLayer(layers[i]);
71 map.removeLayer(layers[i]);
78 $(window).on("hashchange", function () {
79 updateLayers(OSM.mapParams());
82 map.on("baselayerchange", function (e) {
83 if (map.getZoom() > e.layer.options.maxZoom) {
84 map.setView(map.getCenter(), e.layer.options.maxZoom, { reset: true });
88 map.noteLayer = new L.LayerGroup();
89 map.noteLayer.options = {code: 'N'};
91 map.dataLayer = new L.OSM.DataLayer(null);
92 map.dataLayer.options.code = 'D';
94 $("#sidebar").on("opened closed", function () {
98 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
100 L.OSM.zoom({position: position})
106 title: I18n.t('javascripts.map.locate.title'),
107 popup: I18n.t('javascripts.map.locate.popup')
111 var sidebar = L.OSM.sidebar('#map-ui')
139 $('.leaflet-control .control-button').tooltip({placement: 'left', container: 'body'});
141 map.on('moveend layeradd layerremove', updateLocation);
144 map.on('layeradd', function (e) {
145 if (e.layer.options) {
146 var goal = OSM.PIWIK.goals[e.layer.options.keyid];
149 $('body').trigger('piwikgoal', goal);
155 var marker = L.marker([0, 0], {icon: getUserIcon()});
157 if (!params.object_zoom) {
159 map.fitBounds(params.bounds);
161 map.setView([params.lat, params.lon], params.zoom);
166 L.rectangle(params.box, {
174 marker.setLatLng([params.mlat, params.mlon]).addTo(map);
178 map.addObject(params.object, { zoom: params.object_zoom });
181 $("#homeanchor").on("click", function(e) {
184 var data = $(this).data(),
185 center = L.latLng(data.lat, data.lon);
187 map.setView(center, data.zoom);
188 marker.setLatLng(center).addTo(map);
191 $("a[data-editor=remote]").click(function(e) {
192 remoteEditHandler(map.getBounds());
196 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
197 remoteEditHandler(map.getBounds());
200 if (OSM.params().edit_help) {
205 title: I18n.t('javascripts.edit_help')
209 $('body').one('click', function() {
210 $('#editanchor').tooltip('hide');
214 initializeSearch(map);
215 initializeExport(map);
216 initializeBrowse(map, params);
217 initializeNotes(map, params);
220 function updateLocation() {
221 updatelinks(this.getCenter().wrap(),
223 this.getLayersCode(),
224 this.getBounds().wrap());
226 var expiry = new Date();
227 expiry.setYear(expiry.getFullYear() + 10);
228 $.cookie("_osm_location", cookieContent(this), { expires: expiry });
230 // Trigger hash update on layer changes.
231 this.hash.onMapMove();