Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
fix: invalidate vector tile point radii when range changes (#3912)
Igor Dykhtae022b6689b8e
diff --git a/src/layers/src/vector-tile/vector-tile-layer.ts b/src/layers/src/vector-tile/vector-tile-layer.tsindex 521ef9a70..ef7a867d1 100644--- a/src/layers/src/vector-tile/vector-tile-layer.ts+++ b/src/layers/src/vector-tile/vector-tile-layer.ts@@ -699,7 +699,7 @@ export default class VectorTileLayer extends AbstractTileLayer<VectorTile, FeaturadiusField: this.config.radiusField,radiusScale: this.config.radiusScale,radiusDomain: this.config.radiusDomain,- radiusRange: this.config.radiusRange,+ radiusRange: visConfig.radiusRange,currentTime: isIndexedField(radiusField) ? animationConfig.currentTime : null}},diff --git a/test/browser/layer-tests/vector-tile-layer-specs.js b/test/browser/layer-tests/vector-tile-layer-specs.jsindex 59f1ad8e1..1013c704d 100644--- a/test/browser/layer-tests/vector-tile-layer-specs.js+++ b/test/browser/layer-tests/vector-tile-layer-specs.js@@ -2,6 +2,10 @@// Copyright contributors to the kepler.gl projectimport test from 'tape-catch';+import {LayerManager, WebMercatorViewport} from '@deck.gl/core';+import {device} from '@deck.gl/test-utils';+import {INITIAL_MAP_STATE} from '@kepler.gl/reducers';+import {preparedDataset, dataId} from 'test/helpers/layer-utils';import {KeplerGlLayers} from '@kepler.gl/layers';import {MISSING_VALUE_COLOR, NO_VALUE_COLOR} from '@kepler.gl/constants';@@ -67,3 +71,94 @@ test('#VectorTileLayer -> getEncodedChannelValue respects hideNulls', t => {t.end();});++test('#VectorTileLayer -> radius range updates cached point attributes', t => {+ const layer = new VectorTileLayer({id: 'vector-radius', dataId});+ const radiusField = preparedDataset.fields.find(field => field.name === 'trip_distance');+ layer.updateLayerConfig({radiusField, radiusDomain: [0, 10], radiusScale: 'linear'});+ layer.updateLayerVisConfig({radiusRange: [2, 10]});+ const datasets = {+ [dataId]: {+ ...preparedDataset,+ type: 'vector-tile',+ metadata: {remoteTileFormat: 'mvt', tilesetDataUrl: 'https://example.com/{z}/{x}/{y}.pbf'}+ }+ };+ const points = [0, 10].map((value, index) => ({+ type: 'Feature',+ geometry: {type: 'Point', coordinates: [index, 0]},+ properties: {trip_distance: value}+ }));+ const manager = new LayerManager(device, {+ viewport: new WebMercatorViewport({width: 64, height: 64, longitude: 0, latitude: 0, zoom: 2})+ });+ const render = () => {+ const data = layer.formatLayerData(datasets, undefined, {});+ const [tileLayer] = layer.renderLayer({+ data,+ gpuFilter: preparedDataset.gpuFilter,+ mapState: INITIAL_MAP_STATE,+ animationConfig: {},+ layerCallbacks: {},+ visible: true+ });+ // Use the production tile sublayer path with an already decoded tile; no network or WebGL draw.+ manager.setLayers([+ layer.renderSubLayers({+ ...tileLayer.props,+ id: 'radius-tile',+ data: points,+ tile: {index: {z: 2}},+ extensions: []+ })+ ]);+ return tileLayer;+ };+ const attributes = () =>+ manager+ .getLayers()+ .find(deckLayer => deckLayer.id.endsWith('-points-circle'))+ .getAttributeManager()+ .getAttributes();+ const radii = () => {+ const attribute = attributes().instanceRadius;+ // deck.gl stores one shared value when the accessor is a constant.+ return attribute.isConstant+ ? points.map(() => attribute.value[0])+ : Array.from(attribute.value.slice(0, points.length));+ };++ try {+ render();+ t.deepEqual(radii(), [2, 10], 'initial tile point radii follow the configured range');+ const originalColors = Array.from(attributes().instanceFillColors.value);+ layer.updateLayerVisConfig({radiusRange: [20, 100]});+ const changed = render();+ t.deepEqual(+ points.map(changed.props.getPointRadius),+ [20, 100],+ 'the radius accessor uses the new range'+ );+ t.deepEqual(radii(), [20, 100], 'cached point attributes refresh to the new range');+ t.deepEqual(+ Array.from(attributes().instanceFillColors.value),+ originalColors,+ 'radius changes preserve point colors'+ );++ layer.updateLayerVisConfig({opacity: 0.5});+ render();+ t.deepEqual(radii(), [20, 100], 'unrelated style changes preserve point radii');++ layer.updateLayerConfig({radiusField: null});+ layer.updateLayerVisConfig({radius: 7});+ render();+ t.deepEqual(radii(), [7, 7], 'constant radius still works without a radius field');+ layer.updateLayerVisConfig({radiusRange: [1, 5]});+ render();+ t.deepEqual(radii(), [7, 7], 'range changes do not alter a constant radius');+ } finally {+ manager.finalize();+ }+ t.end();+});