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 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
96 L.OSM.zoom({position: position})
102 title: I18n.t('javascripts.map.locate.title'),
103 popup: I18n.t('javascripts.map.locate.popup')
107 var sidebar = L.OSM.sidebar('#map-ui')
135 $('.leaflet-control .control-button').tooltip({placement: 'left', container: 'body'});
137 map.on('moveend layeradd layerremove', updateLocation);
140 map.on('layeradd', function (e) {
141 if (e.layer.options) {
142 var goal = OSM.PIWIK.goals[e.layer.options.keyid];
145 $('body').trigger('piwikgoal', goal);
151 var marker = L.marker([0, 0], {icon: getUserIcon()});
153 if (!params.object_zoom) {
155 map.fitBounds(params.bounds);
157 map.setView([params.lat, params.lon], params.zoom);
162 L.rectangle(params.box, {
170 marker.setLatLng([params.mlat, params.mlon]).addTo(map);
174 map.addObject(params.object, { zoom: params.object_zoom });
177 $("#homeanchor").on("click", function(e) {
180 var data = $(this).data(),
181 center = L.latLng(data.lat, data.lon);
183 map.setView(center, data.zoom);
184 marker.setLatLng(center).addTo(map);
187 $("a[data-editor=remote]").click(function(e) {
188 remoteEditHandler(map.getBounds());
192 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
193 remoteEditHandler(map.getBounds());
196 if (OSM.params().edit_help) {
201 title: I18n.t('javascripts.edit_help')
205 $('body').one('click', function() {
206 $('#editanchor').tooltip('hide');
210 initializeSearch(map);
211 initializeExport(map);
212 initializeBrowse(map, params);
213 initializeNotes(map, params);
215 if ('undefined' !== typeof initializeChangesets) initializeChangesets(map);
218 function updateLocation() {
219 updatelinks(this.getCenter().wrap(),
221 this.getLayersCode(),
222 this.getBounds().wrap());
224 var expiry = new Date();
225 expiry.setYear(expiry.getFullYear() + 10);
226 $.cookie("_osm_location", cookieContent(this), { expires: expiry });
228 // Trigger hash update on layer changes.
229 this.hash.onMapMove();