Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
feat: bitmap layer (#3472)
Igor Dykhtacb06210628d5
diff --git a/src/components/src/modals/export-data-modal.tsx b/src/components/src/modals/export-data-modal.tsxindex d54b4f75f..b23820c02 100644--- a/src/components/src/modals/export-data-modal.tsx+++ b/src/components/src/modals/export-data-modal.tsx@@ -96,7 +96,8 @@ const ExportDataModalFactory = () => {(datasets[datasetId].type === DatasetType.VECTOR_TILE ||datasets[datasetId].type === DatasetType.RASTER_TILE ||datasets[datasetId].type === DatasetType.WMS_TILE ||- datasets[datasetId].type === DatasetType.TILE_3D) &&+ datasets[datasetId].type === DatasetType.TILE_3D ||+ datasets[datasetId].type === DatasetType.BITMAP) &&(selectedDataset === datasetId || exportAllDatasets));});diff --git a/src/components/src/modals/tilesets-modals/load-tileset.tsx b/src/components/src/modals/tilesets-modals/load-tileset.tsxindex a9b210c5d..4744db5a9 100644--- a/src/components/src/modals/tilesets-modals/load-tileset.tsx+++ b/src/components/src/modals/tilesets-modals/load-tileset.tsx@@ -7,7 +7,13 @@ import JSONPretty from 'react-json-pretty';import {AutoSizer} from 'react-virtualized';import styled from 'styled-components';-import {VectorTileIcon, RasterTileIcon, WMSLayerIcon, Tile3DLayerIcon} from '@kepler.gl/layers';+import {+ VectorTileIcon,+ RasterTileIcon,+ WMSLayerIcon,+ Tile3DLayerIcon,+ BitmapLayerIcon+} from '@kepler.gl/layers';import {getError, getApplicationConfig} from '@kepler.gl/utils';import {MetaResponse} from './common';@@ -18,6 +24,7 @@ import TilesetRasterForm from './tileset-raster-form';import TilesetWMSForm from './tileset-wms-form';import TilesetTile3DForm from './tileset-tile3d-form';+import TilesetBitmapForm from './tileset-bitmap-form';const WIDTH_ICON = '70px';@@ -34,7 +41,7 @@ const Container = styled.div`const TilesetTypeContainer = styled.div`display: grid;- grid-template-columns: repeat(5, ${WIDTH_ICON});+ grid-template-columns: repeat(6, ${WIDTH_ICON});column-gap: 10px;margin-bottom: 20px;`;@@ -45,6 +52,22 @@ const MetaContainer = styled.div`background-color: ${({theme}) => theme.editorBackground};`;+const BitmapPreviewContainer = styled.div`+ display: flex;+ align-items: center;+ justify-content: center;+ width: 100%;+ height: 100%;+ padding: 16px;++ img {+ max-width: 100%;+ max-height: 360px;+ border-radius: 4px;+ object-fit: contain;+ }+`;+export interface MetaInnerContainerProps {width: number;height: number;@@ -103,6 +126,12 @@ const TILE_TYPES = [label: '3D Tile',Icon: Tile3DLayerIcon,Component: TilesetTile3DForm+ },+ {+ id: 'bitmap',+ label: 'Bitmap',+ Icon: BitmapLayerIcon,+ Component: TilesetBitmapForm}];@@ -130,6 +159,7 @@ function LoadTilesetTabFactory() {// temp patch to hide raster tile layer while in developmentconst enableRasterTileLayer = getApplicationConfig().enableRasterTileLayer;const enableWMSLayer = getApplicationConfig().enableWMSLayer;+ const enableBitmapLayer = getApplicationConfig().enableBitmapLayer;// Filter tile types based on application configconst tileTypes = useMemo(() => {@@ -140,10 +170,13 @@ function LoadTilesetTabFactory() {if (tileType.id === 'wms') {return enableWMSLayer;}+ if (tileType.id === 'bitmap') {+ return enableBitmapLayer;+ }return true; // Include all other types by default});return types;- }, [enableRasterTileLayer, enableWMSLayer]);+ }, [enableRasterTileLayer, enableWMSLayer, enableBitmapLayer]);const CurrentForm = tileTypes[typeIndex].Component;@@ -167,7 +200,11 @@ function LoadTilesetTabFactory() {</div></div><MetaContainer>- {data && (+ {data && 'imagePreviewUrl' in data ? (+ <BitmapPreviewContainer>+ <img src={(data as any).imagePreviewUrl} alt="Bitmap preview" />+ </BitmapPreviewContainer>+ ) : data ? (<AutoSizer>{({height, width}) => (<MetaInnerContainer height={height} width={width}>@@ -175,7 +212,7 @@ function LoadTilesetTabFactory() {</MetaInnerContainer>)}</AutoSizer>- )}+ ) : null}</MetaContainer></Container><LoadDataFooterdiff --git a/src/components/src/modals/tilesets-modals/tileset-bitmap-form.tsx b/src/components/src/modals/tilesets-modals/tileset-bitmap-form.tsxnew file mode 100644index 000000000..12c35b9af--- /dev/null+++ b/src/components/src/modals/tilesets-modals/tileset-bitmap-form.tsx@@ -0,0 +1,359 @@+// SPDX-License-Identifier: MIT+// Copyright contributors to the kepler.gl project++import React, {useCallback, useEffect, useRef, useState} from 'react';+import styled from 'styled-components';++import {validateUrl} from '@kepler.gl/common-utils';+import {DatasetType, BitmapDatasetMetadata, BitmapBounds} from '@kepler.gl/constants';++import {MetaResponse, DatasetCreationAttributes} from './common';+import {InputLight} from '../../common';++const TilesetInputContainer = styled.div`+ display: grid;+ grid-template-rows: repeat(auto, auto);+ row-gap: 12px;+ font-size: 12px;+`;++const BoundsGrid = styled.div`+ display: grid;+ grid-template-columns: 1fr 1fr;+ gap: 8px;+`;++const BoundsLabel = styled.label`+ font-size: 11px;+ color: ${props => props.theme.AZURE200};+ margin-bottom: 4px;+ display: block;+`;++const DropZone = styled.div<{isDragging: boolean}>`+ border: 2px dashed ${props => (props.isDragging ? props.theme.AZURE200 : props.theme.AZURE400)};+ border-radius: 4px;+ padding: 0 10px;+ height: 34px;+ display: flex;+ align-items: center;+ justify-content: center;+ white-space: nowrap;+ cursor: pointer;+ color: ${props => props.theme.AZURE200};+ font-size: 11px;+ transition: border-color 0.2s;++ &:hover {+ border-color: ${props => props.theme.AZURE200};+ }+`;++const ImageSourceRow = styled.div`+ display: grid;+ grid-template-columns: 1fr auto;+ gap: 8px;+ align-items: end;+`;++const DropZoneWrapper = styled.div`+ position: relative;+`;++const ClearButton = styled.button`+ position: absolute;+ top: -6px;+ right: -6px;+ background: #ffffff;+ border: 2px solid ${props => props.theme.AZURE400};+ border-radius: 50%;+ color: ${props => props.theme.AZURE200};+ cursor: pointer;+ font-size: 10px;+ line-height: 1;+ width: 18px;+ height: 18px;+ display: flex;+ align-items: center;+ justify-content: center;+ padding: 0;+ z-index: 1;++ &:hover {+ border-color: ${props => props.theme.AZURE200};+ }+`;++type BitmapFormProps = {+ setResponse: (response: MetaResponse) => void;+};++export function getDatasetAttributesFromBitmap({+ name,+ imageUrl,+ bounds,+ isDataUri+}: {+ name: string;+ imageUrl: string;+ bounds: BitmapBounds;+ isDataUri?: boolean;+}): DatasetCreationAttributes {+ return {+ name,+ type: DatasetType.BITMAP,+ metadata: {+ imageUrl,+ bounds,+ isDataUri+ } as BitmapDatasetMetadata+ };+}++const ACCEPTED_IMAGE_TYPES = ['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/tiff'];++const TilesetBitmapForm: React.FC<BitmapFormProps> = ({setResponse}) => {+ const [layerName, setLayerName] = useState<string>('');+ const [imageUrl, setImageUrl] = useState<string>('');+ const [imageDataUri, setImageDataUri] = useState<string>('');+ const [west, setWest] = useState<string>('-122.52');+ const [south, setSouth] = useState<string>('37.70');+ const [east, setEast] = useState<string>('-122.35');+ const [north, setNorth] = useState<string>('37.82');+ const [isDragging, setIsDragging] = useState(false);+ const [fileError, setFileError] = useState<string | null>(null);+ const fileInputRef = useRef<HTMLInputElement>(null);++ const effectiveImageUrl = imageDataUri || imageUrl;+ const isDataUri = Boolean(imageDataUri);++ const onLayerNameChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {+ setLayerName(event.target.value);+ }, []);++ const onImageUrlChange = useCallback(+ (event: React.ChangeEvent<HTMLInputElement>) => {+ const newUrl = event.target.value;+ setImageUrl(newUrl);+ setImageDataUri('');+ setFileError(null);+ if (!layerName && validateUrl(newUrl)) {+ setLayerName('Bitmap Layer');+ }+ },+ [layerName]+ );++ const handleFile = useCallback(+ (file: File) => {+ if (!ACCEPTED_IMAGE_TYPES.includes(file.type)) {+ setFileError('Unsupported image format. Use PNG, JPEG, GIF, WebP, or TIFF.');+ return;+ }++ const MAX_SIZE = 10 * 1024 * 1024; // 10MB+ if (file.size > MAX_SIZE) {+ setFileError('Image is too large (max 10MB).');+ return;+ }++ setFileError(null);+ const reader = new FileReader();+ reader.onload = () => {+ const dataUri = reader.result as string;+ setImageDataUri(dataUri);+ setImageUrl('');+ if (!layerName) {+ setLayerName(file.name.replace(/\.[^.]+$/, ''));+ }+ };+ reader.onerror = () => {+ setFileError('Failed to read file.');+ };+ reader.readAsDataURL(file);+ },+ [layerName]+ );++ const onDrop = useCallback(+ (event: React.DragEvent) => {+ event.preventDefault();+ setIsDragging(false);+ const files = event.dataTransfer?.files;+ if (files && files.length > 0) {+ handleFile(files[0]);+ }+ },+ [handleFile]+ );++ const onDragOver = useCallback((event: React.DragEvent) => {+ event.preventDefault();+ setIsDragging(true);+ }, []);++ const onDragLeave = useCallback(() => {+ setIsDragging(false);+ }, []);++ const onFileInputChange = useCallback(+ (event: React.ChangeEvent<HTMLInputElement>) => {+ const files = event.target.files;+ if (files && files.length > 0) {+ handleFile(files[0]);+ }+ },+ [handleFile]+ );++ const onDropZoneClick = useCallback(() => {+ fileInputRef.current?.click();+ }, []);++ const onClearImage = useCallback(() => {+ setImageDataUri('');+ setImageUrl('');+ setFileError(null);+ }, []);++ // Update response whenever form state changes+ useEffect(() => {+ if (fileError) {+ setResponse({+ metadata: null,+ dataset: null,+ loading: false,+ error: new Error(fileError)+ });+ return;+ }++ const boundsValid =+ west !== '' &&+ south !== '' &&+ east !== '' &&+ north !== '' &&+ !isNaN(Number(west)) &&+ !isNaN(Number(south)) &&+ !isNaN(Number(east)) &&+ !isNaN(Number(north));++ if (layerName && effectiveImageUrl && boundsValid) {+ const bounds: BitmapBounds = [Number(west), Number(south), Number(east), Number(north)];+ const dataset = getDatasetAttributesFromBitmap({+ name: layerName,+ imageUrl: effectiveImageUrl,+ bounds,+ isDataUri+ });+ setResponse({+ metadata: {imagePreviewUrl: effectiveImageUrl},+ dataset,+ loading: false,+ error: null+ });+ } else {+ setResponse({+ metadata: effectiveImageUrl ? {imagePreviewUrl: effectiveImageUrl} : null,+ dataset: null,+ loading: false,+ error: null+ });+ }+ }, [setResponse, layerName, effectiveImageUrl, west, south, east, north, isDataUri, fileError]);++ return (+ <TilesetInputContainer>+ <div>+ <label htmlFor="bitmap-layer-name">Name</label>+ <InputLight+ id="bitmap-layer-name"+ placeholder="Name your bitmap layer"+ value={layerName}+ onChange={onLayerNameChange}+ />+ </div>++ <div>+ <label htmlFor="bitmap-url">Image source</label>+ <ImageSourceRow>+ <InputLight+ id="bitmap-url"+ placeholder="Image URL"+ value={imageUrl}+ onChange={onImageUrlChange}+ disabled={Boolean(imageDataUri)}+ />+ <DropZoneWrapper>+ {(imageDataUri || imageUrl) && (+ <ClearButton onClick={onClearImage} title="Clear image">✕</ClearButton>+ )}+ <DropZone+ isDragging={isDragging}+ onDrop={onDrop}+ onDragOver={onDragOver}+ onDragLeave={onDragLeave}+ onClick={onDropZoneClick}+ >+ {imageDataUri ? '✓ Local' : 'Drop / Select'}+ </DropZone>+ </DropZoneWrapper>+ </ImageSourceRow>+ <input+ ref={fileInputRef}+ type="file"+ accept={ACCEPTED_IMAGE_TYPES.join(',')}+ style={{display: 'none'}}+ onChange={onFileInputChange}+ />+ {fileError && (+ <div style={{color: '#ff5a5a', fontSize: '11px', marginTop: '4px'}}>{fileError}</div>+ )}+ </div>++ <div>+ <label>Bounds</label>+ <BoundsGrid>+ <div>+ <BoundsLabel htmlFor="bitmap-west">West (min lng)</BoundsLabel>+ <InputLight+ id="bitmap-west"+ placeholder="-180"+ value={west}+ onChange={(e: React.ChangeEvent<HTMLInputElement>) => setWest(e.target.value)}+ />+ </div>+ <div>+ <BoundsLabel htmlFor="bitmap-east">East (max lng)</BoundsLabel>+ <InputLight+ id="bitmap-east"+ placeholder="180"+ value={east}+ onChange={(e: React.ChangeEvent<HTMLInputElement>) => setEast(e.target.value)}+ />+ </div>+ <div>+ <BoundsLabel htmlFor="bitmap-south">South (min lat)</BoundsLabel>+ <InputLight+ id="bitmap-south"+ placeholder="-90"+ value={south}+ onChange={(e: React.ChangeEvent<HTMLInputElement>) => setSouth(e.target.value)}+ />+ </div>+ <div>+ <BoundsLabel htmlFor="bitmap-north">North (max lat)</BoundsLabel>+ <InputLight+ id="bitmap-north"+ placeholder="90"+ value={north}+ onChange={(e: React.ChangeEvent<HTMLInputElement>) => setNorth(e.target.value)}+ />+ </div>+ </BoundsGrid>+ </div>+ </TilesetInputContainer>+ );+};++export default TilesetBitmapForm;diff --git a/src/components/src/side-panel/common/dataset-info.tsx b/src/components/src/side-panel/common/dataset-info.tsxindex eacac63ea..1a8d27f98 100644--- a/src/components/src/side-panel/common/dataset-info.tsx+++ b/src/components/src/side-panel/common/dataset-info.tsx@@ -39,6 +39,8 @@ export default function DatasetInfoFactory() {? 'datasetInfo.wmsTile': dataset.type === DatasetType.TILE_3D? 'datasetInfo.tile3d'+ : dataset.type === DatasetType.BITMAP+ ? 'datasetInfo.bitmap': 'datasetInfo.rowCount'}values={{rowCount: numFormat(dataset.dataContainer.numRows())}}diff --git a/src/components/src/side-panel/layer-panel/dataset-layer-section.tsx b/src/components/src/side-panel/layer-panel/dataset-layer-section.tsxindex 1d5039d85..f73dfabdc 100644--- a/src/components/src/side-panel/layer-panel/dataset-layer-section.tsx+++ b/src/components/src/side-panel/layer-panel/dataset-layer-section.tsx@@ -62,6 +62,7 @@ function DatasetLayerSectionFactory(const enableRasterTileLayer = getApplicationConfig().enableRasterTileLayer;const enableWMSLayer = getApplicationConfig().enableWMSLayer;const enableFlowLayer = getApplicationConfig().enableFlowLayer;+ const enableBitmapLayer = getApplicationConfig().enableBitmapLayer;const filteredLayerClasses = useMemo(() => {let filteredClasses = layerClasses;@@ -77,8 +78,12 @@ function DatasetLayerSectionFactory(const {flow: _flow, ...rest} = filteredClasses;filteredClasses = rest as LayerClassesType;}+ if (!enableBitmapLayer) {+ const {bitmap: _bitmap, ...rest} = filteredClasses;+ filteredClasses = rest as LayerClassesType;+ }return filteredClasses as LayerClassesType;- }, [enableRasterTileLayer, enableWMSLayer, enableFlowLayer, layerClasses]);+ }, [enableRasterTileLayer, enableWMSLayer, enableFlowLayer, enableBitmapLayer, layerClasses]);return (<DatasetLayerSectionWrapper>diff --git a/src/components/src/side-panel/layer-panel/layer-configurator.tsx b/src/components/src/side-panel/layer-panel/layer-configurator.tsxindex 28962141c..45f0526f6 100644--- a/src/components/src/side-panel/layer-panel/layer-configurator.tsx+++ b/src/components/src/side-panel/layer-panel/layer-configurator.tsx@@ -3,11 +3,11 @@/* eslint-disable complexity */import {FormattedMessage} from '@kepler.gl/localization';-import React, {Component, Fragment} from 'react';+import React, {Component, Fragment, useCallback, useRef, useState} from 'react';import styled from 'styled-components';import ItemSelector from '../../common/item-selector/item-selector';-import {Input, PanelLabel, PanelLabelWrapper, SidePanelSection} from '../../common/styled-components';+import {Input, InputLight, PanelLabel, PanelLabelWrapper, SidePanelSection} from '../../common/styled-components';import SourceDataSelectorFactory from '../common/source-data-selector';import AggrScaleSelectorFactory from './aggr-scale-selector';@@ -36,7 +36,8 @@ import {ActionHandler, toggleModal} from '@kepler.gl/actions';import {AGGREGATION_TYPE_OPTIONS,LAYER_TYPES,- CUSTOM_SCENEGRAPH_MODEL_ID+ CUSTOM_SCENEGRAPH_MODEL_ID,+ BitmapDatasetMetadata} from '@kepler.gl/constants';import {AggregationLayer, Layer, LayerBaseConfig, VisualChannel, COLUMN_MODE_GEOJSON} from '@kepler.gl/layers';@@ -99,8 +100,198 @@ const StyledLayerVisualConfigurator = styled.div.attrs({className: 'layer-panel__config__visualC-config'})`margin-top: 12px;++ .bitmap-bounds-sliders .kg-range-slider__input {+ width: 80px;+ }`;+const BitmapDropZone = styled.div<{$isDragging: boolean}>`+ border: 2px dashed ${props => (props.$isDragging ? props.theme.activeColor : props.theme.borderColor)};+ border-radius: 4px;+ padding: 12px;+ text-align: center;+ cursor: pointer;+ color: ${props => props.theme.textColorHl};+ font-size: 11px;+ transition: border-color 0.2s;+ margin-top: 8px;++ &:hover {+ border-color: ${props => props.theme.activeColor};+ }+`;++const BitmapDropZoneWrapper = styled.div`+ position: relative;+`;++const BitmapClearButton = styled.button`+ position: absolute;+ top: 2px;+ right: 2px;+ background: ${props => props.theme.panelBackground};+ border: 2px solid ${props => props.theme.borderColor};+ border-radius: 50%;+ color: ${props => props.theme.textColorHl};+ cursor: pointer;+ font-size: 10px;+ line-height: 1;+ width: 18px;+ height: 18px;+ display: flex;+ align-items: center;+ justify-content: center;+ padding: 0;+ z-index: 1;++ &:hover {+ border-color: ${props => props.theme.activeColor};+ }+`;++const ACCEPTED_IMAGE_TYPES = ['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/tiff'];+const MAX_IMAGE_SIZE = 10 * 1024 * 1024;++type BitmapImageSourceProps = {+ dataset: any;+ onChange: (v: Record<string, any>) => void;+};++const BitmapImageSourceSection: React.FC<BitmapImageSourceProps> = ({dataset, onChange}) => {+ const metadata = (dataset?.metadata || {}) as BitmapDatasetMetadata;+ const [url, setUrl] = useState(metadata.isDataUri ? '' : metadata.imageUrl || '');+ const [isDragging, setIsDragging] = useState(false);+ const [error, setError] = useState<string | null>(null);+ const fileInputRef = useRef<HTMLInputElement>(null);++ const updateImage = useCallback(+ (imageUrl: string, isDataUri: boolean) => {+ if (dataset?.metadata) {+ (dataset.metadata as BitmapDatasetMetadata).imageUrl = imageUrl;+ (dataset.metadata as BitmapDatasetMetadata).isDataUri = isDataUri;+ }+ // Force a layer re-render by bumping a timestamp in visConfig+ onChange({_imageTs: Date.now()});+ },+ [dataset, onChange]+ );++ const onUrlChange = useCallback(+ (e: React.ChangeEvent<HTMLInputElement>) => {+ setUrl(e.target.value);+ setError(null);+ },+ []+ );++ const onUrlBlur = useCallback(() => {+ if (url) {+ updateImage(url, false);+ }+ }, [url, updateImage]);++ const handleFile = useCallback(+ (file: File) => {+ if (!ACCEPTED_IMAGE_TYPES.includes(file.type)) {+ setError('Unsupported format. Use PNG, JPEG, GIF, WebP, or TIFF.');+ return;+ }+ if (file.size > MAX_IMAGE_SIZE) {+ setError('Image too large (max 10MB).');+ return;+ }+ setError(null);+ const reader = new FileReader();+ reader.onload = () => {+ const dataUri = reader.result as string;+ setUrl('');+ updateImage(dataUri, true);+ };+ reader.onerror = () => setError('Failed to read file.');+ reader.readAsDataURL(file);+ },+ [updateImage]+ );++ const onDrop = useCallback(+ (e: React.DragEvent) => {+ e.preventDefault();+ setIsDragging(false);+ const files = e.dataTransfer?.files;+ if (files && files.length > 0) handleFile(files[0]);+ },+ [handleFile]+ );++ const onDragOver = useCallback((e: React.DragEvent) => {+ e.preventDefault();+ setIsDragging(true);+ }, []);++ const onDragLeave = useCallback(() => setIsDragging(false), []);++ const onDropZoneClick = useCallback(() => fileInputRef.current?.click(), []);++ const onFileInputChange = useCallback(+ (e: React.ChangeEvent<HTMLInputElement>) => {+ const files = e.target.files;+ if (files && files.length > 0) handleFile(files[0]);+ },+ [handleFile]+ );++ const isCurrentDataUri = metadata.isDataUri;++ const onClearLocal = useCallback(() => {+ if (dataset?.metadata) {+ (dataset.metadata as BitmapDatasetMetadata).imageUrl = '';+ (dataset.metadata as BitmapDatasetMetadata).isDataUri = false;+ }+ setUrl('');+ setError(null);+ onChange({_imageTs: Date.now()});+ }, [dataset, onChange]);++ return (+ <div>+ <PanelLabel>+ <FormattedMessage id="layerVisConfigs.imageUrl" />+ </PanelLabel>+ <InputLight+ type="text"+ placeholder="Image URL (PNG, JPEG, etc.)"+ value={url}+ onChange={onUrlChange}+ onBlur={onUrlBlur}+ disabled={isCurrentDataUri}+ />+ <BitmapDropZoneWrapper>+ {isCurrentDataUri && (+ <BitmapClearButton onClick={onClearLocal} title="Clear image">✕</BitmapClearButton>+ )}+ <BitmapDropZone+ $isDragging={isDragging}+ onDrop={onDrop}+ onDragOver={onDragOver}+ onDragLeave={onDragLeave}+ onClick={onDropZoneClick}+ >+ {isCurrentDataUri ? 'Local image loaded. Drop another to replace.' : 'Drop image here or click to select'}+ </BitmapDropZone>+ </BitmapDropZoneWrapper>+ <input+ ref={fileInputRef}+ type="file"+ accept={ACCEPTED_IMAGE_TYPES.join(',')}+ style={{display: 'none'}}+ onChange={onFileInputChange}+ />+ {error && <div style={{color: '#ff5a5a', fontSize: '11px', marginTop: '4px'}}>{error}</div>}+ </div>+ );+};+export const getLayerFields = (datasets: Datasets, layer: Layer) =>datasets[layer.config?.dataId || ''] ? datasets[layer.config.dataId].fields : [];@@ -1239,6 +1430,32 @@ export default function LayerConfiguratorFactory();}+ _renderBitmapLayerConfig({layer, dataset, visConfiguratorProps}) {+ return (+ <StyledLayerVisualConfigurator>+ <LayerConfigGroup label={'layer.imageSource'} collapsible>+ <BitmapImageSourceSection+ dataset={dataset}+ onChange={visConfiguratorProps.onChange}+ />+ </LayerConfigGroup>+ <LayerConfigGroup label={'layer.appearance'}>+ <VisConfigSlider {...layer.visConfigSettings.opacity} {...visConfiguratorProps} />+ </LayerConfigGroup>+ <LayerConfigGroup label={'layer.bounds'} collapsible>+ <VisConfigSwitch {...layer.visConfigSettings.editBounds} {...visConfiguratorProps} />+ <div className="bitmap-bounds-sliders">+ <VisConfigSlider {...layer.visConfigSettings.boundsWest} {...visConfiguratorProps} />+ <VisConfigSlider {...layer.visConfigSettings.boundsEast} {...visConfiguratorProps} />+ <VisConfigSlider {...layer.visConfigSettings.boundsSouth} {...visConfiguratorProps} />+ <VisConfigSlider {...layer.visConfigSettings.boundsNorth} {...visConfiguratorProps} />+ </div>+ <VisConfigSwitch {...layer.visConfigSettings.showBounds} {...visConfiguratorProps} />+ </LayerConfigGroup>+ </StyledLayerVisualConfigurator>+ );+ }+_renderWmsLayerConfig({layer,visConfiguratorProps,diff --git a/src/constants/src/dataset.ts b/src/constants/src/dataset.tsindex ed57210ac..60533a086 100644--- a/src/constants/src/dataset.ts+++ b/src/constants/src/dataset.ts@@ -6,7 +6,8 @@ export enum DatasetType {VECTOR_TILE = 'vector-tile',RASTER_TILE = 'raster-tile',WMS_TILE = 'wms-tile',- TILE_3D = 'tile-3d'+ TILE_3D = 'tile-3d',+ BITMAP = 'bitmap'}export enum RemoteTileFormat {@@ -123,3 +124,13 @@ export type Tile3DDatasetMetadata = {tile3dAccessToken?: string;tile3dProvider?: string;};++export type BitmapBounds =+ | [number, number, number, number]+ | [[number, number], [number, number], [number, number], [number, number]];++export type BitmapDatasetMetadata = {+ imageUrl: string;+ bounds: BitmapBounds;+ isDataUri?: boolean;+};diff --git a/src/constants/src/layers.ts b/src/constants/src/layers.tsindex da4ca6832..b398d02fb 100644--- a/src/constants/src/layers.ts+++ b/src/constants/src/layers.ts@@ -611,7 +611,8 @@ export const LAYER_TYPES = keyMirror({vectorTile: null,rasterTile: null,wms: null,- tile3d: null+ tile3d: null,+ bitmap: null});export const EDITOR_AVAILABLE_LAYERS: string[] = [diff --git a/src/layers/src/bitmap-layer/bitmap-layer-icon.tsx b/src/layers/src/bitmap-layer/bitmap-layer-icon.tsxnew file mode 100644index 000000000..e651e11f1--- /dev/null+++ b/src/layers/src/bitmap-layer/bitmap-layer-icon.tsx@@ -0,0 +1,28 @@+// SPDX-License-Identifier: MIT+// Copyright contributors to the kepler.gl project++import React from 'react';+import {Base, BaseProps} from '../base';++const BitmapLayerIcon: React.FC<Partial<BaseProps>> = ({+ height = '16px',+ predefinedClassName = 'bitmap-layer-icon',+ totalColor = 2,+ ...props+}) => (+ <Base+ height={height}+ predefinedClassName={predefinedClassName}+ totalColor={totalColor}+ {...props}+ >+ <g transform="translate(8, 10)">+ <rect x="0" y="0" width="48" height="36" rx="2" fill="currentColor" opacity="0.2" />+ <rect x="2" y="2" width="44" height="32" rx="1" fill="currentColor" opacity="0.5" />+ <path d="M6 28L18 18L26 24L38 12L42 16V30H6V28Z" fill="currentColor" opacity="0.8" />+ <circle cx="14" cy="12" r="4" fill="currentColor" opacity="0.8" />+ </g>+ </Base>+);++export default BitmapLayerIcon;diff --git a/src/layers/src/bitmap-layer/bitmap-layer.ts b/src/layers/src/bitmap-layer/bitmap-layer.tsnew file mode 100644index 000000000..126f413ec--- /dev/null+++ b/src/layers/src/bitmap-layer/bitmap-layer.ts@@ -0,0 +1,400 @@+// SPDX-License-Identifier: MIT+// Copyright contributors to the kepler.gl project++import {BitmapLayer as DeckBitmapLayer, PathLayer} from '@deck.gl/layers';+import {+ EditableGeoJsonLayer,+ ModifyMode,+ TranslateMode,+ CompositeMode,+ GeoJsonEditMode+} from '@deck.gl-community/editable-layers';++import Layer from '../base-layer';+import BitmapLayerIcon from './bitmap-layer-icon';+import {FindDefaultLayerPropsReturnValue} from '../layer-utils';+import {+ LAYER_VIS_CONFIGS,+ LAYER_TYPES,+ DatasetType,+ BitmapDatasetMetadata,+ BitmapBounds+} from '@kepler.gl/constants';+import {KeplerTable as KeplerDataset, Datasets as KeplerDatasets} from '@kepler.gl/table';+import {VisConfigNumber, VisConfigBoolean} from '@kepler.gl/types';++const EDIT_MODE = new CompositeMode([+ new TranslateMode() as unknown as GeoJsonEditMode,+ new ModifyMode() as unknown as GeoJsonEditMode+]);++export type BitmapLayerVisConfigSettings = {+ opacity: VisConfigNumber;+ showBounds: VisConfigBoolean;+ editBounds: VisConfigBoolean;+ boundsWest: VisConfigNumber;+ boundsSouth: VisConfigNumber;+ boundsEast: VisConfigNumber;+ boundsNorth: VisConfigNumber;+};++export const bitmapVisConfigs = {+ opacity: {+ ...LAYER_VIS_CONFIGS.opacity,+ defaultValue: 1,+ property: 'opacity'+ } as VisConfigNumber,+ showBounds: {+ type: 'boolean',+ defaultValue: true,+ label: 'layerVisConfigs.showBounds',+ group: 'display',+ property: 'showBounds'+ } as VisConfigBoolean,+ editBounds: {+ type: 'boolean',+ defaultValue: false,+ label: 'layerVisConfigs.editBounds',+ group: 'display',+ property: 'editBounds'+ } as VisConfigBoolean,+ boundsWest: {+ type: 'number',+ defaultValue: 0,+ label: 'layerVisConfigs.boundsWest',+ isRanged: false,+ range: [-180, 180],+ step: 0.0001,+ group: 'display',+ property: 'boundsWest'+ } as VisConfigNumber,+ boundsSouth: {+ type: 'number',+ defaultValue: 0,+ label: 'layerVisConfigs.boundsSouth',+ isRanged: false,+ range: [-90, 90],+ step: 0.0001,+ group: 'display',+ property: 'boundsSouth'+ } as VisConfigNumber,+ boundsEast: {+ type: 'number',+ defaultValue: 0,+ label: 'layerVisConfigs.boundsEast',+ isRanged: false,+ range: [-180, 180],+ step: 0.0001,+ group: 'display',+ property: 'boundsEast'+ } as VisConfigNumber,+ boundsNorth: {+ type: 'number',+ defaultValue: 0,+ label: 'layerVisConfigs.boundsNorth',+ isRanged: false,+ range: [-90, 90],+ step: 0.0001,+ group: 'display',+ property: 'boundsNorth'+ } as VisConfigNumber+};++export default class BitmapOverlayLayer extends Layer {+ declare visConfigSettings: BitmapLayerVisConfigSettings;+ private _editFeatureCollection: any = null;+ private _prevDataBoundsKey: string = '';+ private _onRedrawNeeded: (() => void) | undefined;+ private _rafId: number | undefined;++ constructor(props: {dataId: string; visConfig?: Record<string, any>} & Record<string, any>) {+ super(props);+ this.registerVisConfig(bitmapVisConfigs);+ // Apply visConfig from findDefaultLayerProps (e.g. bounds seeded from metadata)+ if (props.visConfig) {+ this.updateLayerVisConfig(props.visConfig);+ }+ this.meta = {};+ }++ static findDefaultLayerProps(dataset: KeplerDataset): FindDefaultLayerPropsReturnValue {+ if (dataset.type !== DatasetType.BITMAP) {+ return {props: []};+ }++ const metadata = (dataset.metadata || {}) as BitmapDatasetMetadata;+ const visConfig: Record<string, any> = {};++ if (metadata.bounds) {+ const metaBounds = metadata.bounds;+ if (Array.isArray(metaBounds) && typeof metaBounds[0] === 'number') {+ const [w, s, e, n] = metaBounds as [number, number, number, number];+ visConfig.boundsWest = w;+ visConfig.boundsSouth = s;+ visConfig.boundsEast = e;+ visConfig.boundsNorth = n;+ } else if (Array.isArray(metaBounds) && Array.isArray(metaBounds[0])) {+ const corners = metaBounds as [+ [number, number],+ [number, number],+ [number, number],+ [number, number]+ ];+ const lngs = corners.map(c => c[0]);+ const lats = corners.map(c => c[1]);+ visConfig.boundsWest = Math.min(...lngs);+ visConfig.boundsSouth = Math.min(...lats);+ visConfig.boundsEast = Math.max(...lngs);+ visConfig.boundsNorth = Math.max(...lats);+ }+ }++ return {+ props: [+ {+ label: dataset.label || 'Bitmap',+ isVisible: true,+ visConfig+ }+ ]+ };+ }++ get type(): string {+ return LAYER_TYPES.bitmap;+ }++ get name(): string {+ return 'Bitmap';+ }++ get requireData(): boolean {+ return false;+ }++ get requiredLayerColumns(): string[] {+ return [];+ }++ get layerIcon(): typeof BitmapLayerIcon {+ return BitmapLayerIcon;+ }++ get supportedDatasetTypes(): DatasetType[] {+ return [DatasetType.BITMAP];+ }++ get visualChannels() {+ return {};+ }++ shouldRenderLayer(): boolean {+ return Boolean(this.type && this.config.isVisible);+ }++ getHoverData(): any {+ return null;+ }++ formatLayerData(datasets: KeplerDatasets): Record<string, any> {+ const {dataId} = this.config;+ if (!dataId || !datasets[dataId]) {+ return {};+ }++ const dataset = datasets[dataId];+ const metadata = (dataset.metadata || {}) as BitmapDatasetMetadata;+ const {visConfig} = this.config;++ const bounds: BitmapBounds = [+ visConfig.boundsWest,+ visConfig.boundsSouth,+ visConfig.boundsEast,+ visConfig.boundsNorth+ ];++ this.updateMeta({bounds});++ return {+ imageUrl: metadata.imageUrl,+ bounds+ };+ }++ updateLayerMeta(_dataset: KeplerDataset): void {+ // bounds are managed through visConfig, meta.bounds is set in formatLayerData+ }++ renderLayer(opts: any) {+ const {data, layerCallbacks} = opts;+ const {imageUrl, bounds} = data || {};+ if (!imageUrl || !bounds) {+ return [];+ }++ this._onRedrawNeeded = layerCallbacks?.onRedrawNeeded;+ const {visConfig} = this.config;++ const {visible} = this.getDefaultDeckLayerProps(opts);++ const [west, south, east, north] = bounds as [number, number, number, number];+ const dataBoundsKey = `${west},${south},${east},${north}`;++ // Rebuild the editable feature collection only when data.bounds changes+ // (i.e., formatLayerData was re-run due to slider change or other external update).+ // During editing, data.bounds stays stale (cached), so this won't trigger.+ if (dataBoundsKey !== this._prevDataBoundsKey) {+ this._prevDataBoundsKey = dataBoundsKey;+ this._editFeatureCollection = {+ type: 'FeatureCollection',+ features: [+ {+ type: 'Feature',+ geometry: {+ type: 'Polygon',+ coordinates: [+ [+ [west, north],+ [east, north],+ [east, south],+ [west, south],+ [west, north]+ ]+ ]+ },+ properties: {shape: 'Rectangle'}+ }+ ]+ };+ }++ // Read current bounds from the edit feature collection (source of truth during editing)+ const editCoords =+ this._editFeatureCollection?.features?.[0]?.geometry?.coordinates?.[0];+ let activeBounds: [number, number, number, number];+ if (editCoords && editCoords.length >= 4) {+ // Use all vertices (excluding closing point which duplicates the first)+ const pts = editCoords.slice(0, -1);+ const lngs = pts.map((c: number[]) => c[0]);+ const lats = pts.map((c: number[]) => c[1]);+ activeBounds = [+ Math.min(...lngs),+ Math.min(...lats),+ Math.max(...lngs),+ Math.max(...lats)+ ];+ } else {+ activeBounds = [west, south, east, north];+ }++ const layers: any[] = [+ new DeckBitmapLayer({+ id: this.id,+ image: imageUrl,+ bounds: activeBounds,+ opacity: visConfig.opacity ?? 1,+ pickable: false,+ visible,+ parameters: {+ blend: true,+ blendColorSrcFactor: 'one',+ blendColorDstFactor: 'one-minus-src-alpha',+ blendAlphaSrcFactor: 'one',+ blendAlphaDstFactor: 'one-minus-src-alpha'+ }+ })+ ];++ if (visConfig.showBounds && !visConfig.editBounds) {+ // Static boundary outline (no interaction)+ const [aW, aS, aE, aN] = activeBounds;+ layers.push(+ new PathLayer({+ id: `${this.id}-bounds`,+ data: [+ [+ [aW, aN],+ [aE, aN],+ [aE, aS],+ [aW, aS],+ [aW, aN]+ ]+ ],+ getPath: (d: any) => d,+ getColor: [255, 255, 255, 200],+ getWidth: 2,+ widthUnits: 'pixels',+ pickable: false,+ visible+ })+ );+ }++ if (visConfig.editBounds) {+ // @ts-ignore - EditableGeoJsonLayer types are loose+ layers.push(+ new EditableGeoJsonLayer({+ id: `${this.id}-edit`,+ // @ts-ignore+ data: this._editFeatureCollection,+ mode: EDIT_MODE,+ selectedFeatureIndexes: [0],+ pickable: true,+ pickingRadius: 12,+ visible,+ modeConfig: {+ lockRectangles: true+ },+ filled: false,+ stroked: true,+ getLineColor: [255, 255, 255, 200],+ getLineWidth: 2,+ lineWidthUnits: 'pixels',+ getEditHandlePointColor: [255, 200, 0, 255],+ getEditHandlePointRadius: 6,+ editHandlePointRadiusUnits: 'pixels',+ onEdit: ({updatedData, editType}) => {+ this._editFeatureCollection = updatedData;++ const isFinal =+ editType === 'finishMovePosition' ||+ editType === 'translated' ||+ editType === 'addPosition';++ if (isFinal) {+ // Sync sliders on gesture end+ const geom = updatedData?.features?.[0]?.geometry;+ const coords =+ geom && 'coordinates' in geom ? (geom as any).coordinates[0] : null;+ if (coords && coords.length >= 5) {+ const pts = coords.slice(0, -1);+ const lngs = pts.map((c: number[]) => c[0]);+ const lats = pts.map((c: number[]) => c[1]);+ this.updateLayerVisConfig({+ boundsWest: Math.min(...lngs),+ boundsSouth: Math.min(...lats),+ boundsEast: Math.max(...lngs),+ boundsNorth: Math.max(...lats)+ });+ }+ if (this._rafId) {+ cancelAnimationFrame(this._rafId);+ this._rafId = undefined;+ }+ this._onRedrawNeeded?.();+ } else if (!this._rafId) {+ // Throttle live redraws to animation frame rate+ this._rafId = requestAnimationFrame(() => {+ this._rafId = undefined;+ this._onRedrawNeeded?.();+ });+ }+ }+ })+ );+ }++ return layers;+ }++}diff --git a/src/layers/src/bitmap-layer/index.ts b/src/layers/src/bitmap-layer/index.tsnew file mode 100644index 000000000..40e2c5f1c--- /dev/null+++ b/src/layers/src/bitmap-layer/index.ts@@ -0,0 +1,5 @@+// SPDX-License-Identifier: MIT+// Copyright contributors to the kepler.gl project++export {default} from './bitmap-layer';+export {default as BitmapLayerIcon} from './bitmap-layer-icon';diff --git a/src/layers/src/index.ts b/src/layers/src/index.tsindex 1cdd1e54f..61501bbc8 100644--- a/src/layers/src/index.ts+++ b/src/layers/src/index.ts@@ -60,6 +60,10 @@ export {import {default as Tile3DLayer} from './tile3d-layer/tile3d-layer';export {default as Tile3DLayer} from './tile3d-layer/tile3d-layer';export {default as Tile3DLayerIcon} from './tile3d-layer/tile3d-layer-icon';++import {default as BitmapOverlayLayer} from './bitmap-layer/bitmap-layer';+export {default as BitmapOverlayLayer} from './bitmap-layer/bitmap-layer';+export {default as BitmapLayerIcon} from './bitmap-layer/bitmap-layer-icon';export {CATEGORICAL_COLORMAP_ID,DATA_SOURCE_COLOR_DEFAULTS,@@ -104,7 +108,8 @@ export const KeplerGlLayers = {VectorTileLayer,RasterTileLayer,WMSLayer,- Tile3DLayer+ Tile3DLayer,+ BitmapOverlayLayer};export type LayerClassesType = typeof LayerClasses;@@ -126,7 +131,8 @@ export const LayerClasses = {[LAYER_TYPES['vectorTile']]: VectorTileLayer,[LAYER_TYPES['rasterTile']]: RasterTileLayer,[LAYER_TYPES.wms]: WMSLayer,- [LAYER_TYPES.tile3d]: Tile3DLayer+ [LAYER_TYPES.tile3d]: Tile3DLayer,+ [LAYER_TYPES.bitmap]: BitmapOverlayLayer};export * from './mapbox-utils';diff --git a/src/layers/src/layer-utils.ts b/src/layers/src/layer-utils.tsindex f523a8828..72ab21bca 100644--- a/src/layers/src/layer-utils.ts+++ b/src/layers/src/layer-utils.ts@@ -39,6 +39,7 @@ export type FindDefaultLayerProps = {isVisible?: boolean;columns?: Record<string, LayerColumn>;columnMode?: string;+ visConfig?: Record<string, any>;};export type FindDefaultLayerPropsReturnValue = {diff --git a/src/localization/src/translations/en.ts b/src/localization/src/translations/en.tsindex aab74422c..c70e03c65 100644--- a/src/localization/src/translations/en.ts+++ b/src/localization/src/translations/en.ts@@ -103,6 +103,8 @@ export default {service: 'Service',layer: 'Layer',appearance: 'Appearance',+ bounds: 'Bounds',+ imageSource: 'Image Source',uniqueIdField: 'Unique ID Field',type: {point: 'point',@@ -124,7 +126,8 @@ export default {vectortile: 'vector tile',rastertile: 'raster tile',wms: 'WMS',- tile3d: '3D tile'+ tile3d: '3D tile',+ bitmap: 'bitmap'},wms: {hover: 'Value:'@@ -149,6 +152,13 @@ export default {billboardDescription: 'Orient geometry towards the camera',fadeTrail: 'Fade trail',opacity: 'Opacity',+ imageUrl: 'Image URL',+ showBounds: 'Show Bounds',+ editBounds: 'Drag corners to resize',+ boundsWest: 'West',+ boundsSouth: 'South',+ boundsEast: 'East',+ boundsNorth: 'North',pointSize: 'Point Size',coverage: 'Coverage',outline: 'Outline',@@ -317,7 +327,8 @@ export default {vectorTile: 'Vector tile',rasterTile: 'Raster tile',wmsTile: 'WMS tile',- tile3d: '3D tile'+ tile3d: '3D tile',+ bitmap: 'Bitmap image'},tooltip: {hideLayer: 'Hide layer',diff --git a/src/reducers/src/vis-state-updaters.ts b/src/reducers/src/vis-state-updaters.tsindex 953efe4bb..d3c06cb23 100644--- a/src/reducers/src/vis-state-updaters.ts+++ b/src/reducers/src/vis-state-updaters.ts@@ -1120,13 +1120,34 @@ export function layerVisConfigChangeUpdater(const newLayer = oldLayer.updateLayerConfig({visConfig: newVisConfig});+ let nextState = state;++ // Exclusive bitmap editing: when editBounds is turned on for one bitmap layer,+ // turn it off for all other bitmap layers+ if (+ newLayer.type === 'bitmap' &&+ action.newVisConfig.editBounds === true+ ) {+ nextState = {+ ...nextState,+ layers: nextState.layers.map((l, i) => {+ if (i !== idx && l.type === 'bitmap' && l.config.visConfig.editBounds) {+ return l.updateLayerConfig({+ visConfig: {...l.config.visConfig, editBounds: false}+ });+ }+ return l;+ })+ };+ }+if (newLayer.shouldCalculateLayerData(props)) {- const oldLayerData = state.layerData[idx];- const {layerData, layer} = calculateLayerData(newLayer, state, oldLayerData);- return updateStateWithLayerAndData(state, {layerData, layer, idx});+ const oldLayerData = nextState.layerData[idx];+ const {layerData, layer} = calculateLayerData(newLayer, nextState, oldLayerData);+ return updateStateWithLayerAndData(nextState, {layerData, layer, idx});}- return updateStateWithLayerAndData(state, {layer: newLayer, idx});+ return updateStateWithLayerAndData(nextState, {layer: newLayer, idx});}/**diff --git a/src/table/src/dataset-utils.ts b/src/table/src/dataset-utils.tsindex 6596f75e4..b317f7151 100644--- a/src/table/src/dataset-utils.ts+++ b/src/table/src/dataset-utils.ts@@ -164,6 +164,8 @@ async function refreshRemoteData(datasetInfo: CreateTableProps): Promise<objectreturn await refreshWMSMetadata(datasetInfo);case DatasetType.TILE_3D:return null;+ case DatasetType.BITMAP:+ return null;default:return null;}diff --git a/src/utils/src/application-config.ts b/src/utils/src/application-config.tsindex f728e438f..ba3491401 100644--- a/src/utils/src/application-config.ts+++ b/src/utils/src/application-config.ts@@ -86,6 +86,9 @@ export type KeplerApplicationConfig = {// Flow layer configenableFlowLayer?: boolean;+ // Bitmap layer config+ enableBitmapLayer?: boolean;+/** Whether to show example URLs in tileset setup forms (vector tile, raster tile, WMS, 3D tile) */showInlineTilesetExamples?: boolean;@@ -159,6 +162,9 @@ const DEFAULT_APPLICATION_CONFIG: Required<KeplerApplicationConfig> = {// Flow layer configenableFlowLayer: true,+ // Bitmap layer config+ enableBitmapLayer: true,+showInlineTilesetExamples: true,// Image export configdiff --git a/test/browser/layer-tests/bitmap-layer-specs.js b/test/browser/layer-tests/bitmap-layer-specs.jsnew file mode 100644index 000000000..56b1170b1--- /dev/null+++ b/test/browser/layer-tests/bitmap-layer-specs.js@@ -0,0 +1,386 @@+// SPDX-License-Identifier: MIT+// Copyright contributors to the kepler.gl project++import test from 'tape-catch';+import {KeplerGlLayers} from '@kepler.gl/layers';+import {DatasetType} from '@kepler.gl/constants';+import {testCreateCases} from 'test/helpers/layer-utils';++const {BitmapOverlayLayer} = KeplerGlLayers;++const MOCK_BITMAP_DATASET = {+ type: DatasetType.BITMAP,+ metadata: {+ imageUrl: 'https://example.com/image.png',+ bounds: [-122.52, 37.7, -122.35, 37.82],+ isDataUri: false+ },+ label: 'Test Bitmap'+};++const MOCK_BITMAP_DATASET_CORNERS = {+ type: DatasetType.BITMAP,+ metadata: {+ imageUrl: 'https://example.com/image2.png',+ bounds: [+ [-122.52, 37.82],+ [-122.35, 37.82],+ [-122.35, 37.7],+ [-122.52, 37.7]+ ],+ isDataUri: false+ },+ label: 'Corner Bounds Bitmap'+};++const MOCK_DATASETS = {+ 'bitmap-test-data': MOCK_BITMAP_DATASET+};++function createBitmapLayer(config = {}) {+ const layer = new BitmapOverlayLayer({+ id: 'test-bitmap-layer',+ dataId: 'bitmap-test-data',+ ...config+ });++ if (config.visConfig) {+ layer.updateLayerVisConfig(config.visConfig);+ }++ return layer;+}++test('#BitmapOverlayLayer -> constructor', t => {+ const TEST_CASES = {+ CREATE: [+ {+ props: {+ dataId: 'bitmap-test-data',+ isVisible: true,+ label: 'test bitmap layer'+ },+ test: layer => {+ t.equal(layer.config.dataId, 'bitmap-test-data', 'dataId should be correct');+ t.equal(layer.type, 'bitmap', 'type should be bitmap');+ t.equal(layer.isAggregated, false, 'BitmapLayer is not aggregated');+ t.equal(layer.config.label, 'test bitmap layer', 'label should be correct');+ t.equal(layer.config.isVisible, true, 'should be visible');+ t.ok(layer.config.visConfig, 'should have visConfig');+ t.equal(layer.config.visConfig.opacity, 1, 'should have default opacity of 1');+ t.equal(layer.config.visConfig.showBounds, true, 'should show bounds by default');+ t.equal(layer.config.visConfig.editBounds, false, 'edit bounds off by default');+ t.equal(layer.config.visConfig.boundsWest, 0, 'default boundsWest should be 0');+ t.equal(layer.config.visConfig.boundsSouth, 0, 'default boundsSouth should be 0');+ t.equal(layer.config.visConfig.boundsEast, 0, 'default boundsEast should be 0');+ t.equal(layer.config.visConfig.boundsNorth, 0, 'default boundsNorth should be 0');+ t.ok(typeof layer.layerIcon === 'function', 'should have layerIcon');+ t.deepEqual(+ layer.supportedDatasetTypes,+ [DatasetType.BITMAP],+ 'should support BITMAP dataset type'+ );+ t.equal(layer.requireData, false, 'should not require data');+ t.deepEqual(layer.requiredLayerColumns, [], 'should have no required columns');+ }+ }+ ]+ };++ testCreateCases(t, BitmapOverlayLayer, TEST_CASES.CREATE);+ t.end();+});++test('#BitmapOverlayLayer -> constructor with visConfig', t => {+ const layer = new BitmapOverlayLayer({+ dataId: 'bitmap-test-data',+ visConfig: {+ boundsWest: -122.52,+ boundsSouth: 37.7,+ boundsEast: -122.35,+ boundsNorth: 37.82+ }+ });++ t.equal(layer.config.visConfig.boundsWest, -122.52, 'should apply visConfig boundsWest');+ t.equal(layer.config.visConfig.boundsSouth, 37.7, 'should apply visConfig boundsSouth');+ t.equal(layer.config.visConfig.boundsEast, -122.35, 'should apply visConfig boundsEast');+ t.equal(layer.config.visConfig.boundsNorth, 37.82, 'should apply visConfig boundsNorth');++ t.end();+});++test('#BitmapOverlayLayer -> findDefaultLayerProps with flat bounds', t => {+ const result = BitmapOverlayLayer.findDefaultLayerProps(MOCK_BITMAP_DATASET);++ t.ok(result.props, 'should return props');+ t.equal(result.props.length, 1, 'should return one layer prop');+ t.equal(result.props[0].label, 'Test Bitmap', 'should use dataset label');+ t.equal(result.props[0].isVisible, true, 'should be visible');+ t.ok(result.props[0].visConfig, 'should have visConfig');+ t.equal(result.props[0].visConfig.boundsWest, -122.52, 'should extract west bound');+ t.equal(result.props[0].visConfig.boundsSouth, 37.7, 'should extract south bound');+ t.equal(result.props[0].visConfig.boundsEast, -122.35, 'should extract east bound');+ t.equal(result.props[0].visConfig.boundsNorth, 37.82, 'should extract north bound');++ t.end();+});++test('#BitmapOverlayLayer -> findDefaultLayerProps with corner bounds', t => {+ const result = BitmapOverlayLayer.findDefaultLayerProps(MOCK_BITMAP_DATASET_CORNERS);++ t.ok(result.props, 'should return props');+ t.equal(result.props.length, 1, 'should return one layer prop');+ t.equal(result.props[0].visConfig.boundsWest, -122.52, 'should compute west from corners');+ t.equal(result.props[0].visConfig.boundsSouth, 37.7, 'should compute south from corners');+ t.equal(result.props[0].visConfig.boundsEast, -122.35, 'should compute east from corners');+ t.equal(result.props[0].visConfig.boundsNorth, 37.82, 'should compute north from corners');++ t.end();+});++test('#BitmapOverlayLayer -> findDefaultLayerProps with non-bitmap dataset', t => {+ const result = BitmapOverlayLayer.findDefaultLayerProps({type: 'csv', metadata: {}});++ t.deepEqual(result.props, [], 'should return empty props for non-bitmap dataset');++ t.end();+});++test('#BitmapOverlayLayer -> shouldRenderLayer', t => {+ const layer = createBitmapLayer();++ t.equal(layer.shouldRenderLayer(), true, 'visible layer should render');++ layer.updateLayerConfig({isVisible: false});+ t.equal(layer.shouldRenderLayer(), false, 'invisible layer should not render');++ t.end();+});++test('#BitmapOverlayLayer -> formatLayerData', t => {+ const layer = createBitmapLayer({+ visConfig: {+ boundsWest: -122.52,+ boundsSouth: 37.7,+ boundsEast: -122.35,+ boundsNorth: 37.82+ }+ });++ const result = layer.formatLayerData(MOCK_DATASETS);++ t.ok(result, 'should return layer data');+ t.equal(result.imageUrl, 'https://example.com/image.png', 'should have imageUrl');+ t.deepEqual(+ result.bounds,+ [-122.52, 37.7, -122.35, 37.82],+ 'should have bounds from visConfig'+ );++ t.end();+});++test('#BitmapOverlayLayer -> formatLayerData with missing dataset', t => {+ const layer = createBitmapLayer();++ const result = layer.formatLayerData({});+ t.deepEqual(result, {}, 'should return empty object for missing dataset');++ t.end();+});++test('#BitmapOverlayLayer -> renderLayer basic', t => {+ const layer = createBitmapLayer({+ visConfig: {+ boundsWest: -122.52,+ boundsSouth: 37.7,+ boundsEast: -122.35,+ boundsNorth: 37.82,+ opacity: 0.8,+ showBounds: true,+ editBounds: false+ }+ });++ const opts = {+ data: {+ imageUrl: 'https://example.com/image.png',+ bounds: [-122.52, 37.7, -122.35, 37.82]+ },+ idx: 0,+ mapState: {dragRotate: false},+ gpuFilter: {filterRange: null, filterValueUpdateTriggers: {}},+ interactionConfig: {},+ layerCallbacks: {},+ visible: true+ };++ const deckLayers = layer.renderLayer(opts);++ t.ok(deckLayers, 'should return deck layers');+ t.equal(deckLayers.length, 2, 'should render bitmap layer + bounds path');+ t.equal(deckLayers[0].id, layer.id, 'first layer should be bitmap');+ t.equal(deckLayers[0].props.opacity, 0.8, 'should have correct opacity');+ t.deepEqual(+ deckLayers[0].props.bounds,+ [-122.52, 37.7, -122.35, 37.82],+ 'should have correct bounds'+ );+ t.equal(deckLayers[1].id, `${layer.id}-bounds`, 'second layer should be bounds outline');++ t.end();+});++test('#BitmapOverlayLayer -> renderLayer without bounds outline', t => {+ const layer = createBitmapLayer({+ visConfig: {+ boundsWest: -122.52,+ boundsSouth: 37.7,+ boundsEast: -122.35,+ boundsNorth: 37.82,+ showBounds: false,+ editBounds: false+ }+ });++ const opts = {+ data: {+ imageUrl: 'https://example.com/image.png',+ bounds: [-122.52, 37.7, -122.35, 37.82]+ },+ idx: 0,+ mapState: {dragRotate: false},+ gpuFilter: {filterRange: null, filterValueUpdateTriggers: {}},+ interactionConfig: {},+ layerCallbacks: {},+ visible: true+ };++ const deckLayers = layer.renderLayer(opts);++ t.equal(deckLayers.length, 1, 'should only render bitmap layer when showBounds is false');++ t.end();+});++test('#BitmapOverlayLayer -> renderLayer with editBounds', t => {+ const layer = createBitmapLayer({+ visConfig: {+ boundsWest: -122.52,+ boundsSouth: 37.7,+ boundsEast: -122.35,+ boundsNorth: 37.82,+ showBounds: true,+ editBounds: true+ }+ });++ const opts = {+ data: {+ imageUrl: 'https://example.com/image.png',+ bounds: [-122.52, 37.7, -122.35, 37.82]+ },+ idx: 0,+ mapState: {dragRotate: false},+ gpuFilter: {filterRange: null, filterValueUpdateTriggers: {}},+ interactionConfig: {},+ layerCallbacks: {},+ visible: true+ };++ const deckLayers = layer.renderLayer(opts);++ t.equal(deckLayers.length, 2, 'should render bitmap + editable layer (no static bounds)');+ t.equal(deckLayers[0].id, layer.id, 'first should be bitmap');+ t.equal(deckLayers[1].id, `${layer.id}-edit`, 'second should be editable layer');++ t.end();+});++test('#BitmapOverlayLayer -> renderLayer with no data', t => {+ const layer = createBitmapLayer();++ const opts = {+ data: null,+ idx: 0,+ mapState: {dragRotate: false},+ gpuFilter: {filterRange: null, filterValueUpdateTriggers: {}},+ interactionConfig: {},+ layerCallbacks: {},+ visible: true+ };++ const deckLayers = layer.renderLayer(opts);+ t.deepEqual(deckLayers, [], 'should return empty array when no data');++ t.end();+});++test('#BitmapOverlayLayer -> renderLayer with missing imageUrl', t => {+ const layer = createBitmapLayer();++ const opts = {+ data: {imageUrl: null, bounds: [-122.52, 37.7, -122.35, 37.82]},+ idx: 0,+ mapState: {dragRotate: false},+ gpuFilter: {filterRange: null, filterValueUpdateTriggers: {}},+ interactionConfig: {},+ layerCallbacks: {},+ visible: true+ };++ const deckLayers = layer.renderLayer(opts);+ t.deepEqual(deckLayers, [], 'should return empty array when no imageUrl');++ t.end();+});++test('#BitmapOverlayLayer -> updateLayerVisConfig', t => {+ const layer = createBitmapLayer();++ layer.updateLayerVisConfig({+ boundsWest: -100,+ boundsSouth: 30,+ boundsEast: -80,+ boundsNorth: 40,+ opacity: 0.5+ });++ t.equal(layer.config.visConfig.boundsWest, -100, 'should update boundsWest');+ t.equal(layer.config.visConfig.boundsSouth, 30, 'should update boundsSouth');+ t.equal(layer.config.visConfig.boundsEast, -80, 'should update boundsEast');+ t.equal(layer.config.visConfig.boundsNorth, 40, 'should update boundsNorth');+ t.equal(layer.config.visConfig.opacity, 0.5, 'should update opacity');++ t.end();+});++test('#BitmapOverlayLayer -> visual channels', t => {+ const layer = createBitmapLayer();++ t.deepEqual(layer.visualChannels, {}, 'should have no visual channels');++ t.end();+});++test('#BitmapOverlayLayer -> getHoverData', t => {+ const layer = createBitmapLayer();++ t.equal(layer.getHoverData(), null, 'should return null for hover data');++ t.end();+});++test('#BitmapOverlayLayer -> layer properties', t => {+ const layer = createBitmapLayer();++ t.equal(layer.name, 'Bitmap', 'should have correct name');+ t.equal(layer.type, 'bitmap', 'should have correct type');+ t.equal(layer.requireData, false, 'should not require data');+ t.deepEqual(layer.requiredLayerColumns, [], 'should have no required columns');+ t.deepEqual(layer.supportedDatasetTypes, [DatasetType.BITMAP], 'should support bitmap type');+ t.ok(layer.layerIcon, 'should have layer icon');++ t.end();+});diff --git a/test/browser/layer-tests/index.js b/test/browser/layer-tests/index.jsindex 74ba53d6b..75c22620f 100644--- a/test/browser/layer-tests/index.js+++ b/test/browser/layer-tests/index.js@@ -3,6 +3,7 @@import './base-layer-specs';import './arc-layer-specs';+import './bitmap-layer-specs';import './cluster-layer-specs';import './geojson-layer-specs';import './grid-layer-specs';