X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/56fd5c4d90c7d3757fb97ff16c40aaa307ae1d22..2f076d8f349837751e701d9c948414abc7ddeeaf:/app/assets/javascripts/index.js diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 2a704f724..d57b76b28 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -48,26 +48,49 @@ $(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'}; map.dataLayer = new L.OSM.DataLayer(null); map.dataLayer.options.code = 'D'; - $("#sidebar").on("opened closed", function () { - map.invalidateSize(); - }); - var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright'; L.OSM.zoom({position: position}) @@ -111,7 +134,33 @@ $(document).ready(function () { $('.leaflet-control .control-button').tooltip({placement: 'left', container: 'body'}); - map.on('moveend layeradd layerremove', updateLocation); + map.on('moveend layeradd layerremove', function() { + updatelinks( + map.getCenter().wrap(), + map.getZoom(), + map.getLayersCode(), + map.getBounds().wrap(), + map._object); + + var expiry = new Date(); + expiry.setYear(expiry.getFullYear() + 10); + $.cookie("_osm_location", cookieContent(map), { expires: expiry }); + + // Trigger hash update on layer changes. + map.hash.onMapMove(); + }); + + 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()}); @@ -123,14 +172,6 @@ $(document).ready(function () { } } - if (params.box) { - L.rectangle(params.box, { - weight: 2, - color: '#e90', - fillOpacity: 0 - }).addTo(map); - } - if (params.marker) { marker.setLatLng([params.mlat, params.mlon]).addTo(map); } @@ -176,18 +217,6 @@ $(document).ready(function () { initializeExport(map); initializeBrowse(map, params); initializeNotes(map, params); -}); - -function updateLocation() { - updatelinks(this.getCenter().wrap(), - this.getZoom(), - this.getLayersCode(), - this.getBounds().wrap()); - var expiry = new Date(); - expiry.setYear(expiry.getFullYear() + 10); - $.cookie("_osm_location", cookieContent(this), { expires: expiry }); - - // Trigger hash update on layer changes. - this.hash.onMapMove(); -} + if ('undefined' !== typeof initializeChangesets) initializeChangesets(map); +});