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', function() {
139 map.getCenter().wrap(),
144 var expiry = new Date();
145 expiry.setYear(expiry.getFullYear() + 10);
146 $.cookie("_osm_location", cookieContent(map), { expires: expiry });
148 // Trigger hash update on layer changes.
149 map.hash.onMapMove();
153 map.on('layeradd', function (e) {
154 if (e.layer.options) {
155 var goal = OSM.PIWIK.goals[e.layer.options.keyid];
158 $('body').trigger('piwikgoal', goal);
164 var marker = L.marker([0, 0], {icon: getUserIcon()});
166 if (!params.object_zoom) {
168 map.fitBounds(params.bounds);
170 map.setView([params.lat, params.lon], params.zoom);
175 marker.setLatLng([params.mlat, params.mlon]).addTo(map);
179 map.addObject(params.object, { zoom: params.object_zoom });
182 $("#homeanchor").on("click", function(e) {
185 var data = $(this).data(),
186 center = L.latLng(data.lat, data.lon);
188 map.setView(center, data.zoom);
189 marker.setLatLng(center).addTo(map);
192 $("a[data-editor=remote]").click(function(e) {
193 remoteEditHandler(map.getBounds());
197 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
198 remoteEditHandler(map.getBounds());
201 if (OSM.params().edit_help) {
206 title: I18n.t('javascripts.edit_help')
210 $('body').one('click', function() {
211 $('#editanchor').tooltip('hide');
215 initializeSearch(map);
216 initializeExport(map);
217 initializeBrowse(map, params);
218 initializeNotes(map, params);
220 if ('undefined' !== typeof initializeChangesets) initializeChangesets(map);