X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/d31fc7c2f5c0f43b9e65479e3f1690bdd0c2fb4a..dc931c4ac47b340c9a2a8d855fa57a290e838260:/app/assets/javascripts/index.js diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 5190277c9..d84b8ae24 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -48,16 +48,43 @@ $(document).ready(function () { code: "Q", keyid: "mapquest", name: I18n.t("javascripts.map.base.mapquest") + }), + new L.OSM.HOT({ + attribution: copyright + ". Tiles courtesy of Humanitarian OpenStreetMap Team", + code: "H", + keyid: "hot", + name: I18n.t("javascripts.map.base.hot") }) ]; - for (var i = layers.length - 1; i >= 0; i--) { - if (i === 0 || params.layers.indexOf(layers[i].options.code) >= 0) { - map.addLayer(layers[i]); - break; + function updateLayers(params) { + var layerParam = params.layers || "M"; + var layersAdded = ""; + + for (var i = layers.length - 1; i >= 0; i--) { + if (layerParam.indexOf(layers[i].options.code) >= 0) { + map.addLayer(layers[i]); + layersAdded = layersAdded + layers[i].options.code; + } else if (i == 0 && layersAdded == "") { + map.addLayer(layers[i]); + } else { + map.removeLayer(layers[i]); + } } } + updateLayers(params); + + $(window).on("hashchange", function () { + updateLayers(OSM.mapParams()); + }); + + map.on("baselayerchange", function (e) { + if (map.getZoom() > e.layer.options.maxZoom) { + map.setView(map.getCenter(), e.layer.options.maxZoom, { reset: true }); + } + }); + map.noteLayer = new L.LayerGroup(); map.noteLayer.options = {code: 'N'}; @@ -75,7 +102,10 @@ $(document).ready(function () { L.control.locate({ position: position, - title: I18n.t('javascripts.map.locate.title') + strings: { + title: I18n.t('javascripts.map.locate.title'), + popup: I18n.t('javascripts.map.locate.popup') + } }).addTo(map); var sidebar = L.OSM.sidebar('#map-ui') @@ -110,6 +140,18 @@ $(document).ready(function () { map.on('moveend layeradd layerremove', updateLocation); + if (OSM.PIWIK) { + map.on('layeradd', function (e) { + if (e.layer.options) { + var goal = OSM.PIWIK.goals[e.layer.options.keyid]; + + if (goal) { + $('body').trigger('piwikgoal', goal); + } + } + }); + } + var marker = L.marker([0, 0], {icon: getUserIcon()}); if (!params.object_zoom) { @@ -155,6 +197,20 @@ $(document).ready(function () { remoteEditHandler(map.getBounds()); } + if (OSM.params().edit_help) { + $('#editanchor') + .removeAttr('title') + .tooltip({ + placement: 'bottom', + title: I18n.t('javascripts.edit_help') + }) + .tooltip('show'); + + $('body').one('click', function() { + $('#editanchor').tooltip('hide'); + }); + } + initializeSearch(map); initializeExport(map); initializeBrowse(map, params);