Skip to content

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

[Enhancement] Simplify map layer visible logic in splitMaps and deck, mapbox overlay renders (#642)

Shan He74d97aba168a
diff --git a/src/actions/vis-state-actions.js b/src/actions/vis-state-actions.js
index 531d938b9..1929c52dd 100644
--- a/src/actions/vis-state-actions.js
+++ b/src/actions/vis-state-actions.js
@@ -404,22 +404,6 @@ export function toggleLayerForMap(mapIndex, layerId) {
};
}
-/**
- * Set layers to be visible in split map
- * @memberof visStateActions
- * @param {Number} mapIndex - index of the split map
- * @param {Array<string>} layerIds - array of layer ids
- * @returns {{type: ActionTypes.SET_VISIBLE_LAYERS_FOR_MAP, layerIndex: *, mapIndex: *}}
- * @public
- */
-export function setVisibleLayersForMap(mapIndex, layerIds) {
- return {
- type: ActionTypes.SET_VISIBLE_LAYERS_FOR_MAP,
- mapIndex,
- layerIds
- };
-}
-
/**
* Set the property of a filter plot
* @memberof visStateActions
diff --git a/src/components/kepler-gl.js b/src/components/kepler-gl.js
index eff8c19d8..0be77e402 100644
--- a/src/components/kepler-gl.js
+++ b/src/components/kepler-gl.js
@@ -241,6 +241,7 @@ function KeplerGlFactory(
const mapFields = {
datasets,
+ getMapboxRef,
mapboxApiAccessToken,
mapboxApiUrl,
mapState,
@@ -271,7 +272,6 @@ function KeplerGlFactory(
index={0}
{...mapFields}
mapLayers={isSplit ? splitMaps[0].layers : null}
- getMapboxRef={getMapboxRef}
/>
]
: splitMaps.map((settings, index) => (
@@ -280,7 +280,6 @@ function KeplerGlFactory(
index={index}
{...mapFields}
mapLayers={splitMaps[index].layers}
- getMapboxRef={getMapboxRef}
/>
));
diff --git a/src/components/map-container.js b/src/components/map-container.js
index db7688de4..6cd5f7a19 100644
--- a/src/components/map-container.js
+++ b/src/components/map-container.js
@@ -23,6 +23,7 @@ import React, {Component} from 'react';
import PropTypes from 'prop-types';
import MapboxGLMap from 'react-map-gl';
import DeckGL from 'deck.gl';
+import {createSelector} from 'reselect';
import WebMercatorViewport from 'viewport-mercator-project';
// components
@@ -31,12 +32,13 @@ import MapControlFactory from 'components/map/map-control';
import {StyledMapContainer} from 'components/common/styled-components';
// utils
-import {generateMapboxLayers, updateMapboxLayers} from '../layers/mapbox-utils';
+import {generateMapboxLayers, updateMapboxLayers} from 'layers/mapbox-utils';
+import {OVERLAY_TYPE} from 'layers/base-layer';
import {onWebGLInitialized, setLayerBlending} from 'utils/gl-utils';
import {transformRequest} from 'utils/map-style-utils/mapbox-utils';
// default-settings
-import ThreeDBuildingLayer from '../deckgl-layers/3d-building-layer/3d-building-layer';
+import ThreeDBuildingLayer from 'deckgl-layers/3d-building-layer/3d-building-layer';
const MAP_STYLE = {
container: {
@@ -108,7 +110,35 @@ export default function MapContainerFactory(MapPopover, MapControl) {
}
}
+ layersSelector = props => props.layers;
+ layerDataSelector = props => props.layerData;
+ mapLayersSelector = props => props.mapLayers;
+ layerOrderSelector = props => props.layerOrder;
+ layersToRenderSelector = createSelector(
+ this.layersSelector,
+ this.layerDataSelector,
+ this.mapLayersSelector,
+ // {[id]: true \ false}
+ (layers, layerData, mapLayers) => layers.reduce((accu, layer, idx) => ({
+ ...accu,
+ [layer.id]: layer.shouldRenderLayer(layerData[idx]) &&
+ this._isVisibleMapLayer(layer, mapLayers)
+ }), {})
+ );
+
+ mapboxLayersSelector = createSelector(
+ this.layersSelector,
+ this.layerDataSelector,
+ this.layerOrderSelector,
+ this.layersToRenderSelector,
+ generateMapboxLayers
+ )
/* component private functions */
+ _isVisibleMapLayer(layer, mapLayers) {
+ // if layer.id is not in mapLayers, don't render it
+ return !mapLayers || (mapLayers && mapLayers[layer.id]);
+ }
+
_onCloseMapPopover = () => {
this.props.visStateActions.onLayerClick(null);
};
@@ -128,14 +158,8 @@ export default function MapContainerFactory(MapPopover, MapControl) {
_onMapboxStyleUpdate = () => {
// force refresh mapboxgl layers
-
- updateMapboxLayers(
- this._map,
- this._renderMapboxLayers(),
- this.previousLayers,
- this.props.mapLayers,
- {force: true}
- );
+ this.previousLayers = {};
+ this._updateMapboxLayers();
if (typeof this.props.onMapStyleLoaded === 'function') {
this.props.onMapStyleLoaded(this._map);
@@ -175,7 +199,7 @@ export default function MapContainerFactory(MapPopover, MapControl) {
/* component render functions */
/* eslint-disable complexity */
- _renderMapPopover() {
+ _renderMapPopover(layersToRender) {
// TODO: move this into reducer so it can be tested
const {
mapState,
@@ -184,7 +208,6 @@ export default function MapContainerFactory(MapPopover, MapControl) {
datasets,
interactionConfig,
layers,
- mapLayers,
mousePos: {mousePosition, coordinate, pinned}
} = this.props;
@@ -208,9 +231,8 @@ export default function MapContainerFactory(MapPopover, MapControl) {
const layer = layers[overlay.props.idx];
if (
- layer.config.isVisible &&
layer.getHoverData &&
- (!mapLayers || mapLayers[layer.id].isVisible)
+ layersToRender[layer.id]
) {
// if layer is visible and have hovered data
@@ -257,29 +279,21 @@ export default function MapContainerFactory(MapPopover, MapControl) {
return screenCoord && {x: screenCoord[0], y: screenCoord[1]};
}
- _shouldRenderLayer(layer, data, mapLayers) {
- const isAvailableAndVisible =
- !(mapLayers && mapLayers[layer.id]) || mapLayers[layer.id].isVisible;
- return layer.shouldRenderLayer(data) && isAvailableAndVisible;
- }
-
_renderLayer = (overlays, idx) => {
const {
layers,
layerData,
hoverInfo,
clicked,
- mapLayers,
mapState,
interactionConfig,
mousePos
} = this.props;
- const {mousePosition} = mousePos;
const layer = layers[idx];
const data = layerData[idx];
const layerInteraction = {
- mousePosition,
+ mousePosition: mousePos.mousePosition,
wrapLongitude: true
};
@@ -288,37 +302,27 @@ export default function MapContainerFactory(MapPopover, MapControl) {
onSetLayerDomain: val => this._onLayerSetDomain(idx, val)
};
- if (!this._shouldRenderLayer(layer, data, mapLayers)) {
- return overlays;
- }
-
- let layerOverlay = [];
-
// Layer is Layer class
- if (typeof layer.renderLayer === 'function') {
- layerOverlay = layer.renderLayer({
- data,
- idx,
- layerInteraction,
- objectHovered,
- mapState,
- interactionConfig,
- layerCallbacks
- });
- }
+ const layerOverlay = layer.renderLayer({
+ data,
+ idx,
+ layerInteraction,
+ objectHovered,
+ mapState,
+ interactionConfig,
+ layerCallbacks
+ });
- if (layerOverlay.length) {
- overlays = overlays.concat(layerOverlay);
- }
- return overlays;
+ return overlays.concat(layerOverlay || []);
};
- _renderOverlay() {
+ _renderDeckOverlay(layersToRender) {
const {
mapState,
mapStyle,
layerData,
layerOrder,
+ layers,
visStateActions,
mapboxApiAccessToken,
mapboxApiUrl
@@ -331,6 +335,7 @@ export default function MapContainerFactory(MapPopover, MapControl) {
deckGlLayers = layerOrder
.slice()
.reverse()
+ .filter(idx => layers[idx].overlayType === OVERLAY_TYPE.deckgl && layersToRender[layers[idx].id])
.reduce(this._renderLayer, []);
}
@@ -360,32 +365,24 @@ export default function MapContainerFactory(MapPopover, MapControl) {
);
}
- _renderMapboxLayers() {
- const {
- layers,
- layerData,
- layerOrder
- } = this.props;
+ _updateMapboxLayers() {
+ const mapboxLayers = this.mapboxLayersSelector(this.props);
+ if (!Object.keys(mapboxLayers).length && !Object.keys(this.previousLayers).length) {
+ return;
+ }
- return generateMapboxLayers(layers, layerData, layerOrder);
+ updateMapboxLayers(
+ this._map,
+ mapboxLayers,
+ this.previousLayers
+ );
+
+ this.previousLayers = mapboxLayers;
}
_renderMapboxOverlays() {
if (this._map && this._map.isStyleLoaded()) {
-
- const mapboxLayers = this._renderMapboxLayers();
-
- updateMapboxLayers(
- this._map,
- mapboxLayers,
- this.previousLayers,
- this.props.mapLayers
- );
-
- this.previousLayers = mapboxLayers.reduce((final, layer) => ({
- ...final,
- [layer.id]: layer.config
- }), {})
+ this._updateMapboxLayers();
}
}
@@ -401,7 +398,7 @@ export default function MapContainerFactory(MapPopover, MapControl) {
mapState, mapStyle, mapStateActions, mapLayers, layers, MapComponent,
datasets, mapboxApiAccessToken, mapboxApiUrl, mapControls, toggleMapControl
} = this.props;
-
+ const layersToRender = this.layersToRenderSelector(this.props);
if (!mapStyle.bottomMapStyle) {
// style not yet loaded
return <div/>;
@@ -421,11 +418,11 @@ export default function MapContainerFactory(MapPopover, MapControl) {
<MapControl
datasets={datasets}
dragRotate={mapState.dragRotate}
- isSplit={mapState.isSplit}
+ isSplit={Boolean(mapLayers)}
isExport={this.props.isExport}
layers={layers}
+ layersToRender={layersToRender}
mapIndex={this.props.index}
- mapLayers={mapLayers}
mapControls={mapControls}
scale={mapState.scale || 1}
top={0}
@@ -443,8 +440,8 @@ export default function MapContainerFactory(MapPopover, MapControl) {
transitionDuration={TRANSITION_DURATION}
onMouseMove={this.props.visStateActions.onMouseMove}
>
- {this._renderOverlay()}
- {this._renderMapboxOverlays()}
+ {this._renderDeckOverlay(layersToRender)}
+ {this._renderMapboxOverlays(layersToRender)}
</MapComponent>
{mapStyle.topMapStyle && (
<div style={MAP_STYLE.top}>
@@ -455,7 +452,7 @@ export default function MapContainerFactory(MapPopover, MapControl) {
/>
</div>
)}
- {this._renderMapPopover()}
+ {this._renderMapPopover(layersToRender)}
</StyledMapContainer>
);
}
diff --git a/src/components/map/map-control.js b/src/components/map/map-control.js
index 829ab3336..37cdff98b 100644
--- a/src/components/map/map-control.js
+++ b/src/components/map/map-control.js
@@ -115,52 +115,6 @@ const StyledMapControlPanelHeader = styled.div`
}
`;
-/**
- * Generates all layers available for the current map
- * TODO: this may be moved into map-container or map-control or even at the reducer level
- * @param layers
- * @param mapLayers
- * @returns {[id, label, isVisible]}
- */
-const layerSelector = (layers, mapLayers) => {
- const availableItems = Object.keys(layers).reduce(
- (availableLayers, currentLayerId) => {
- // is available ? if yes add to available list
- const currentLayer = layers[currentLayerId];
- // if maplayers exists we need to make sure currentlayer
- // is contained in mapLayers in order to add onto availableLayers
- // otherwise we add all layers
-
- const layerConfig = mapLayers
- ? mapLayers[currentLayer.id]
- : currentLayer.config;
-
- const mustBeAdded =
- mapLayers && mapLayers[currentLayer.id]
- ? mapLayers[currentLayer.id].isAvailable
- : layerConfig.isVisible;
-
- return mustBeAdded
- ? [
- ...availableLayers,
- {
- id: currentLayer.id,
- name: currentLayer.config.label,
- isVisible:
- mapLayers && mapLayers[currentLayer.id]
- ? mapLayers[currentLayer.id].isVisible
- : layerConfig.isVisible,
- layer: currentLayer
- }
- ]
- : availableLayers;
- },
- []
- );
-
- return availableItems;
-};
-
const ActionPanel = ({children}) => (
<StyledMapControlAction>{children}</StyledMapControlAction>
);
@@ -223,7 +177,7 @@ const MapControlPanel = ({children, header, onClick, scale = 1, isExport}) => (
</StyledMapControlPanel>
);
-const MapLegendPanel = ({items, isActive, scale, toggleMenuPanel, isExport}) =>
+const MapLegendPanel = ({layers, isActive, scale, toggleMenuPanel, isExport}) =>
!isActive ? (
<StyledMapControlButton
key={2}
@@ -245,9 +199,7 @@ const MapLegendPanel = ({items, isActive, scale, toggleMenuPanel, isExport}) =>
onClick={toggleMenuPanel}
isExport={isExport}
>
- <MapLegend
- layers={items.filter(item => item.isVisible).map(item => item.layer)}
- />
+ <MapLegend layers={layers}/>
</MapControlPanel>
);
@@ -258,6 +210,7 @@ const MapControlFactory = () => {
dragRotate: PropTypes.bool.isRequired,
isSplit: PropTypes.bool.isRequired,
layers: PropTypes.arrayOf(PropTypes.object),
+ layersToRender: PropTypes.object.isRequired,
mapIndex: PropTypes.number.isRequired,
mapControls: PropTypes.object.isRequired,
onTogglePerspective: PropTypes.func.isRequired,
@@ -267,8 +220,7 @@ const MapControlFactory = () => {
top: PropTypes.number.isRequired,
// optional
- scale: PropTypes.number,
- mapLayers: PropTypes.object
+ scale: PropTypes.number
};
static defaultProps = {
@@ -276,24 +228,28 @@ const MapControlFactory = () => {
top: 0
};
- layerSelector = state => state.layers;
- mapLayersSelector = state => state.mapLayers;
-
- initialDataSelector = createSelector(
+ layerSelector = props => props.layers;
+ layersToRenderSelector = props => props.layersToRender;
+ layerPanelItemsSelector = createSelector(
this.layerSelector,
- this.mapLayersSelector,
- layerSelector
+ this.layersToRenderSelector,
+ (layers, layersToRender) =>
+ layers
+ .filter(l => l.config.isVisible)
+ .map(layer => ({
+ id: layer.id,
+ name: layer.config.label,
+ // layer
+ isVisible: layersToRender[layer.id]
+ }))
);
render() {
- const items = this.initialDataSelector(this.props);
-
- if (!items) {
- return null;
- }
const {
dragRotate,
+ layers,
+ layersToRender,
isSplit,
isExport,
mapIndex,
@@ -312,6 +268,8 @@ const MapControlFactory = () => {
splitMap = {}
} = mapControls;
+ // const items = this.initialDataSelector(this.props);
+
return (
<StyledMapControl className="map-control">
{/* Split Map */}
@@ -343,7 +301,7 @@ const MapControlFactory = () => {
{isSplit && visibleLayers.show ? (
<ActionPanel key={1}>
<LayerSelectorPanel
- items={items}
+ items={this.layerPanelItemsSelector(this.props)}
onMapToggleLayer={onMapToggleLayer}
isActive={visibleLayers.active}
toggleMenuPanel={() => onToggleMapControl('visibleLayers')}
@@ -377,7 +335,7 @@ const MapControlFactory = () => {
{mapLegend.show ? (
<ActionPanel key={3}>
<MapLegendPanel
- items={items}
+ layers={layers.filter(l => layersToRender[l.id])}
scale={scale}
isExport={isExport}
onMapToggleLayer={onMapToggleLayer}
diff --git a/src/layers/base-layer.js b/src/layers/base-layer.js
index ebea553f5..e976dd55d 100644
--- a/src/layers/base-layer.js
+++ b/src/layers/base-layer.js
@@ -561,9 +561,10 @@ export default class Layer {
shouldRenderLayer(data) {
return (
this.type &&
- this.hasAllColumns() &&
this.config.isVisible &&
- this.hasLayerData(data)
+ this.hasAllColumns() &&
+ this.hasLayerData(data) &&
+ typeof this.renderLayer === 'function'
);
}
diff --git a/src/layers/heatmap-layer/heatmap-layer.js b/src/layers/heatmap-layer/heatmap-layer.js
index 6976d8c85..b25490e0a 100644
--- a/src/layers/heatmap-layer/heatmap-layer.js
+++ b/src/layers/heatmap-layer/heatmap-layer.js
@@ -26,6 +26,8 @@ import MapboxGLLayer from '../mapboxgl-layer';
import HeatmapLayerIcon from './heatmap-layer-icon';
const MAX_ZOOM_LEVEL = 18;
+export const pointColResolver = ({lat, lng, altitude}) =>
+ `${lat.fieldIdx}-${lng.fieldIdx}`;
export const heatmapVisConfigs = {
opacity: 'opacity',
@@ -150,26 +152,26 @@ class HeatmapLayer extends MapboxGLLayer {
};
datasetSelector = config => config.dataId;
- isVisibleSelector = config => config.isVisible;
+ columnsSelector = config => pointColResolver(config.columns);
visConfigSelector = config => config.visConfig;
weightFieldSelector = config => config.weightField ? config.weightField.name : null;
weightDomainSelector = config => config.weightDomain;
computeHeatmapConfiguration = createSelector(
this.datasetSelector,
- this.isVisibleSelector,
+ this.columnsSelector,
this.visConfigSelector,
this.weightFieldSelector,
this.weightDomainSelector,
- (datasetId, isVisible, visConfig, weightField, weightDomain) => {
+ (datasetId, columns, visConfig, weightField, weightDomain) => {
- const layer = {
+ return {
type: 'heatmap',
id: this.id,
- source: datasetId,
+ source: `${datasetId}-${columns}`,
layout: {
- visibility: isVisible ? 'visible' : 'none'
+ visibility: 'visible'
},
maxzoom: MAX_ZOOM_LEVEL,
paint: {
@@ -203,8 +205,6 @@ class HeatmapLayer extends MapboxGLLayer {
'heatmap-opacity': visConfig.opacity
}
};
-
- return layer;
}
);
@@ -222,7 +222,7 @@ class HeatmapLayer extends MapboxGLLayer {
const isSameConfig = this.isSameConfig(options);
const data = !shouldRebuild(isSameData, isSameConfig) ?
- null :
+ oldLayerData.data :
geojsonFromPoints(
allData,
filteredIndex,
diff --git a/src/layers/mapbox-utils.js b/src/layers/mapbox-utils.js
index 71a29d01e..e6af0104e 100644
--- a/src/layers/mapbox-utils.js
+++ b/src/layers/mapbox-utils.js
@@ -22,116 +22,112 @@ import {OVERLAY_TYPE} from './base-layer';
/**
* This function will convert layers to mapbox layers
- * @param layers the layers to be converted
- * @param layerData extra layer information
- * @param layerOrder the order by which we should convert layers
- * @returns {*}
+ * @param {Array<Object>} layers the layers to be converted
+ * @param {Array<Object>} layerData extra layer information
+ * @param {Array<Number>} layerOrder the order by which we should convert layers
+ * @param {Object} layersToRender {[id]: true | false} object whether each layer should be rendered
+ * @returns {Object} {[id]: layer}
*/
-export function generateMapboxLayers(layers = [], layerData = [], layerOrder = []) {
+export function generateMapboxLayers(
+ layers = [],
+ layerData = [],
+ layerOrder = [],
+ layersToRender = {}
+) {
if (layerData.length > 0) {
- return layerOrder.slice()
+ return layerOrder
+ .slice()
.reverse()
- .reduce((overlays, idx) => {
- const layer = layers[idx];
-
- return layer.overlayType !== OVERLAY_TYPE.mapboxgl ?
- overlays
- : [
- ...overlays,
- {
- id: layer.id,
- data: layerData[idx].data,
- config: layerData[idx].config,
- datasetId: layer.config.dataId
- }
- ]
- }, []);
+ .filter(
+ idx =>
+ layers[idx].overlayType === OVERLAY_TYPE.mapboxgl &&
+ layersToRender[layers[idx].id]
+ )
+ .reduce((accu, index) => {
+ const layer = layers[index];
+ return {
+ ...accu,
+ [layer.id]: {
+ id: layer.id,
+ data: layerData[index].data,
+ isVisible: layer.config.isVisible,
+ config: layerData[index].config,
+ sourceId: layerData[index].config.source
+ }
+ };
+ }, {});
}
- return [];
+ return {};
}
/**
* Update mapbox layers on the given map
- * @param map
- * @param newLayers Array of new mapbox layers to be displayed
- * @param oldLayers Map of the old layers to be compare with the current ones to detect deleted layers
- * {layerId: datasetId}
- * @param mapLayers carries information about split map view
+ * @param {Object} map
+ * @param {Object} newLayers Map of new mapbox layers to be displayed
+ * @param {Object} oldLayers Map of the old layers to be compare with the current ones to detect deleted layers
+ * {layerId: sourceId}
*/
-export function updateMapboxLayers(map, newLayers = [], oldLayers = null, mapLayers = null, opt = {force: true}) {
- // delete non existing layers
-
+export function updateMapboxLayers(map, newLayers = {}, oldLayers = null) {
+ // delete no longer existed old layers
if (oldLayers) {
- const oldLayersKeys = Object.keys(oldLayers);
- if (newLayers.length === 0 && oldLayersKeys.length > 0) {
- oldLayersKeys.forEach(layerId => map.removeLayer(layerId));
- } else {
- // remove layers
- const currentLayersIds = newLayers.reduce((final, layer) => ({
- ...final,
- [layer.id]: true
- }), {});
-
- const layersToDelete = oldLayersKeys.reduce((final, layerId) => {
- // if layer doesn't exists anymore
- if (!currentLayersIds[layerId]) {
- return {
- ...final,
- [layerId]: oldLayers[layerId]
- };
- }
- return final;
- }, []);
- Object.keys(layersToDelete).forEach(layerId => map.removeLayer(layerId));
- }
+ checkAndRemoveOldLayers(map, oldLayers, newLayers);
}
// insert or update new layer
- // TODO: fix complexity
- /* eslint-disable complexity */
- newLayers.forEach(overlay => {
- const {id: layerId, config, data, datasetId} = overlay;
+ Object.values(newLayers).forEach(overlay => {
+ const {id: layerId, config, data, sourceId, isVisible} = overlay;
if (!data && !config) {
return;
}
- const isAvailableAndVisible =
- !(mapLayers && mapLayers[layerId]) || mapLayers[layerId].isVisible;
- // checking if source already exists
-
- if (data && isAvailableAndVisible) {
- const source = map.getSource(datasetId);
- if (!source) {
- map.addSource(datasetId, {
- type: 'geojson',
- data
- });
- }
- else {
- source.setData(data);
- }
+
+ const {data: oldData, config: oldConfig} =
+ (oldLayers && oldLayers[layerId]) || {};
+
+ if (data && data !== oldData) {
+ updateSourceData(map, sourceId, data);
}
- const oldConfig = oldLayers[layerId];
- const mapboxLayer = map.getLayer(layerId);
// compare with previous configs
+ if (oldConfig !== config) {
+ updateLayerConfig(map, layerId, config, isVisible);
+ }
+ });
+}
- if (!oldConfig || oldConfig !== config || !mapboxLayer || opt.force) {
- // check if layer already is set
- // remove it if exists
- if (mapboxLayer) {
- map.removeLayer(layerId);
- }
- // add if visible and available
- if (isAvailableAndVisible) {
- map.addLayer(config);
- }
+function checkAndRemoveOldLayers(map, oldLayers, newLayers) {
+ Object.keys(oldLayers).forEach(layerId => {
+ if (!newLayers[layerId]) {
+ map.removeLayer(layerId);
}
});
- /* eslint-enable complexity */
- // TODO: think about removing sources
-};
+}
+
+function updateLayerConfig(map, layerId, config, isVisible) {
+ const mapboxLayer = map.getLayer(layerId);
+ if (mapboxLayer) {
+ // check if layer already is set
+ // remove it if exists
+ map.removeLayer(layerId);
+ }
+
+ map.addLayer(config);
+ map.setLayoutProperty(layerId, 'visibility', isVisible ? 'visible' : 'none');
+}
+
+function updateSourceData(map, sourceId, data) {
+ const source = map.getSource(sourceId);
+
+ if (!source) {
+ map.addSource(sourceId, {
+ type: 'geojson',
+ data
+ });
+ } else {
+ source.setData(data);
+ }
+}
/**
*
* @param points
@@ -143,23 +139,37 @@ export function updateMapboxLayers(map, newLayers = [], oldLayers = null, mapLay
* @param properties [{label: {fieldIdx}]
* @returns {{type: string, properties: {}, features: {type: string, properties: {}, geometry: {type: string, coordinates: *[]}}[]}}
*/
-export function geojsonFromPoints(allData = [], filteredIndex = [], columns = {}, properties = []) {
- return {
+export function geojsonFromPoints(
+ allData = [],
+ filteredIndex = [],
+ columns = {},
+ properties = []
+) {
+ const geojson = {
type: 'FeatureCollection',
- features: filteredIndex.map(index => allData[index]).map(point => ({
+ features: []
+ };
+
+ for (let i = 0; i < filteredIndex.length; i++) {
+ const point = allData[filteredIndex[i]];
+ geojson.features.push({
type: 'Feature',
- properties: properties.reduce((final, property) => ({
- ...final,
- [property.name]: point[property.tableFieldIndex - 1]
- }), {}),
+ properties: properties.reduce(
+ (final, property) => ({
+ ...final,
+ [property.name]: point[property.tableFieldIndex - 1]
+ }),
+ {}
+ ),
geometry: {
type: 'Point',
coordinates: [
columns.lng ? point[columns.lng.fieldIdx] : null, // lng
- columns.lat ? point[columns.lat.fieldIdx] : null, // lat
- columns.altitude ? point[columns.altitude.fieldIdx] : 0 // altitude
+ columns.lat ? point[columns.lat.fieldIdx] : null // lat
]
}
- }))
- };
+ });
+ }
+
+ return geojson;
}
diff --git a/src/layers/mapboxgl-layer.js b/src/layers/mapboxgl-layer.js
index 08d8f79fe..12e753563 100644
--- a/src/layers/mapboxgl-layer.js
+++ b/src/layers/mapboxgl-layer.js
@@ -55,7 +55,11 @@ class MapboxLayerGL extends Layer {
// this layer is rendered at mapbox level
// todo: maybe need to find a better solution for this one
shouldRenderLayer() {
- return false;
+ return (
+ this.type &&
+ this.config.isVisible &&
+ this.hasAllColumns()
+ );
}
}
diff --git a/src/reducers/vis-state-updaters.js b/src/reducers/vis-state-updaters.js
index 5441ef2b5..d5aeb06d0 100644
--- a/src/reducers/vis-state-updaters.js
+++ b/src/reducers/vis-state-updaters.js
@@ -159,12 +159,7 @@ export const INITIAL_VIS_STATE = {
// describe the state of layer availability and visibility for each map
// [
// {
- // layers: {
- // layer_id: {
- // isAvailable: true|false # this is driven by the left hand panel
- // isVisible: true|false
- // }
- // }
+ // layers: {layer_id: true | false}
// }
// ]
],
@@ -208,13 +203,15 @@ export function layerConfigChangeUpdater(state, action) {
return updateStateWithLayerAndData(state, {layerData, layer, idx});
}
- const newState = {
- ...state,
- splitMaps:
- 'isVisible' in action.newConfig
- ? toggleLayerFromSplitMaps(state, newLayer)
- : state.splitMaps
- };
+ let newState = state;
+ if ('isVisible' in action.newConfig && state.splitMaps.length) {
+ newState = {
+ ...state,
+ splitMaps: action.newConfig.isVisible ?
+ addNewLayersToSplitMap(state.splitMaps, newLayer) :
+ removeLayerFromSplitMaps(state.splitMaps, newLayer)
+ };
+ }
return updateStateWithLayerAndData(newState, {layer: newLayer, idx});
}
@@ -320,18 +317,18 @@ export function layerTypeChangeUpdater(state, action) {
let newState = state;
// update splitMap layer id
- if (state.splitMaps) {
+ if (state.splitMaps.length) {
newState = {
...state,
splitMaps: state.splitMaps.map(settings => {
const {[oldId]: oldLayerMap, ...otherLayers} = settings.layers;
- return {
+ return oldId in settings.layers ? {
...settings,
layers: {
...otherLayers,
[layer.id]: oldLayerMap
}
- };
+ } : settings;
})
};
}
@@ -716,7 +713,7 @@ export const addLayerUpdater = (state, action) => {
export const removeLayerUpdater = (state, {idx}) => {
const {layers, layerData, clicked, hoverInfo} = state;
const layerToRemove = state.layers[idx];
- const newMaps = removeLayerFromSplitMaps(state, layerToRemove);
+ const newMaps = removeLayerFromSplitMaps(state.splitMaps, layerToRemove);
return {
...state,
@@ -972,61 +969,6 @@ export const toggleSplitMapUpdater = (state, action) =>
}
: closeSpecificMapAtIndex(state, action);
-/**
- * Set layers to be visible in split map
- * @memberof visStateUpdaters
- * @param {Object} state `visState`
- * @param {Object} action action
- * @param {Number} mapIndex index of the split map
- * @param {Array<string>} layerIds array of layer ids
- * @returns {Object} nextState
- * @public
- */
-export const setVisibleLayersForMapUpdater = (state, action) => {
- const {mapIndex, layerIds} = action;
- if (!layerIds) {
- return state;
- }
-
- const {splitMaps = []} = state;
-
- if (splitMaps.length === 0) {
- // we should never get into this state
- // because this action should only be triggered
- // when map view is split
- // but something may have happened
- return state;
- }
-
- // need to check if maps is populated otherwise will create
- const {[mapIndex]: map = {}} = splitMaps;
-
- const layers = map.layers || [];
-
- // we set visibility to true for all layers included in our input list
- const newLayers = (Object.keys(layers) || []).reduce((currentLayers, idx) => {
- return {
- ...currentLayers,
- [idx]: {
- ...layers[idx],
- isVisible: layerIds.includes(idx)
- }
- };
- }, {});
-
- const newMaps = [...splitMaps];
-
- newMaps[mapIndex] = {
- ...splitMaps[mapIndex],
- layers: newLayers
- };
-
- return {
- ...state,
- splitMaps: newMaps
- };
-};
-
/**
* Toggle visibility of a layer in a split map
* @memberof visStateUpdaters
@@ -1037,38 +979,19 @@ export const setVisibleLayersForMapUpdater = (state, action) => {
* @returns {Object} nextState
* @public
*/
-export const toggleLayerForMapUpdater = (state, action) => {
- if (!state.splitMaps[action.mapIndex]) {
- return state;
- }
-
- const mapSettings = state.splitMaps[action.mapIndex];
- const {layers} = mapSettings;
- if (!layers || !layers[action.layerId]) {
- return state;
- }
-
- const layer = layers[action.layerId];
-
- const newLayer = {
- ...layer,
- isVisible: !layer.isVisible
- };
-
- const newLayers = {
- ...layers,
- [action.layerId]: newLayer
- };
-
- const newSplitMaps = [...state.splitMaps];
- newSplitMaps[action.mapIndex] = {
- ...mapSettings,
- layers: newLayers
- };
+export const toggleLayerForMapUpdater = (state, {mapIndex, layerId}) => {
+ const {splitMaps} = state;
return {
...state,
- splitMaps: newSplitMaps
+ splitMaps: splitMaps.map((sm, i) => i === mapIndex ? {
+ ...splitMaps[i],
+ layers: {
+ ...splitMaps[i].layers,
+ // if layerId not in layers, set it to visible
+ [layerId]: !splitMaps[i].layers[layerId]
+ }
+ } : sm)
};
};
@@ -1169,54 +1092,47 @@ export const updateVisDataUpdater = (state, action) => {
};
/* eslint-enable max-statements */
-function generateLayerMetaForSplitViews(layer) {
- return {
- isAvailable: layer.config.isVisible,
- isVisible: layer.config.isVisible
- };
-}
-
/**
- * This method will compute the default maps custom list
- * based on the current layers status
+ * This method will compute the default maps layer settings
+ * based on the current layers visibility
* @param {Array<Object>} layers
* @returns {Array<Object>} split map settings
*/
function computeSplitMapLayers(layers) {
- const mapLayers = layers.reduce(
- (newLayers, currentLayer) => ({
- ...newLayers,
- [currentLayer.id]: generateLayerMetaForSplitViews(currentLayer)
- }),
- {}
- );
+ const mapLayers = layers
+ .filter(layer => layer.config.isVisible)
+ .reduce(
+ (newLayers, currentLayer) => ({
+ ...newLayers,
+ [currentLayer.id]: currentLayer.config.isVisible
+ }),
+ {}
+ );
+
return [
- {
- layers: mapLayers
- },
- {
- layers: mapLayers
- }
+ {layers: mapLayers},
+ {layers: cloneDeep(mapLayers)}
];
}
/**
* Remove an existing layer from split map settings
- * @param {Object} state `visState`
+ * @param {Object} splitMaps
* @param {Object} layer
* @returns {Object} Maps of custom layer objects
*/
-function removeLayerFromSplitMaps(state, layer) {
- return state.splitMaps.map(settings => {
- const {layers} = settings;
- /* eslint-disable no-unused-vars */
- const {[layer.id]: _, ...newLayers} = layers;
- /* eslint-enable no-unused-vars */
+function removeLayerFromSplitMaps(splitMaps, layer) {
+ if (!splitMaps.length) {
+ return splitMaps;
+ }
+ return splitMaps.map(settings => {
+ // eslint-disable-next-line no-unused-vars
+ const {[layer.id]: _, ...newLayers} = settings.layers;
return {
...settings,
layers: newLayers
};
- });
+ })
}
/**
@@ -1228,53 +1144,28 @@ function removeLayerFromSplitMaps(state, layer) {
function addNewLayersToSplitMap(splitMaps, layers) {
const newLayers = Array.isArray(layers) ? layers : [layers];
- if (!splitMaps || !splitMaps.length || !newLayers.length) {
+ if (!splitMaps.length || !newLayers.length) {
return splitMaps;
}
// add new layer to both maps,
- // don't override, if layer.id is already in splitMaps.settings.layers
+ // don't override, if layer.id is already in splitMaps
return splitMaps.map(settings => ({
...settings,
layers: {
...settings.layers,
...newLayers.reduce(
(accu, newLayer) =>
- newLayer.config.isVisible
- ? {
- ...accu,
- [newLayer.id]: settings.layers[newLayer.id]
- ? settings.layers[newLayer.id]
- : generateLayerMetaForSplitViews(newLayer)
- }
- : accu,
+ [newLayer.id] in settings.layers || !newLayer.config.isVisible ? accu : {
+ ...accu,
+ [newLayer.id]: newLayer.config.isVisible
+ },
{}
)
}
}));
}
-/**
- * Hide an existing layers from custom map layer objects
- * @param {Object} state
- * @param {Object} layer
- * @returns {Object} Maps of custom layer objects
- */
-function toggleLayerFromSplitMaps(state, layer) {
- return state.splitMaps.map(settings => {
- const {layers} = settings;
- const newLayers = {
- ...layers,
- [layer.id]: generateLayerMetaForSplitViews(layer)
- };
-
- return {
- ...settings,
- layers: newLayers
- };
- });
-}
-
/**
* When a user clicks on the specific map closing icon
* the application will close the selected map
@@ -1287,27 +1178,16 @@ function toggleLayerFromSplitMaps(state, layer) {
function closeSpecificMapAtIndex(state, action) {
// retrieve layers meta data from the remaining map that we need to keep
const indexToRetrieve = 1 - action.payload;
-
- const metaSettings = state.splitMaps[indexToRetrieve];
- if (!metaSettings || !metaSettings.layers) {
- // if we can't find the meta settings we simply clean up splitMaps and
- // keep global state as it is
- // but why does this ever happen?
- return {
- ...state,
- splitMaps: []
- };
- }
-
+ const mapLayers = state.splitMaps[indexToRetrieve].layers;
const {layers} = state;
// update layer visibility
const newLayers = layers.map(layer =>
- layer.updateLayerConfig({
- isVisible: metaSettings.layers[layer.id]
- ? metaSettings.layers[layer.id].isVisible
- : layer.config.isVisible
- })
+ !mapLayers[layer.id] && layer.config.isVisible ?
+ layer.updateLayerConfig({
+ // if layer.id is not in mapLayers, it should be inVisible
+ isVisible: false
+ }) : layer
);
// delete map
diff --git a/src/reducers/vis-state.js b/src/reducers/vis-state.js
index 41d763567..bd46f26da 100644
--- a/src/reducers/vis-state.js
+++ b/src/reducers/vis-state.js
@@ -73,8 +73,6 @@ const actionHandler = {
[ActionTypes.SET_FILTER_PLOT]: visStateUpdaters.setFilterPlotUpdater,
- [ActionTypes.SET_VISIBLE_LAYERS_FOR_MAP]: visStateUpdaters.setVisibleLayersForMapUpdater,
-
[ActionTypes.SHOW_DATASET_TABLE]: visStateUpdaters.showDatasetTableUpdater,
[ActionTypes.TOGGLE_FILTER_ANIMATION]: visStateUpdaters.toggleFilterAnimationUpdater,
diff --git a/src/schemas/vis-state-schema.js b/src/schemas/vis-state-schema.js
index caa9e5dd0..52b6827c7 100644
--- a/src/schemas/vis-state-schema.js
+++ b/src/schemas/vis-state-schema.js
@@ -605,6 +605,39 @@ export class DimensionFieldSchema extends Schema {
}
}
+export class SplitMapsSchema extends Schema {
+ convertLayerSettings(accu, [key, value]) {
+ if (typeof value === 'boolean') {
+ return {
+ ...accu,
+ [key]: value
+ };
+ } else if (value && typeof value === 'object' && value.isAvailable) {
+ return {
+ ...accu,
+ [key]: Boolean(value.isVisible)
+ };
+ }
+ return accu;
+ }
+
+ load(splitMaps) {
+ // previous splitMaps Schema {layers: {layerId: {isVisible, isAvailable}}}
+
+ if (!Array.isArray(splitMaps) || !splitMaps.length) {
+ return {splitMaps: []};
+ }
+
+ return {
+ splitMaps: splitMaps.map(settings => ({
+ ...settings,
+ layers: Object.entries(settings.layers || {})
+ .reduce(this.convertLayerSettings, {})
+ }))
+ }
+ }
+}
+
export const filterPropsV1 = {
...filterPropsV0,
plotType: null,
@@ -648,7 +681,10 @@ export const propertiesV1 = {
properties: interactionPropsV0
}),
layerBlending: null,
- splitMaps: null
+ splitMaps: new SplitMapsSchema({
+ key: 'splitMaps',
+ version: VERSIONS.v1
+ })
};
export const visStateSchemaV0 = new Schema({
diff --git a/test/fixtures/state-saved-v1-3.js b/test/fixtures/state-saved-v1-3.js
index 2f1299950..f195acb62 100644
--- a/test/fixtures/state-saved-v1-3.js
+++ b/test/fixtures/state-saved-v1-3.js
@@ -494,14 +494,14 @@ export const mergedLayers = [mergedLayer0, mergedLayer1];
export const mergedSplitMaps = [
{
layers: {
- f24uw1: {isAvailable: true, isVisible: false},
- '9x77w7h': {isAvailable: true, isVisible: true}
+ f24uw1: false,
+ '9x77w7h': true
}
},
{
layers: {
- f24uw1: {isAvailable: true, isVisible: true},
- '9x77w7h': {isAvailable: true, isVisible: false}
+ f24uw1: true,
+ '9x77w7h': false
}
}
];
diff --git a/test/node/layer-tests/heatmap-layer-specs.js b/test/node/layer-tests/heatmap-layer-specs.js
index 09521e17e..63649ac32 100644
--- a/test/node/layer-tests/heatmap-layer-specs.js
+++ b/test/node/layer-tests/heatmap-layer-specs.js
@@ -53,7 +53,6 @@ test('#HeatmapLayer -> contructor', t => {
t.end()
});
-
test('#Heatmaplayer -> formatLayerData', t => {
const {rows} = processCsvData(csvData);
const filteredIndex = Array(rows.length).fill().map((_, index) => index);
@@ -79,14 +78,12 @@ test('#Heatmaplayer -> formatLayerData', t => {
data: [data, rows, filteredIndex, undefined],
test: result => {
const {layerData, layer} = result;
- // log(layer);
- // log(layerData);
const expectedLayerData = {
columns,
config: {
type: 'heatmap',
- source: 'heatmap',
+ source: 'heatmap-1-2',
layout: {
visibility: 'visible'
},
@@ -118,30 +115,30 @@ test('#Heatmaplayer -> formatLayerData', t => {
data: {
type: 'FeatureCollection',
features: [
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2590542, 29.9900937, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2461142, 29.9927699, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2312742, 29.9907261, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2175827, 29.9870074, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2154899, 29.9923041, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2149361, 29.9968249, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2164035, 30.0037217, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2179346, 30.0116207, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2179556, 30.0208925, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2178842, 30.0218999, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2179138, 30.0229344, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2179415, 30.0264237, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2181809, 30.0292134, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2193991, 30.034391, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2181803, 30.0352752, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2195902, 30.0395918, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2174421, 30.0497387, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2165983, 30.0538936, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2148748, 30.060911, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2212278, 30.060334, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2288985, 30.0554663, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2187021, 30.0614122, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2191059, 30.0612697, 0 ] } },
- { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2194728, 30.0610977, 0 ] } }
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2590542, 29.9900937] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2461142, 29.9927699] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2312742, 29.9907261] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2175827, 29.9870074] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2154899, 29.9923041] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2149361, 29.9968249] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2164035, 30.0037217] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2179346, 30.0116207] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2179556, 30.0208925] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2178842, 30.0218999] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2179138, 30.0229344] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2179415, 30.0264237] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2181809, 30.0292134] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2193991, 30.034391] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2181803, 30.0352752] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2195902, 30.0395918] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2174421, 30.0497387] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2165983, 30.0538936] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2148748, 30.060911] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2212278, 30.060334] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2288985, 30.0554663] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2187021, 30.0614122] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2191059, 30.0612697] } },
+ { type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: [ 31.2194728, 30.0610977] } }
]
},
weightField: null
diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.js
index 0840a9d7a..24cc3515c 100644
--- a/test/node/reducers/vis-state-test.js
+++ b/test/node/reducers/vis-state-test.js
@@ -198,24 +198,11 @@ test('#visStateReducer -> ADD_LAYER.1', t => {
layers: [{id: 'existing_layer'}],
layerData: [[{data: [1, 2, 3]}, {data: [4, 5, 6]}]],
layerOrder: [0],
- splitMaps: [
- {
- layers: {
- existing_layer: {
- isAvailable: true,
- isVisible: false
- }
- }
- },
- {
- layers: {
- existing_layer: {
- isAvailable: true,
- isVisible: false
- }
- }
- }
- ]
+ splitMaps: [{
+ layers: {existing_layer: false}
+ },{
+ layers: {existing_layer: false}
+ }]
};
const newReducer = reducer(oldState, VisStateActions.addLayer());
@@ -223,26 +210,14 @@ test('#visStateReducer -> ADD_LAYER.1', t => {
const expectedSplitMaps = [
{
layers: {
- existing_layer: {
- isAvailable: true,
- isVisible: false
- },
- [newId]: {
- isAvailable: true,
- isVisible: true
- }
+ existing_layer:false,
+ [newId]: true
}
},
{
layers: {
- existing_layer: {
- isAvailable: true,
- isVisible: false
- },
- [newId]: {
- isAvailable: true,
- isVisible: true
- }
+ existing_layer: false,
+ [newId]: true
}
}
];
@@ -294,26 +269,14 @@ test('#visStateReducer -> LAYER_TYPE_CHANGE.1', t => {
splitMaps: [
{
layers: {
- existing_layer: {
- isAvailable: true,
- isVisible: false
- },
- more_layer: {
- isAvailable: true,
- isVisible: true
- }
+ existing_layer: false,
+ more_layer: true
}
},
{
layers: {
- existing_layer: {
- isAvailable: true,
- isVisible: false
- },
- more_layer: {
- isAvailable: true,
- isVisible: false
- }
+ existing_layer: false,
+ more_layer: false
}
}
]
@@ -327,26 +290,14 @@ test('#visStateReducer -> LAYER_TYPE_CHANGE.1', t => {
const expectedSplitMaps = [
{
layers: {
- existing_layer: {
- isAvailable: true,
- isVisible: false
- },
- [newId]: {
- isAvailable: true,
- isVisible: true
- }
+ existing_layer: false,
+ [newId]: true
}
},
{
layers: {
- existing_layer: {
- isAvailable: true,
- isVisible: false
- },
- [newId]: {
- isAvailable: true,
- isVisible: false
- }
+ existing_layer: false,
+ [newId]: false
}
}
];
@@ -1269,26 +1220,14 @@ test('#visStateReducer -> UPDATE_VIS_DATA.SPLIT_MAPS', t => {
splitMaps: [
{
layers: {
- a: {
- isAvailable: true,
- isVisible: true
- },
- b: {
- isAvailable: true,
- isVisible: false
- }
+ a: true,
+ b: false
}
},
{
layers: {
- a: {
- isAvailable: true,
- isVisible: false
- },
- b: {
- isAvailable: true,
- isVisible: true
- }
+ a: false,
+ b: true
}
}
],
@@ -1317,38 +1256,19 @@ test('#visStateReducer -> UPDATE_VIS_DATA.SPLIT_MAPS', t => {
// first visible layer should be point
const id1 = newState.layers[3].id;
-
const expectedSplitMaps = [
{
layers: {
- a: {
- isAvailable: true,
- isVisible: true
- },
- b: {
- isAvailable: true,
- isVisible: false
- },
- [id1]: {
- isAvailable: true,
- isVisible: true
- }
+ a: true,
+ b: false,
+ [id1]: true
}
},
{
layers: {
- a: {
- isAvailable: true,
- isVisible: false
- },
- b: {
- isAvailable: true,
- isVisible: true
- },
- [id1]: {
- isAvailable: true,
- isVisible: true
- }
+ a: false,
+ b: true,
+ [id1]: true
}
}
];
@@ -2330,37 +2250,29 @@ test('#visStateReducer -> REMOVE_DATASET', t => {
test('#visStateReducer -> SPLIT_MAP: TOGGLE', t => {
const layer0 = new ArcLayer({id: 'a', dataId: 'puppy_0', isVisible: true});
+ const layer1 = new ArcLayer({id: 'b', dataId: 'puppy_0', isVisible: false});
const oldState = {
- layers: [layer0],
+ layers: [layer0, layer1],
splitMaps: []
};
const newReducer = reducer(oldState, MapStateActions.toggleSplitMap());
t.deepEqual(
- newReducer,
- {
- layers: [layer0],
- splitMaps: [
- {
- layers: {
- a: {
- isAvailable: true,
- isVisible: true
- }
- }
- },
- {
- layers: {
- a: {
- isAvailable: true,
- isVisible: true
- }
- }
+ newReducer.splitMaps,
+ [
+ {
+ layers: {
+ a: true
}
- ]
- },
+ },
+ {
+ layers: {
+ a: true
+ }
+ }
+ ],
'should split map'
);
@@ -2385,26 +2297,14 @@ test('#visStateReducer -> SPLIT_MAP: REMOVE_LAYER', t => {
splitMaps: [
{
layers: {
- a: {
- isVisible: true,
- isAvailable: true
- },
- b: {
- isVisible: true,
- isAvailable: true
- }
+ a: true,
+ b: true
}
},
{
layers: {
- a: {
- isVisible: true,
- isAvailable: true
- },
- b: {
- isVisible: true,
- isAvailable: true
- }
+ a: true,
+ b: true
}
}
]
@@ -2426,18 +2326,12 @@ test('#visStateReducer -> SPLIT_MAP: REMOVE_LAYER', t => {
splitMaps: [
{
layers: {
- a: {
- isVisible: true,
- isAvailable: true
- }
+ a: true
}
},
{
layers: {
- a: {
- isVisible: true,
- isAvailable: true
- }
+ a: true
}
}
]
@@ -2480,42 +2374,18 @@ test('#visStateReducer -> SPLIT_MAP: REMOVE_DATASET', t => {
splitMaps: [
{
layers: {
- a: {
- isVisible: true,
- isAvailable: true
- },
- b: {
- isVisible: true,
- isAvailable: true
- },
- c: {
- isVisible: true,
- isAvailable: true
- },
- d: {
- isVisible: true,
- isAvailable: true
- }
+ a: true,
+ b: true,
+ c: true,
+ d: true
}
},
{
layers: {
- a: {
- isVisible: true,
- isAvailable: true
- },
- b: {
- isVisible: true,
- isAvailable: true
- },
- c: {
- isVisible: true,
- isAvailable: true
- },
- d: {
- isVisible: true,
- isAvailable: true
- }
+ a: true,
+ b: true,
+ c: true,
+ d: true
}
}
]
@@ -2550,34 +2420,16 @@ test('#visStateReducer -> SPLIT_MAP: REMOVE_DATASET', t => {
splitMaps: [
{
layers: {
- a: {
- isVisible: true,
- isAvailable: true
- },
- b: {
- isVisible: true,
- isAvailable: true
- },
- d: {
- isVisible: true,
- isAvailable: true
- }
+ a: true,
+ b: true,
+ d: true
}
},
{
layers: {
- a: {
- isVisible: true,
- isAvailable: true
- },
- b: {
- isVisible: true,
- isAvailable: true
- },
- d: {
- isVisible: true,
- isAvailable: true
- }
+ a: true,
+ b: true,
+ d: true
}
}
]
@@ -2606,18 +2458,12 @@ test('#visStateReducer -> SPLIT_MAP: ADD_LAYER', t => {
splitMaps: [
{
layers: {
- existing_layer: {
- isAvailable: true,
- isVisible: true
- }
+ existing_layer: true
}
},
{
layers: {
- existing_layer: {
- isAvailable: true,
- isVisible: true
- }
+ existing_layer: true
}
}
]
@@ -2646,18 +2492,22 @@ test('#visStateReducer -> SPLIT_MAP: ADD_LAYER', t => {
'newLayer was added into splitMaps layers'
);
t.deepEqual(
- newReducer.splitMaps[0].layers[newReducer.layers[1].id],
+ newReducer.splitMaps[0],
{
- isAvailable: true,
- isVisible: true
+ layers: {
+ existing_layer: true,
+ [newReducer.layers[1].id]: true
+ }
},
'newLayer map meta data settings are correct'
);
t.deepEqual(
- newReducer.splitMaps[1].layers[newReducer.layers[1].id],
+ newReducer.splitMaps[1],
{
- isAvailable: true,
- isVisible: true
+ layers: {
+ existing_layer: true,
+ [newReducer.layers[1].id]: true
+ }
},
'newLayer map meta data settings are correct'
);
@@ -2674,26 +2524,14 @@ test('#visStateReducer -> SPLIT_MAP: TOGGLE_SPLIT_MAP', t => {
splitMaps: [
{
layers: {
- a: {
- isAvailable: true,
- isVisible: false
- },
- b: {
- isAvailable: true,
- isVisible: true
- }
+ a: true,
+ b: true
}
},
{
layers: {
- a: {
- isAvailable: true,
- isVisible: true
- },
- b: {
- isAvailable: true,
- isVisible: false
- }
+ a: true,
+ b: false
}
}
]
@@ -2715,123 +2553,20 @@ test('#visStateReducer -> SPLIT_MAP: TOGGLE_SPLIT_MAP', t => {
t.end();
});
-test('#visStateReducer -> SPLIT_MAP: SET VISIBLE LAYERS IN MAP', t => {
- const layer1 = new PointLayer({id: 'a'});
- const layer2 = new PointLayer({id: 'b'});
- const oldState = {
- layers: [layer1, layer2],
- layerData: [{data: 1}, {data: 2}],
- layerOrder: [1, 0],
- hoverInfo: {
- layer: {props: {id: 'b'}},
- picked: true
- },
- clicked: {
- layer: {props: {id: 'a'}},
- picked: true
- },
- splitMaps: [
- {
- layers: {
- a: {
- isVisible: true,
- isAvailable: true
- },
- b: {
- isVisible: true,
- isAvailable: true
- }
- }
- },
- {
- layers: {
- a: {
- isVisible: true,
- isAvailable: true
- },
- b: {
- isVisible: true,
- isAvailable: true
- }
- }
- }
- ]
- };
-
- const newState = reducer(
- oldState,
- VisStateActions.setVisibleLayersForMap(1, ['a'])
- );
-
- const expectedState = {
- layers: [layer1, layer2],
- layerData: [{data: 1}, {data: 2}],
- layerOrder: [1, 0],
- hoverInfo: {
- layer: {props: {id: 'b'}},
- picked: true
- },
- clicked: {
- layer: {props: {id: 'a'}},
- picked: true
- },
- splitMaps: [
- {
- layers: {
- a: {
- isVisible: true,
- isAvailable: true
- },
- b: {
- isVisible: true,
- isAvailable: true
- }
- }
- },
- {
- layers: {
- a: {
- isVisible: true,
- isAvailable: true
- },
- b: {
- isVisible: false,
- isAvailable: true
- }
- }
- }
- ]
- };
-
- t.deepEqual(
- newState,
- expectedState,
- 'should hide layer B in split map using set visible layers'
- );
-
- t.end();
-});
-
test('#visStateReducer -> SPLIT_MAP: HIDE LAYER', t => {
- const layer1 = new PointLayer({id: 'a'});
- // const layer2 = new PointLayer({id: 'b'});
+
const oldState = {
- layers: [layer1],
splitMaps: [
{
layers: {
- a: {
- isVisible: true,
- isAvailable: true
- }
+ a: true,
+ b: true
}
},
{
layers: {
- a: {
- isVisible: true,
- isAvailable: true
- }
+ a: true,
+ b: false
}
}
]
@@ -2840,28 +2575,23 @@ test('#visStateReducer -> SPLIT_MAP: HIDE LAYER', t => {
const newState = reducer(oldState, VisStateActions.toggleLayerForMap(1, 'a'));
const expectedState = {
- layers: [layer1],
splitMaps: [
{
layers: {
- a: {
- isVisible: true,
- isAvailable: true
- }
+ a: true,
+ b: true
}
},
{
layers: {
- a: {
- isVisible: false,
- isAvailable: true
- }
+ a: false,
+ b: false
}
}
]
};
- t.deepEqual(newState, expectedState, 'should hide layer B in split map');
+ t.deepEqual(newState.splitMaps, expectedState.splitMaps, 'should hide layer B in split map');
t.end();
});