Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

Consider all mew layers when calculating the map bounds (#142)

Javidf7954a1d988e
diff --git a/src/reducers/composers.js b/src/reducers/composers.js
index cbfbb61df..d9fa71b14 100644
--- a/src/reducers/composers.js
+++ b/src/reducers/composers.js
@@ -37,7 +37,7 @@ import KeplerGlSchema from 'schemas';
*/
export const updateVisDataComposed = (state, action) => {
// keep a copy of oldLayers
- const oldLayers = state.visState.layers.map(l => l.id);
+ const oldLayers = state.visState.layers;
const visState = updateVisDataUpdater(state.visState, action);
@@ -54,7 +54,7 @@ export const updateVisDataComposed = (state, action) => {
let bounds;
if (options.centerMap) {
// find map bounds for new layers
- const newLayers = visState.layers.filter(l => !oldLayers.includes(l.id));
+ const newLayers = visState.layers.filter(nl => !oldLayers.find(ol => ol === nl));
bounds = findMapBounds(newLayers);
}
diff --git a/src/utils/data-utils.js b/src/utils/data-utils.js
index 18ebdc322..433cd59cd 100644
--- a/src/utils/data-utils.js
+++ b/src/utils/data-utils.js
@@ -22,6 +22,11 @@ import moment from 'moment';
import assert from 'assert';
import {ALL_FIELD_TYPES} from 'constants/default-settings';
+const MAX_LATITUDE = 90;
+const MIN_LATITUDE = -90;
+const MAX_LONGITUDE = 180;
+const MIN_LONGITUDE = -180;
+
/**
* simple getting unique values of an array
*
@@ -46,27 +51,29 @@ export function unique(values) {
* @param {string} dataId
* @returns {object} coordinates of map center, empty if not found
*/
-export function findMapBounds(layers, dataId) {
+export function findMapBounds(layers) {
// find bounds in formatted layerData
- // use first isVisible Layer
-
- const newLayers = dataId
- ? layers.filter(l => l.config.dataId === dataId)
- : layers;
- const firstVisibleLayer = newLayers.find(l => l.config.isVisible);
- if (!firstVisibleLayer) {
+ // take ALL layers into account when finding map bounds
+ const availableLayerBounds = layers.reduce((res, l) => {
+ if (l.meta && l.meta.bounds) {
+ res.push(l.meta.bounds);
+ }
+ return res;
+ }, [])
+ // return null if no layer is available
+ if (availableLayerBounds.length === 0) {
return null;
}
-
- // if first visible layer has bounds, use it
- if (firstVisibleLayer.meta && firstVisibleLayer.meta.bounds) {
- return firstVisibleLayer.meta.bounds;
- }
-
- // if not, find any layer that has bound
- const anyLayerWBound = newLayers.find(l => l.meta && l.meta.bounds);
-
- return anyLayerWBound ? anyLayerWBound.meta.bounds : null;
+ // merge bounds in each layer
+ const newBounds = availableLayerBounds.reduce((res, b) => {
+ return [
+ Math.min(res[0], b[0]),
+ Math.min(res[1], b[1]),
+ Math.max(res[2], b[2]),
+ Math.max(res[3], b[3])
+ ];
+ }, [MAX_LONGITUDE, MAX_LATITUDE, MIN_LONGITUDE, MIN_LATITUDE]);
+ return newBounds;
}
/* eslint-enable max-statements */
diff --git a/yarn.lock b/yarn.lock
index 779e7f582..d91b4adb3 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -95,11 +95,7 @@ abab@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.4.tgz#5faad9c2c07f60dd76770f71cf025b62a63cfd4e"
-abbrev@1:
- version "1.1.1"
- resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"
-
+abbrev@1, [email protected]:
version "1.0.9"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135"
@@ -331,13 +327,6 @@ array-unique@^0.3.2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428"
-array.prototype.find@^2.0.1:
- version "2.0.4"
- resolved "https://registry.yarnpkg.com/array.prototype.find/-/array.prototype.find-2.0.4.tgz#556a5c5362c08648323ddaeb9de9d14bc1864c90"
- dependencies:
- define-properties "^1.1.2"
- es-abstract "^1.7.0"
-
arrify@^1.0.0, arrify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d"
@@ -1846,7 +1835,15 @@ [email protected]:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
-concat-stream@^1.5.2, concat-stream@^1.6.0, concat-stream@^1.6.1, concat-stream@~1.6.0:
+concat-stream@^1.5.2, concat-stream@~1.5.0:
+ version "1.5.2"
+ resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.5.2.tgz#708978624d856af41a5a741defdd261da752c266"
+ dependencies:
+ inherits "~2.0.1"
+ readable-stream "~2.0.0"
+ typedarray "~0.0.5"
+
+concat-stream@^1.6.0, concat-stream@^1.6.1, concat-stream@~1.6.0:
version "1.6.2"
resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.2.tgz#904bdf194cd3122fc675c77fc4ac3d4ff0fd1a34"
dependencies:
@@ -1855,14 +1852,6 @@ concat-stream@^1.5.2, concat-stream@^1.6.0, concat-stream@^1.6.1, concat-stream@
readable-stream "^2.2.2"
typedarray "^0.0.6"
-concat-stream@~1.5.0:
- version "1.5.2"
- resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.5.2.tgz#708978624d856af41a5a741defdd261da752c266"
- dependencies:
- inherits "~2.0.1"
- readable-stream "~2.0.0"
- typedarray "~0.0.5"
-
configstore@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/configstore/-/configstore-2.1.0.tgz#737a3a7036e9886102aa6099e47bb33ab1aba1a1"
@@ -2501,20 +2490,13 @@ domhandler@^2.3.0:
dependencies:
domelementtype "1"
[email protected], domutils@^1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.5.1.tgz#dcd8488a26f563d61079e48c9f7b7e32373682cf"
dependencies:
dom-serializer "0"
domelementtype "1"
-domutils@^1.5.1:
- version "1.7.0"
- resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.7.0.tgz#56ea341e834e06e6748af7a1cb25da67ea9f8c2a"
- dependencies:
- dom-serializer "0"
- domelementtype "1"
-
dot-prop@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-3.0.0.tgz#1b708af094a49c9a0e7dbcad790aba539dac1177"
@@ -2785,17 +2767,7 @@ eslint-plugin-prettier@^2.2.0:
fast-diff "^1.1.1"
jest-docblock "^21.0.0"
-eslint-plugin-react@^6.7.1:
- version "6.10.3"
- resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-6.10.3.tgz#c5435beb06774e12c7db2f6abaddcbf900cd3f78"
- dependencies:
- array.prototype.find "^2.0.1"
- doctrine "^1.2.2"
- has "^1.0.1"
- jsx-ast-utils "^1.3.4"
- object.assign "^4.0.4"
-
-eslint-plugin-react@~6.7.0:
+eslint-plugin-react@^6.7.1, eslint-plugin-react@~6.7.0:
version "6.7.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-6.7.1.tgz#1af96aea545856825157d97c1b50d5a8fb64a5a7"
dependencies:
@@ -3054,14 +3026,10 @@ extglob@^2.0.4:
snapdragon "^0.8.1"
to-regex "^3.0.1"
[email protected], extsprintf@^1.2.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05"
-extsprintf@^1.2.0:
- version "1.4.0"
- resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f"
-
falafel@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/falafel/-/falafel-2.1.0.tgz#96bb17761daba94f46d001738b3cedf3a67fe06c"
@@ -4383,7 +4351,7 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.10.0"
-jsx-ast-utils@^1.3.3, jsx-ast-utils@^1.3.4:
+jsx-ast-utils@^1.3.3:
version "1.4.1"
resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-1.4.1.tgz#3867213e8dd79bf1e8f2300c0cfc1efb182c0df1"
@@ -4871,7 +4839,7 @@ [email protected]:
version "0.0.5"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.5.tgz#d7aa327bcecf518f9106ac6b8f003fa3bcea8566"
[email protected], minimist@~0.0.1:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
@@ -4879,10 +4847,6 @@ [email protected], minimist@^1.1.0, minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
-minimist@~0.0.1:
- version "0.0.10"
- resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"
-
minipass@^2.2.1, minipass@^2.2.4:
version "2.3.0"
resolved "https://registry.yarnpkg.com/minipass/-/minipass-2.3.0.tgz#2e11b1c46df7fe7f1afbe9a490280add21ffe384"
@@ -5909,7 +5873,7 @@ react-map-gl@^3.2.1:
dependencies:
babel-runtime "^6.23.0"
bowser "^1.2.0"
- immutable "^3.8.2"
+ immutable "*"
mapbox-gl "0.44"
math.gl "^1.1.3"
mjolnir.js "^1.1.0"
@@ -6866,11 +6830,7 @@ static-module@^2.2.0:
static-eval "^2.0.0"
through2 "~2.0.3"
-"statuses@>= 1.3.1 < 2", "statuses@>= 1.4.0 < 2":
- version "1.5.0"
- resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c"
-
-statuses@~1.4.0:
+"statuses@>= 1.3.1 < 2", "statuses@>= 1.4.0 < 2", statuses@~1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.4.0.tgz#bb73d446da2796106efcc1b601a253d6c46bd087"