diff --git a/mapiris/static/js/carto.js b/mapiris/static/js/carto.js index 449aca052b2244f562b84d1b9e56bf595fc3a9ef..37cb96d72251f4fe84242256afe5141c6c7d4941 100644 --- a/mapiris/static/js/carto.js +++ b/mapiris/static/js/carto.js @@ -79,17 +79,19 @@ function resetHighlightAll() { * @param {geojson} geojson . * @param {event} events . * @param {object} style . + * @param {string} typeMethod . (specify the method which caused this display, ex "searchBounds", "searchCode", "searchName") * @param {function} callback . */ -function addLayerFromGeoJSON(geojson, events, style){ - if(irisLayer !== null) { // if already displayed iris, remove them +function addLayerFromGeoJSON(geojson, events, style, typeMethod){ + if(irisLayer != null) { // if already displayed iris, remove them removeLayer(irisLayer); } if(geojson != null) { irisLayer = new L.geoJSON(geojson, {onEachFeature: events}); irisLayer.setStyle(style); irisLayer.addTo(map); - map.fitBounds(irisLayer.getBounds()); // zoom on the displayed iris + if(typeMethod != "searchBounds") // if searchBounds (zoom), fitBounds() will decrease the zoom, thus reloading searchBounds... + map.fitBounds(irisLayer.getBounds()); // zoom on the displayed iris } // todo add markers ? return irisLayer; diff --git a/mapiris/static/js/utils.js b/mapiris/static/js/utils.js index 87bc57203a4074e52fd09654ab806d1a77da5ec5..dec99fe45b25ceb49afa61927792d7e43ebec512 100644 --- a/mapiris/static/js/utils.js +++ b/mapiris/static/js/utils.js @@ -27,7 +27,7 @@ function getIrisFromCode(e) { contentType: 'application/json;charset=UTF-8', success: function(result){ jsonResult = JSON.parse(result); - irisLayer = addLayerFromGeoJSON(jsonResult['geojson'], eventsIRIS, styleDisplayedIris); + irisLayer = addLayerFromGeoJSON(jsonResult['geojson'], eventsIRIS, styleDisplayedIris, "searchCode"); refreshMessages(); }, error: function(result, textStatus, errorThrown) { @@ -52,7 +52,7 @@ function getIrisFromName(e) { contentType: 'application/json;charset=UTF-8', success: function(result){ jsonResult = JSON.parse(result); - irisLayer = addLayerFromGeoJSON(jsonResult['geojson'], eventsIRIS, styleDisplayedIris); + irisLayer = addLayerFromGeoJSON(jsonResult['geojson'], eventsIRIS, styleDisplayedIris, "searchName"); refreshMessages(); }, error: function(result, textStatus, errorThrown) { @@ -81,7 +81,7 @@ function getIrisForBounds(areaBounds) { contentType: 'application/json;charset=UTF-8', success: function(result){ jsonResult = JSON.parse(result); - irisLayer = addLayerFromGeoJSON(jsonResult['geojson'], eventsIRIS, styleDisplayedIris); + irisLayer = addLayerFromGeoJSON(jsonResult['geojson'], eventsIRIS, styleDisplayedIris, "searchBounds"); refreshMessages(); }, error: function(result, textStatus, errorThrown) {