Skip to content

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

feat(annotations): support individual fade on zoom (#3836)

Igor Dykhta5db79a291893
diff --git a/src/components/src/annotations/annotation-node.spec.tsx b/src/components/src/annotations/annotation-node.spec.tsx
new file mode 100644
index 000000000..2c0bf8cb5
--- /dev/null
+++ b/src/components/src/annotations/annotation-node.spec.tsx
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+import React from 'react';
+import {DndContext} from '@dnd-kit/core';
+import {render} from '@testing-library/react';
+
+import {AnnotationKind} from '@kepler.gl/constants';
+import {Annotation} from '@kepler.gl/types';
+
+import AnnotationNode from './annotation-node';
+import {MapViewport} from './annotation-utils';
+
+const annotation: Annotation = {
+ id: 'annotation-1',
+ kind: AnnotationKind.POINT,
+ isVisible: true,
+ autoSize: false,
+ autoSizeY: false,
+ anchorPoint: [0, 0],
+ label: 'Test annotation',
+ lineColor: '#ffffff',
+ lineWidth: 2,
+ textWidth: 120,
+ textHeight: 40,
+ armLength: 20,
+ angle: 0
+};
+
+const viewport: MapViewport = {
+ project: () => [100, 200],
+ unproject: () => [0, 0],
+ longitude: 0,
+ latitude: 0,
+ width: 800,
+ height: 600,
+ zoom: 4
+};
+
+describe('AnnotationNode', () => {
+ test('removes the entire annotation shape from hit testing at zero opacity', () => {
+ const {container, rerender} = render(
+ <svg>
+ <DndContext>
+ <AnnotationNode
+ annotation={annotation}
+ opacity={0}
+ viewport={viewport}
+ isEditing={true}
+ isSelected={true}
+ />
+ </DndContext>
+ </svg>
+ );
+ const shape = container.querySelector('[data-annotation-part="shape"]') as SVGGElement;
+
+ expect(shape.style.display).toBe('none');
+
+ rerender(
+ <svg>
+ <DndContext>
+ <AnnotationNode
+ annotation={annotation}
+ opacity={0.5}
+ viewport={viewport}
+ isEditing={true}
+ isSelected={true}
+ />
+ </DndContext>
+ </svg>
+ );
+
+ expect(shape.style.display).toBe('');
+ });
+});
diff --git a/src/components/src/annotations/annotation-node.tsx b/src/components/src/annotations/annotation-node.tsx
index ca2c47fd1..2f064278b 100644
--- a/src/components/src/annotations/annotation-node.tsx
+++ b/src/components/src/annotations/annotation-node.tsx
@@ -49,12 +49,19 @@ const ResizeHandle: FC<{id: string; x: number; y: number}> = ({id, x, y}) => {
export type AnnotationNodeProps = {
annotation: Annotation;
+ opacity?: number;
viewport: MapViewport;
isEditing: boolean;
isSelected: boolean;
};
-const AnnotationNode: FC<AnnotationNodeProps> = ({annotation, viewport, isEditing, isSelected}) => {
+const AnnotationNode: FC<AnnotationNodeProps> = ({
+ annotation,
+ opacity = 1,
+ viewport,
+ isEditing,
+ isSelected
+}) => {
const {lineColor, lineWidth} = annotation;
const marker = makeMarker(annotation, viewport);
const {kind, x, y, tx, ty} = marker;
@@ -140,7 +147,21 @@ const AnnotationNode: FC<AnnotationNodeProps> = ({annotation, viewport, isEditin
);
}
- return <g transform={`translate(${x},${y})`}>{body}</g>;
+ return (
+ <g
+ data-annotation-id={annotation.id}
+ data-annotation-part="shape"
+ transform={`translate(${x},${y})`}
+ style={{
+ opacity,
+ display: opacity === 0 ? 'none' : undefined,
+ visibility: opacity === 0 ? 'hidden' : undefined,
+ pointerEvents: opacity === 0 ? 'none' : undefined
+ }}
+ >
+ {body}
+ </g>
+ );
};
export default AnnotationNode;
diff --git a/src/components/src/annotations/annotation-overlay.tsx b/src/components/src/annotations/annotation-overlay.tsx
index fb3d798e7..db3cb71e2 100644
--- a/src/components/src/annotations/annotation-overlay.tsx
+++ b/src/components/src/annotations/annotation-overlay.tsx
@@ -52,6 +52,7 @@ const AnnotationTextContainer = styled.div`
export type AnnotationOverlayProps = {
annotations: Annotation[];
+ getAnnotationOpacity?: (annotationId: string) => number;
selectedAnnotationId: string | null;
isEditingAnnotationText: boolean;
isAnnotationMode: boolean;
@@ -65,6 +66,7 @@ export type AnnotationOverlayProps = {
const AnnotationOverlay: FC<AnnotationOverlayProps> = ({
annotations,
+ getAnnotationOpacity = () => 1,
selectedAnnotationId,
isEditingAnnotationText,
isAnnotationMode,
@@ -194,6 +196,7 @@ const AnnotationOverlay: FC<AnnotationOverlayProps> = ({
<AnnotationNode
key={annotation.id}
annotation={annotation}
+ opacity={getAnnotationOpacity(annotation.id)}
viewport={viewport}
isEditing={isAnnotationMode}
isSelected={annotation.id === selectedAnnotationId}
@@ -205,6 +208,7 @@ const AnnotationOverlay: FC<AnnotationOverlayProps> = ({
<AnnotationText
key={annotation.id}
annotation={annotation}
+ opacity={getAnnotationOpacity(annotation.id)}
viewport={viewport}
isEditing={isAnnotationMode}
isSelected={annotation.id === selectedAnnotationId}
diff --git a/src/components/src/annotations/annotation-text.tsx b/src/components/src/annotations/annotation-text.tsx
index 7cc16b423..c213c0cb5 100644
--- a/src/components/src/annotations/annotation-text.tsx
+++ b/src/components/src/annotations/annotation-text.tsx
@@ -77,6 +77,7 @@ const StyledToolbarWrapper = styled.div`
export type AnnotationTextProps = {
annotation: Annotation;
+ opacity?: number;
viewport: MapViewport;
isEditing: boolean;
isSelected: boolean;
@@ -88,6 +89,7 @@ export type AnnotationTextProps = {
const AnnotationText: FC<AnnotationTextProps> = ({
annotation,
+ opacity = 1,
viewport,
isEditing,
isSelected,
@@ -127,7 +129,14 @@ const AnnotationText: FC<AnnotationTextProps> = ({
$isEditingText={isEditingText}
$isSelected={isSelected}
$textVerticalAlign={textVerticalAlign}
- style={style}
+ data-annotation-id={annotation.id}
+ data-annotation-part="text"
+ style={{
+ ...style,
+ opacity,
+ visibility: opacity === 0 ? 'hidden' : undefined,
+ pointerEvents: opacity === 0 ? 'none' : undefined
+ }}
{...(isEditing
? {
...attributes,
diff --git a/src/components/src/kepler-gl.tsx b/src/components/src/kepler-gl.tsx
index fde112362..b23ae923a 100644
--- a/src/components/src/kepler-gl.tsx
+++ b/src/components/src/kepler-gl.tsx
@@ -233,6 +233,7 @@ export const sidePanelSelector = (props: KeplerGLProps, availableProviders, filt
datasets: filteredDatasets,
filters: props.visState.filters,
layers: props.visState.layers,
+ annotations: props.visState.annotations,
layerOrder: props.visState.layerOrder,
layerClasses: props.visState.layerClasses,
interactionConfig: props.visState.interactionConfig,
diff --git a/src/components/src/map-container.tsx b/src/components/src/map-container.tsx
index 2b1b576d7..7b8865eb4 100644
--- a/src/components/src/map-container.tsx
+++ b/src/components/src/map-container.tsx
@@ -117,7 +117,9 @@ import {
MapStyle,
areAnyDeckLayersLoading,
computeDeckLayers,
+ getZoomOpacityAnnotationTargetId,
getLayerHoverProp,
+ getLayerZoomOpacityFactor,
LayerHoverProp,
prepareLayersForDeck,
prepareLayersToRender,
@@ -1608,6 +1610,7 @@ export default function MapContainerFactory(
const useMapboxAdapter = ResolvedMapComponent === MapboxLegacyMap;
const internalViewState = this.context?.getInternalViewState(index);
+ const annotationZoom = internalViewState?.zoom ?? mapState.zoom;
const configMaxPitch = mapState.maxPitch ?? getApplicationConfig().maxPitch;
const effectiveMaxPitch = useMapboxAdapter
? Math.min(configMaxPitch, MAPBOX_MAX_PITCH)
@@ -1746,6 +1749,13 @@ export default function MapContainerFactory(
) : null}
<AnnotationOverlay
annotations={visState.annotations}
+ getAnnotationOpacity={annotationId =>
+ getLayerZoomOpacityFactor(
+ getZoomOpacityAnnotationTargetId(annotationId),
+ annotationZoom,
+ interactionConfig
+ )
+ }
selectedAnnotationId={visState.selectedAnnotationId}
isEditingAnnotationText={visState.isEditingAnnotationText}
isAnnotationMode={Boolean(mapControls?.annotation?.active)}
diff --git a/src/components/src/side-panel.tsx b/src/components/src/side-panel.tsx
index ffe880387..44ac97a8c 100644
--- a/src/components/src/side-panel.tsx
+++ b/src/components/src/side-panel.tsx
@@ -118,6 +118,7 @@ export default function SidePanelFactory(
datasets,
filters,
layers,
+ annotations = [],
layerBlending,
overlayBlending,
layerClasses,
@@ -241,6 +242,7 @@ export default function SidePanelFactory(
datasets={datasets}
filters={filters}
layers={layers}
+ annotations={annotations}
layerClasses={layerClasses}
layerOrder={layerOrder}
layerBlending={layerBlending}
diff --git a/src/components/src/side-panel/interaction-manager.tsx b/src/components/src/side-panel/interaction-manager.tsx
index 9ed771164..e4bcc05d5 100644
--- a/src/components/src/side-panel/interaction-manager.tsx
+++ b/src/components/src/side-panel/interaction-manager.tsx
@@ -4,7 +4,7 @@
import React from 'react';
import {useIntl} from 'react-intl';
-import {InteractionConfig, LayerOrder, MapInfo, MapState} from '@kepler.gl/types';
+import {Annotation, InteractionConfig, LayerOrder, MapInfo, MapState} from '@kepler.gl/types';
import {UIStateActions, VisStateActions} from '@kepler.gl/actions';
import {Datasets} from '@kepler.gl/table';
import {Layer} from '@kepler.gl/layers';
@@ -39,6 +39,7 @@ type InteractionManagerProps = {
uiStateActions?: typeof UIStateActions;
panelMetadata: PanelMeta;
layers?: readonly Layer[];
+ annotations?: readonly Annotation[];
layerOrder?: LayerOrder;
mapLegendActive?: boolean;
mapInfo?: Partial<MapInfo>;
@@ -75,6 +76,7 @@ function InteractionManagerFactory(
uiStateActions,
panelMetadata,
layers,
+ annotations = [],
layerOrder,
mapLegendActive,
mapInfo,
@@ -127,6 +129,7 @@ function InteractionManagerFactory(
<ZoomOpacityConfig
key={key}
layers={layers}
+ annotations={annotations}
zoomOpacityConfig={interactionConfig.zoomOpacity}
zoom={fadeOnZoomMarkerZoom(mapState)}
visStateActions={visStateActions}
diff --git a/src/components/src/side-panel/interaction-panel/zoom-opacity-config.spec.tsx b/src/components/src/side-panel/interaction-panel/zoom-opacity-config.spec.tsx
new file mode 100644
index 000000000..9d66cc44d
--- /dev/null
+++ b/src/components/src/side-panel/interaction-panel/zoom-opacity-config.spec.tsx
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+import React from 'react';
+
+import {VisStateActions} from '@kepler.gl/actions';
+import {renderWithTheme} from 'test/helpers/component-jest-utils';
+
+import PanelHeaderActionFactory from '../panel-header-action';
+import ZoomOpacityConfigFactory from './zoom-opacity-config';
+
+const ZoomOpacityConfig = ZoomOpacityConfigFactory(PanelHeaderActionFactory());
+
+describe('ZoomOpacityConfig', () => {
+ test('renders for existing callers that omit annotations', () => {
+ const {container} = renderWithTheme(
+ <ZoomOpacityConfig layers={[]} visStateActions={VisStateActions} />
+ );
+
+ expect(container.querySelector('.interaction-zoom-opacity')).not.toBeNull();
+ });
+});
diff --git a/src/components/src/side-panel/interaction-panel/zoom-opacity-config.tsx b/src/components/src/side-panel/interaction-panel/zoom-opacity-config.tsx
index 673ecf363..66e5b5d81 100644
--- a/src/components/src/side-panel/interaction-panel/zoom-opacity-config.tsx
+++ b/src/components/src/side-panel/interaction-panel/zoom-opacity-config.tsx
@@ -10,13 +10,24 @@ import {VisStateActions} from '@kepler.gl/actions';
import {generateHashId} from '@kepler.gl/common-utils';
import {FormattedMessage} from '@kepler.gl/localization';
import {Layer} from '@kepler.gl/layers';
-import {DEFAULT_ZOOM_OPACITY_STOPS, setZoomOpacityStop} from '@kepler.gl/reducers';
-import {InteractionConfig, ZoomOpacityController, ZoomOpacityStops} from '@kepler.gl/types';
+import {
+ DEFAULT_ZOOM_OPACITY_STOPS,
+ getZoomOpacityAnnotationTargetId,
+ setZoomOpacityStop
+} from '@kepler.gl/reducers';
+import {
+ Annotation,
+ InteractionConfig,
+ ZoomOpacityController,
+ ZoomOpacityStops
+} from '@kepler.gl/types';
import ZoomOpacitySlider from './zoom-opacity-slider';
import ItemSelector from '../../common/item-selector/item-selector';
-import {Delete, Settings, ZoomIn} from '../../common/icons';
+import {ChickletButton, ChickletTag} from '../../common/item-selector/chickleted-input';
+import {ListItemProps} from '../../common/item-selector/dropdown-list';
+import {AnnotationText, Delete, Settings, ZoomIn} from '../../common/icons';
import PanelHeaderActionFactory, {PanelHeaderActionIcon} from '../panel-header-action';
import Switch from '../../common/switch';
import {
@@ -81,6 +92,88 @@ const RemoveButton = styled(Button)`
const EMPTY_CONTROLLERS: ZoomOpacityController[] = [];
+type ZoomOpacityTarget = Layer | {id: string; label: string; annotationId: string};
+
+const TargetLabel = styled.span`
+ align-items: center;
+ display: flex;
+ min-width: 0;
+ width: 100%;
+`;
+
+const AnnotationIcon = styled(AnnotationText)`
+ flex: 0 0 auto;
+ margin-right: 6px;
+`;
+
+const TargetName = styled.span`
+ flex: 1 1 auto;
+ min-width: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+`;
+
+const TargetListItemAnchor = styled.span`
+ align-items: center;
+ display: flex;
+ min-width: 0;
+ white-space: nowrap;
+`;
+
+const TargetChickletTag = styled(ChickletTag)`
+ display: flex;
+ min-width: 0;
+ white-space: nowrap;
+
+ &:hover {
+ overflow: hidden;
+ }
+`;
+
+const getTargetLabel = (target: ZoomOpacityTarget): string =>
+ 'label' in target ? target.label : target.config?.label || target.id;
+
+const ZoomOpacityTargetLabel = ({target}: {target: ZoomOpacityTarget}) => (
+ <TargetLabel title={getTargetLabel(target)}>
+ {'annotationId' in target ? (
+ <AnnotationIcon
+ className="zoom-opacity-target__annotation-icon"
+ height="14px"
+ aria-hidden="true"
+ />
+ ) : null}
+ <TargetName className="zoom-opacity-target__name">{getTargetLabel(target)}</TargetName>
+ </TargetLabel>
+);
+
+const ZoomOpacityTargetListItem = ({value, disabled}: ListItemProps<ZoomOpacityTarget>) => (
+ <TargetListItemAnchor className={classnames('list__item__anchor', {disabled})}>
+ <ZoomOpacityTargetLabel target={value} />
+ </TargetListItemAnchor>
+);
+
+type ZoomOpacityTargetChickletProps = {
+ item: ZoomOpacityTarget;
+ remove?: React.MouseEventHandler<SVGSVGElement>;
+ inputTheme?: string;
+ disabled?: boolean;
+};
+
+const ZoomOpacityTargetChicklet = ({
+ item,
+ remove,
+ inputTheme,
+ disabled
+}: ZoomOpacityTargetChickletProps) => (
+ <ChickletButton $inputTheme={inputTheme}>
+ <TargetChickletTag>
+ <ZoomOpacityTargetLabel target={item} />
+ </TargetChickletTag>
+ <Delete height="16px" onClick={disabled ? undefined : remove} />
+ </ChickletButton>
+);
+
const DEFAULT_ZOOM_OPACITY_CONFIG: InteractionConfig['zoomOpacity'] = {
id: 'zoomOpacity',
label: 'interactions.fadeOnZoom',
@@ -90,6 +183,7 @@ const DEFAULT_ZOOM_OPACITY_CONFIG: InteractionConfig['zoomOpacity'] = {
type ZoomOpacityConfigProps = {
layers: readonly Layer[];
+ annotations?: readonly Annotation[];
zoom?: number;
zoomOpacityConfig?: InteractionConfig['zoomOpacity'];
visStateActions: typeof VisStateActions;
@@ -109,6 +203,7 @@ function ZoomOpacityConfigFactory(
): ComponentType<ZoomOpacityConfigProps> {
const ZoomOpacityConfig: React.FC<ZoomOpacityConfigProps> = ({
layers,
+ annotations = [],
zoom,
zoomOpacityConfig,
visStateActions,
@@ -170,9 +265,9 @@ function ZoomOpacityConfigFactory(
[controllers, updateControllers]
);
- const onLayersChange = useCallback(
- (controllerId: string, selected: readonly Layer[] | null) => {
- const layerIds = (selected || []).map(layer => layer.id);
+ const onTargetsChange = useCallback(
+ (controllerId: string, selected: readonly ZoomOpacityTarget[] | null) => {
+ const layerIds = (selected || []).map(target => target.id);
updateControllers(
controllers.map(controller =>
controller.id === controllerId ? {...controller, layerIds} : controller
@@ -182,6 +277,23 @@ function ZoomOpacityConfigFactory(
[controllers, updateControllers]
);
+ const annotationTargets = useMemo<ZoomOpacityTarget[]>(
+ () =>
+ annotations.map((annotation, index) => {
+ const label = annotation.label?.trim() || `${index + 1}`;
+ return {
+ id: getZoomOpacityAnnotationTargetId(annotation.id),
+ annotationId: annotation.id,
+ label
+ };
+ }),
+ [annotations]
+ );
+ const targets = useMemo<ZoomOpacityTarget[]>(
+ () => [...layers, ...annotationTargets],
+ [annotationTargets, layers]
+ );
+
const onStopChange = useCallback(
(controllerId: string, key: keyof ZoomOpacityStops, value: number) => {
if (!Number.isFinite(value)) {
@@ -267,8 +379,8 @@ function ZoomOpacityConfigFactory(
</Button>
{controllers.map(controller => {
const taken = assignedElsewhere.get(controller.id) || new Set<string>();
- const options = layers.filter(layer => !taken.has(layer.id));
- const selected = layers.filter(layer => controller.layerIds.includes(layer.id));
+ const options = targets.filter(target => !taken.has(target.id));
+ const selected = targets.filter(target => controller.layerIds.includes(target.id));
return (
<ControllerCard
key={controller.id}
@@ -295,12 +407,14 @@ function ZoomOpacityConfigFactory(
options={options}
selectedItems={selected}
onChange={items =>
- onLayersChange(controller.id, (items as Layer[] | null) || [])
+ onTargetsChange(controller.id, (items as ZoomOpacityTarget[] | null) || [])
}
searchable={true}
multiSelect={true}
- getOptionValue={(layer: Layer) => layer.id}
- displayOption={(layer: Layer) => layer.config?.label || layer.id}
+ getOptionValue={(target: ZoomOpacityTarget) => target.id}
+ displayOption={getTargetLabel}
+ DropDownLineItemRenderComponent={ZoomOpacityTargetListItem}
+ CustomChickletComponent={ZoomOpacityTargetChicklet}
placeholder="placeholder.selectLayer"
inputTheme="secondary"
/>
diff --git a/src/components/src/types.ts b/src/components/src/types.ts
index c7356cee4..148ef788a 100644
--- a/src/components/src/types.ts
+++ b/src/components/src/types.ts
@@ -4,7 +4,14 @@
import React, {HTMLAttributes, PropsWithChildren} from 'react';
import {MapStyle} from '@kepler.gl/reducers';
import {Layer, LayerClassesType} from '@kepler.gl/layers';
-import {Filter, InteractionConfig, MapState, UiState, LayerOrder} from '@kepler.gl/types';
+import {
+ Annotation,
+ Filter,
+ InteractionConfig,
+ MapState,
+ UiState,
+ LayerOrder
+} from '@kepler.gl/types';
import {
MapStyleActions,
@@ -31,6 +38,7 @@ export type SidePanelProps = {
layerBlending: string;
overlayBlending?: string;
layers: Layer[];
+ annotations?: Annotation[];
layerClasses: LayerClassesType;
layerOrder: LayerOrder;
mapStyle: MapStyle;
diff --git a/src/localization/src/translations/en.ts b/src/localization/src/translations/en.ts
index 8a40c40ff..bc70b688f 100644
--- a/src/localization/src/translations/en.ts
+++ b/src/localization/src/translations/en.ts
@@ -1035,9 +1035,10 @@ ${'```'}
legendHideInvisible: 'Hide hidden layers in legend',
legendAllLayers: 'All Layers',
fadeOnZoom: 'Fade on zoom',
- fadeOnZoomHint: 'Fade layers as the map zooms. Configure a zoom range to show layers.',
+ fadeOnZoomHint:
+ 'Fade layers and annotations as the map zooms. Configure a zoom range to show them.',
fadeOnZoomAdd: 'Add controller',
- fadeOnZoomLayers: 'Layers',
+ fadeOnZoomLayers: 'Layers and annotations',
fadeOnZoomAppear: 'Appear',
fadeOnZoomFullStart: 'Full start',
fadeOnZoomFullEnd: 'Full end',
diff --git a/src/reducers/src/interaction-utils.ts b/src/reducers/src/interaction-utils.ts
index 2ea52be87..54adcb0bf 100644
--- a/src/reducers/src/interaction-utils.ts
+++ b/src/reducers/src/interaction-utils.ts
@@ -165,6 +165,13 @@ export function getTooltipDisplayValue({
export const ZOOM_OPACITY_RANGE: [number, number] = [0, 24];
+const ZOOM_OPACITY_ANNOTATION_PREFIX = '__kepler_annotation__:';
+
+/** Reserved fade-on-zoom target id for one map annotation. */
+export function getZoomOpacityAnnotationTargetId(annotationId: string): string {
+ return `${ZOOM_OPACITY_ANNOTATION_PREFIX}${annotationId}`;
+}
+
export const DEFAULT_ZOOM_OPACITY_STOPS: ZoomOpacityStops = {
appear: 1,
full: 3,
diff --git a/src/reducers/src/vis-state-updaters.ts b/src/reducers/src/vis-state-updaters.ts
index 97f1e26af..875d137c5 100644
--- a/src/reducers/src/vis-state-updaters.ts
+++ b/src/reducers/src/vis-state-updaters.ts
@@ -217,7 +217,11 @@ import {
sortDatasetByColumn
} from '@kepler.gl/table';
import {remapChartsForDataset} from './column-edit-reconcile';
-import {findFieldsToShow, removeLayerFromZoomOpacity} from './interaction-utils';
+import {
+ findFieldsToShow,
+ getZoomOpacityAnnotationTargetId,
+ removeLayerFromZoomOpacity
+} from './interaction-utils';
import {
calculateLayerData,
findDefaultLayer,
@@ -2997,6 +3001,10 @@ export const removeAnnotationUpdater = (
return {
...state,
annotations: state.annotations.filter(a => a.id !== id),
+ interactionConfig: removeLayerFromZoomOpacity(
+ state.interactionConfig,
+ getZoomOpacityAnnotationTargetId(id)
+ ),
selectedAnnotationId: state.selectedAnnotationId === id ? null : state.selectedAnnotationId,
isEditingAnnotationText:
state.selectedAnnotationId === id ? false : state.isEditingAnnotationText
diff --git a/src/types/reducers.d.ts b/src/types/reducers.d.ts
index f79c79e39..c1489f953 100644
--- a/src/types/reducers.d.ts
+++ b/src/types/reducers.d.ts
@@ -463,7 +463,7 @@ export type ZoomOpacityStops = {
/** Zoom where opacity returns to 0. */
gone: number;
};
-/** Layers that share one zoom envelope. */
+/** Layers and reserved map targets that share one zoom envelope. */
export type ZoomOpacityController = {
id: string;
layerIds: string[];
diff --git a/test/browser/components/side-panel/index.js b/test/browser/components/side-panel/index.js
index e1af675f0..4145dc47e 100644
--- a/test/browser/components/side-panel/index.js
+++ b/test/browser/components/side-panel/index.js
@@ -4,6 +4,7 @@
import './channel-by-value-selctor-test';
import './color-selector-test';
import './filter-manager-test';
+import './interaction-manager-test';
import './layer-configurator-test';
import './layer-manager-test';
import './layer-panel-header-test';
diff --git a/test/browser/components/side-panel/interaction-manager-test.js b/test/browser/components/side-panel/interaction-manager-test.js
index 184335366..1c293bb53 100644
--- a/test/browser/components/side-panel/interaction-manager-test.js
+++ b/test/browser/components/side-panel/interaction-manager-test.js
@@ -6,12 +6,17 @@ import test from 'tape';
import sinon from 'sinon';
import {InteractionManagerFactory, appInjector} from '@kepler.gl/components';
-import {defaultInteractionConfig} from '@kepler.gl/reducers';
+import {defaultInteractionConfig, getZoomOpacityAnnotationTargetId} from '@kepler.gl/reducers';
import {initApplicationConfig} from '@kepler.gl/utils';
import {IntlWrapper, mountWithTheme} from 'test/helpers/component-utils';
const InteractionManager = appInjector.get(InteractionManagerFactory);
+global.ResizeObserver = class ResizeObserver {
+ observe() {}
+ disconnect() {}
+};
+
const panelMetadata = {id: 'interaction', label: 'sidebar.panels.interaction'};
function expandLegend(wrapper) {
@@ -19,6 +24,108 @@ function expandLegend(wrapper) {
wrapper.update();
}
+function expandZoomOpacity(wrapper) {
+ wrapper.find('.interaction-zoom-opacity__header').hostNodes().at(0).simulate('click');
+ wrapper.update();
+}
+
+test('Components -> InteractionManager fade on zoom includes individual annotations', t => {
+ const interactionConfigChange = sinon.spy();
+ const layer = {id: 'layer-1', config: {label: 'Quakes'}};
+ const annotations = [
+ {id: 'annotation-1', label: 'First annotation with a name long enough to be clipped'},
+ {id: 'annotation-2', label: 'Second note'}
+ ];
+ const firstTargetId = getZoomOpacityAnnotationTargetId(annotations[0].id);
+ const secondTargetId = getZoomOpacityAnnotationTargetId(annotations[1].id);
+ const wrapper = mountWithTheme(
+ <IntlWrapper>
+ <InteractionManager
+ interactionConfig={{
+ zoomOpacity: {
+ id: 'zoomOpacity',
+ label: 'interactions.fadeOnZoom',
+ enabled: true,
+ config: {
+ controllers: [
+ {
+ id: 'controller-1',
+ layerIds: [firstTargetId],
+ stops: {appear: 1, full: 3, fade: 8, gone: 12}
+ }
+ ]
+ }
+ }
+ }}
+ datasets={{}}
+ panelMetadata={panelMetadata}
+ layers={[layer]}
+ annotations={annotations}
+ mapState={{zoom: 4}}
+ visStateActions={{
+ interactionConfigChange,
+ setColumnDisplayFormat: () => {}
+ }}
+ />
+ </IntlWrapper>
+ );
+
+ expandZoomOpacity(wrapper);
+
+ const itemSelectors = wrapper.find('ItemSelector');
+ let selector = itemSelectors.at(0);
+ for (let index = 0; index < itemSelectors.length; index++) {
+ const candidate = itemSelectors.at(index);
+ if (Array.isArray(candidate.prop('options'))) {
+ selector = candidate;
+ break;
+ }
+ }
+ const options = selector.prop('options');
+ const firstAnnotation = options.find(option => option.id === firstTargetId);
+ const secondAnnotation = options.find(option => option.id === secondTargetId);
+ t.ok(firstAnnotation, 'lists the first annotation with the layer targets');
+ t.ok(secondAnnotation, 'lists the second annotation with the layer targets');
+ t.equal(
+ firstAnnotation.label,
+ annotations[0].label,
+ 'keeps the first annotation name available for search'
+ );
+ t.equal(secondAnnotation.label, 'Second note', 'uses the second annotation name');
+ t.ok(
+ wrapper.find('svg.zoom-opacity-target__annotation-icon').hostNodes().exists(),
+ 'distinguishes the selected annotation with the annotation SVG icon'
+ );
+ t.equal(
+ wrapper.find('.zoom-opacity-target__name').text(),
+ annotations[0].label,
+ 'renders the selected annotation name in the clipped label'
+ );
+
+ const TargetListItem = selector.prop('DropDownLineItemRenderComponent');
+ const annotationRow = mountWithTheme(
+ <TargetListItem
+ value={firstAnnotation}
+ displayOption={option => option.label}
+ disabled={false}
+ light={false}
+ />
+ );
+ const annotationRowStyle = window.getComputedStyle(
+ annotationRow.find('.list__item__anchor').hostNodes().getDOMNode()
+ );
+ t.equal(annotationRowStyle.display, 'flex', 'keeps the annotation option on one row');
+ t.equal(annotationRowStyle.whiteSpace, 'nowrap', 'prevents the annotation row from wrapping');
+
+ selector.prop('onChange')([layer, firstAnnotation, secondAnnotation]);
+ t.deepEqual(
+ interactionConfigChange.args[0][0].config.controllers[0].layerIds,
+ ['layer-1', firstTargetId, secondTargetId],
+ 'stores individual annotations alongside selected layer ids'
+ );
+ t.end();
+});
+
test('Components -> InteractionManager legend section', t => {
const layerConfigChange = sinon.spy();
const updateLayerGroup = sinon.spy();
diff --git a/test/node/reducers/annotation-updater-test.js b/test/node/reducers/annotation-updater-test.js
index 71d666270..0a07ea946 100644
--- a/test/node/reducers/annotation-updater-test.js
+++ b/test/node/reducers/annotation-updater-test.js
@@ -2,7 +2,11 @@
// Copyright contributors to the kepler.gl project
import test from 'tape';
-import {visStateReducer as reducer, INITIAL_VIS_STATE} from '@kepler.gl/reducers';
+import {
+ getZoomOpacityAnnotationTargetId,
+ visStateReducer as reducer,
+ INITIAL_VIS_STATE
+} from '@kepler.gl/reducers';
import {VisStateActions} from '@kepler.gl/actions';
import {AnnotationKind} from '@kepler.gl/constants';
@@ -108,11 +112,35 @@ test('#visStateReducer -> ADD_ANNOTATION derives placement from angle', t => {
test('#visStateReducer -> REMOVE_ANNOTATION', t => {
let state = reducer(initialState, VisStateActions.addAnnotation({anchorPoint: [0, 0]}));
const id = state.annotations[0].id;
+ state = {
+ ...state,
+ interactionConfig: {
+ ...state.interactionConfig,
+ zoomOpacity: {
+ ...state.interactionConfig.zoomOpacity,
+ enabled: true,
+ config: {
+ controllers: [
+ {
+ id: 'controller-1',
+ layerIds: [getZoomOpacityAnnotationTargetId(id)],
+ stops: {appear: 1, full: 3, fade: 8, gone: 12}
+ }
+ ]
+ }
+ }
+ }
+ };
state = reducer(state, VisStateActions.removeAnnotation(id));
t.equal(state.annotations.length, 0, 'should remove annotation');
t.equal(state.selectedAnnotationId, null, 'should deselect removed annotation');
+ t.deepEqual(
+ state.interactionConfig.zoomOpacity.config.controllers[0].layerIds,
+ [],
+ 'should remove the annotation from fade-on-zoom controllers'
+ );
t.end();
});
diff --git a/test/node/reducers/zoom-opacity-test.js b/test/node/reducers/zoom-opacity-test.js
index 0b805ac07..5753dd14b 100644
--- a/test/node/reducers/zoom-opacity-test.js
+++ b/test/node/reducers/zoom-opacity-test.js
@@ -8,6 +8,7 @@ import {VisStateActions} from '@kepler.gl/actions';
import {
combineZoomOpacityControllers,
getLayerZoomOpacityFactor,
+ getZoomOpacityAnnotationTargetId,
INITIAL_VIS_STATE,
mergeInteractions,
renderDeckGlLayer,
@@ -75,6 +76,32 @@ test('interactionUtil -> getLayerZoomOpacityFactor', t => {
1,
'missing zoom is unchanged'
);
+ const firstAnnotationTarget = getZoomOpacityAnnotationTargetId('annotation-1');
+ const secondAnnotationTarget = getZoomOpacityAnnotationTargetId('annotation-2');
+ const annotationConfig = {
+ zoomOpacity: {
+ ...interactionConfig.zoomOpacity,
+ config: {
+ controllers: [
+ {
+ id: 'c1',
+ layerIds: [firstAnnotationTarget],
+ stops: {appear: 2, full: 4, fade: 8, gone: 10}
+ }
+ ]
+ }
+ }
+ };
+ t.equal(
+ getLayerZoomOpacityFactor(firstAnnotationTarget, 3, annotationConfig),
+ 0.5,
+ 'an assigned annotation target uses the envelope'
+ );
+ t.equal(
+ getLayerZoomOpacityFactor(secondAnnotationTarget, 3, annotationConfig),
+ 1,
+ 'an unassigned annotation target stays unchanged'
+ );
t.end();
});