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
12 //= require index/changeset
15 $(document).ready(function () {
16 var params = OSM.mapParams();
18 var map = L.map("map", {
23 map.attributionControl.setPrefix('');
25 map.hash = L.hash(map);
27 var copyright = I18n.t('javascripts.map.copyright', {copyright_url: '/copyright'});
31 attribution: copyright,
34 name: I18n.t("javascripts.map.base.standard")
37 attribution: copyright + ". Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
40 name: I18n.t("javascripts.map.base.cycle_map")
42 new L.OSM.TransportMap({
43 attribution: copyright + ". Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
45 keyid: "transportmap",
46 name: I18n.t("javascripts.map.base.transport_map")
48 new L.OSM.MapQuestOpen({
49 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'>",
52 name: I18n.t("javascripts.map.base.mapquest")
55 attribution: copyright + ". Tiles courtesy of <a href='http://hot.openstreetmap.org/' target='_blank'>Humanitarian OpenStreetMap Team</a>",
58 name: I18n.t("javascripts.map.base.hot")
62 function updateLayers(params) {
63 var layerParam = params.layers || "M";
66 for (var i = layers.length - 1; i >= 0; i--) {
67 if (layerParam.indexOf(layers[i].options.code) >= 0) {
68 map.addLayer(layers[i]);
69 layersAdded = layersAdded + layers[i].options.code;
70 } else if (i == 0 && layersAdded == "") {
71 map.addLayer(layers[i]);
73 map.removeLayer(layers[i]);
80 $(window).on("hashchange", function () {
81 updateLayers(OSM.mapParams());
84 map.on("baselayerchange", function (e) {
85 if (map.getZoom() > e.layer.options.maxZoom) {
86 map.setView(map.getCenter(), e.layer.options.maxZoom, { reset: true });
90 map.noteLayer = new L.LayerGroup();
91 map.noteLayer.options = {code: 'N'};
93 map.dataLayer = new L.OSM.DataLayer(null);
94 map.dataLayer.options.code = 'D';
96 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
98 L.OSM.zoom({position: position})
104 title: I18n.t('javascripts.map.locate.title'),
105 popup: I18n.t('javascripts.map.locate.popup')
109 var sidebar = L.OSM.sidebar('#map-ui')
137 $('.leaflet-control .control-button').tooltip({placement: 'left', container: 'body'});
139 map.on('moveend layeradd layerremove', function() {
141 map.getCenter().wrap(),
146 var expiry = new Date();
147 expiry.setYear(expiry.getFullYear() + 10);
148 $.cookie("_osm_location", cookieContent(map), { expires: expiry });
150 // Trigger hash update on layer changes.
151 map.hash.onMapMove();
155 map.on('layeradd', function (e) {
156 if (e.layer.options) {
157 var goal = OSM.PIWIK.goals[e.layer.options.keyid];
160 $('body').trigger('piwikgoal', goal);
166 var marker = L.marker([0, 0], {icon: getUserIcon()});
168 if (!params.object_zoom) {
170 map.fitBounds(params.bounds);
172 map.setView([params.lat, params.lon], params.zoom);
177 marker.setLatLng([params.mlat, params.mlon]).addTo(map);
180 $("#homeanchor").on("click", function(e) {
183 var data = $(this).data(),
184 center = L.latLng(data.lat, data.lon);
186 map.setView(center, data.zoom);
187 marker.setLatLng(center).addTo(map);
190 $("a[data-editor=remote]").click(function(e) {
191 remoteEditHandler(map.getBounds());
195 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
196 remoteEditHandler(map.getBounds());
199 if (OSM.params().edit_help) {
204 title: I18n.t('javascripts.edit_help')
208 $('body').one('click', function() {
209 $('#editanchor').tooltip('hide');
213 initializeSearch(map);
214 initializeBrowse(map, params);
215 initializeNotes(map, params);
217 OSM.Index = function(map) {
220 page.pushstate = page.popstate = function(path) {
221 $("#view_tab").addClass("current");
222 $('#sidebar_content').load(path);
225 page.unload = function() {
226 $("#view_tab").removeClass("current");
232 OSM.Browse = function(map) {
235 page.pushstate = page.popstate = function(path) {
236 $('#sidebar_content').load(path, page.load);
239 page.load = function() {
240 map.addObject(OSM.mapParams().object, {zoom: true});
243 page.unload = function() {
250 var router = OSM.Router({
252 "/export": OSM.Export(map),
253 "/browse/changesets": OSM.ChangesetList(map),
254 "/browse/:type/:id(/history)": OSM.Browse(map)
257 $(document).on("click", "a", function(e) {
258 if (router(this.pathname + this.search + this.hash)) e.preventDefault();