From ab29e41286881c14854d86cf9a7906985fd9afef Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 20 Jul 2017 12:04:16 -0400 Subject: [PATCH] review feedback --- .../region_map/public/choropleth_layer.js | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/core_plugins/region_map/public/choropleth_layer.js b/src/core_plugins/region_map/public/choropleth_layer.js index 4c2a1abbc7ef27..6ea21d0699fb83 100644 --- a/src/core_plugins/region_map/public/choropleth_layer.js +++ b/src/core_plugins/region_map/public/choropleth_layer.js @@ -211,8 +211,7 @@ function makeChoroplethStyler(data, colorramp, joinField) { const { min, max } = getMinMax(data); const outstandingFeatures = data.slice(); - - const joinedShapes = []; + const boundsOfAllFeatures = new L.LatLngBounds(); return { getLeafletStyleFunction: function (geojsonFeature) { let lastIndex = -1; @@ -226,7 +225,10 @@ function makeChoroplethStyler(data, colorramp, joinField) { } outstandingFeatures.splice(lastIndex, 1); - joinedShapes.push(geojsonFeature); + + const boundsOfFeature = L.geoJson(geojsonFeature).getBounds(); + boundsOfAllFeatures.extend(boundsOfFeature); + return { fillColor: getChoroplethColor(match.value, min, max, colorramp), weight: 2, @@ -243,19 +245,7 @@ function makeChoroplethStyler(data, colorramp, joinField) { return outstandingFeatures.map((bucket) => bucket.term); }, getLeafletBounds: function () { - - if (!joinedShapes.length) { - return null; - } - - const bounds = L.geoJson(joinedShapes[0]).getBounds(); - for (let i = 1; i < joinedShapes.length; i++) { - const otherBounds = L.geoJson(joinedShapes[i]).getBounds(); - bounds.extend(otherBounds); - } - return bounds; - - + return boundsOfAllFeatures.isValid() ? boundsOfAllFeatures : null; } };