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 if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
97 if (params.layers.indexOf(map.noteLayer.options.code) >= 0) {
98 map.addLayer(map.noteLayer);
101 if (params.layers.indexOf(map.dataLayer.options.code) >= 0) {
102 map.addLayer(map.dataLayer);
106 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
108 L.OSM.zoom({position: position})
114 title: I18n.t('javascripts.map.locate.title'),
115 popup: I18n.t('javascripts.map.locate.popup')
119 var sidebar = L.OSM.sidebar('#map-ui')
147 $('.leaflet-control .control-button').tooltip({placement: 'left', container: 'body'});
149 map.on('moveend layeradd layerremove', function() {
151 map.getCenter().wrap(),
156 var expiry = new Date();
157 expiry.setYear(expiry.getFullYear() + 10);
158 $.cookie("_osm_location", cookieContent(map), { expires: expiry });
160 // Trigger hash update on layer changes.
161 map.hash.onMapMove();
165 map.on('layeradd', function (e) {
166 if (e.layer.options) {
167 var goal = OSM.PIWIK.goals[e.layer.options.keyid];
170 $('body').trigger('piwikgoal', goal);
177 map.fitBounds(params.bounds);
179 map.setView([params.lat, params.lon], params.zoom);
182 var marker = L.marker([0, 0], {icon: getUserIcon()});
185 marker.setLatLng([params.mlat, params.mlon]).addTo(map);
188 $("#homeanchor").on("click", function(e) {
191 var data = $(this).data(),
192 center = L.latLng(data.lat, data.lon);
194 map.setView(center, data.zoom);
195 marker.setLatLng(center).addTo(map);
198 $("a[data-editor=remote]").click(function(e) {
199 remoteEditHandler(map.getBounds());
203 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
204 remoteEditHandler(map.getBounds());
207 if (OSM.params().edit_help) {
212 title: I18n.t('javascripts.edit_help')
216 $('body').one('click', function() {
217 $('#editanchor').tooltip('hide');
221 initializeBrowse(map);
222 initializeNotes(map);
224 OSM.Index = function(map) {
227 page.pushstate = page.popstate = function(path) {
228 $("#view_tab").addClass("current");
229 $('#sidebar_content').load(path);
232 page.unload = function() {
233 $("#view_tab").removeClass("current");
239 OSM.Browse = function(map) {
242 page.pushstate = page.popstate = function(path, type, id) {
243 $('#sidebar_content').load(path, function() {
244 page.load(path, type, id);
248 page.load = function(path, type, id) {
249 if (OSM.STATUS === 'api_offline' || OSM.STATUS === 'database_offline') return;
251 if (type === 'note') {
252 map.noteLayer.showNote(parseInt(id));
254 map.addObject({type: type, id: parseInt(id)}, {zoom: true});
258 page.unload = function() {
265 var router = OSM.Router({
267 "/search": OSM.Search(map),
268 "/export": OSM.Export(map),
269 "/browse/changesets": OSM.ChangesetList(map),
270 "/browse/:type/:id(/history)": OSM.Browse(map)
273 $(document).on("click", "a", function(e) {
274 if (router(this.pathname + this.search + this.hash)) e.preventDefault();
277 $("#search_form").on("submit", function(e) {
279 router("/search?query=" + encodeURIComponent($("#query").val()) + OSM.formatHash(map));
282 $("#describe_location").on("click", function(e) {
284 router("/search?query=" + encodeURIComponent(map.getCenter().lat + "," + map.getCenter().lng));