-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into chr/fix-widget-events
- Loading branch information
Showing
22 changed files
with
892 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# QuadbinHeatmapTileLayer (Experimental) | ||
|
||
`QuadbinHeatmapTileLayer` is a layer for visualizing tiled data indexed with a [Quadbin Spatial Index](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/key-concepts/spatial-indexes#quadbin) using a heatmap. | ||
|
||
## Usage | ||
|
||
```tsx | ||
import DeckGL from '@deck.gl/react'; | ||
import {QuadbinHeatmapTileLayer, quadbinTableSource} from '@deck.gl/carto'; | ||
|
||
function App({viewState}) { | ||
const data = quadbinTableSource({ | ||
accessToken: 'XXX', | ||
connectionName: 'carto_dw', | ||
tableName: 'carto-demo-data.demo_tables.quadbin' | ||
}); | ||
|
||
const layer = new QuadbinHeatmapTileLayer({ | ||
data, | ||
getWeight: d => d.properties.count | ||
}) | ||
|
||
return <DeckGL viewState={viewState} layers={[layer]} />; | ||
} | ||
``` | ||
|
||
## Installation | ||
|
||
To install the dependencies from NPM: | ||
|
||
```bash | ||
npm install deck.gl | ||
# or | ||
npm install @deck.gl/core @deck.gl/layers @deck.gl/carto | ||
``` | ||
|
||
```js | ||
import {QuadbinHeatmapTileLayer} from '@deck.gl/carto'; | ||
new QuadbinHeatmapTileLayer({}); | ||
``` | ||
|
||
To use pre-bundled scripts: | ||
|
||
```html | ||
<script src="https://unpkg.com/deck.gl@^9.0.0/dist.min.js"></script> | ||
<script src="https://unpkg.com/@deck.gl/carto@^9.0.0/dist.min.js"></script> | ||
|
||
<!-- or --> | ||
<script src="https://unpkg.com/@deck.gl/core@^9.0.0/dist.min.js"></script> | ||
<script src="https://unpkg.com/@deck.gl/layers@^9.0.0/dist.min.js"></script> | ||
<script src="https://unpkg.com/@deck.gl/geo-layers@^9.0.0/dist.min.js"></script> | ||
<script src="https://unpkg.com/@deck.gl/carto@^9.0.0/dist.min.js"></script> | ||
``` | ||
|
||
```js | ||
new deck.carto.QuadbinHeatmapTileLayer({}); | ||
``` | ||
|
||
## Properties | ||
|
||
Inherits from all [Base Layer](../core/layer.md) and [CompositeLayer](../core/composite-layer.md) properties. | ||
|
||
#### `data` (TilejsonResult) {#data} | ||
|
||
Required. A valid `TilejsonResult` object. | ||
|
||
Use one of the following [Data Sources](./data-sources.md) to fetch this from the CARTO API: | ||
|
||
- [quadbinTableSource](./data-sources#quadbintablesource) | ||
- [quadbinQuerySource](./data-sources#quadbinquerysource) | ||
- [quadbinTilesetSource](./data-sources#quadbintilesetsource) | ||
|
||
### Render Options | ||
|
||
#### `radiusPixels` (number, optional) ![transition-enabled](https://img.shields.io/badge/transition-enabled-green.svg?style=flat-square") {#radiuspixels} | ||
|
||
* Default: `20` | ||
|
||
Radius of the heatmap blur in pixels, to which the weight of a cell is distributed. | ||
|
||
#### `colorDomain` (number[2], optional) ![transition-enabled](https://img.shields.io/badge/transition-enabled-green.svg?style=flat-square") {#colordomain} | ||
|
||
* Default: `[0, 1]` | ||
|
||
Controls how weight values are mapped to the `colorRange`, as an array of two numbers [`minValue`, `maxValue`]. | ||
|
||
When `colorDomain` is specified, a pixel with `minValue` is assigned the first color in `colorRange`, a pixel with `maxValue` is assigned the last color in `colorRange`, and any value in between is interpolated. Pixels in the bottom 10% of the range defined by `colorDomain` are gradually faded out by reducing alpha, until 100% transparency at `minValue`. Pixels with weight more than `maxValue` are capped to the last color in `colorRange`. | ||
|
||
#### `colorRange` (Color[], optional) {#colorrange} | ||
|
||
* Default: [colorbrewer](http://colorbrewer2.org/#type=sequential&scheme=YlOrRd&n=6) `6-class YlOrRd` <img src="https://deck.gl/images/colorbrewer_YlOrRd_6.png"/> | ||
|
||
The color palette used in the heatmap, as an array of colors [color1, color2, ...]. Each color is in the format of `[r, g, b]`. Each channel is a number between 0-255. | ||
|
||
|
||
### Data Accessors | ||
|
||
#### `getWeight` ([Accessor<number>](../../developer-guide/using-layers.md#accessors), optional) {#getweight} | ||
|
||
* Default: `1` | ||
|
||
Method called to retrieve weight of each quadbin cell. By default each cell will use a weight of `1`. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import {MapViewState} from '@deck.gl/core'; | ||
import { | ||
GOOGLE_BASEMAPS, | ||
CARTO_MAP_STYLES, | ||
applyLayerGroupFilters, | ||
fetchStyle, | ||
getStyleUrl, | ||
someLayerGroupsDisabled | ||
} from '../basemap'; | ||
import {APIErrorContext, Basemap, KeplerMapConfig, MapLibreBasemapProps} from './types'; | ||
|
||
const CUSTOM_STYLE_ID_PREFIX = 'custom:'; | ||
const DEFAULT_CARTO_STYLE = 'positron'; | ||
|
||
function mapLibreViewpros(config: KeplerMapConfig): Omit<MapLibreBasemapProps, 'style'> { | ||
const {longitude, latitude, ...rest} = config.mapState as MapViewState; | ||
return { | ||
center: [longitude, latitude], | ||
...rest | ||
}; | ||
} | ||
|
||
/** | ||
* Get basemap properties for Carto map. | ||
* | ||
* For maplibre-based basemaps it returns style or style URL that can be used with `maplibregl.Map` compatible component. | ||
* * style url is returned for non-filtered standard Carto basemaps or if user used style URL directly in configuration | ||
* * filtered style object returned for Carto basemaps with layer groups filtered | ||
* | ||
* For Google-maps base maps, it returns options that can be used with `google.maps.Map` constructor. | ||
*/ | ||
export async function fetchBasemapProps({ | ||
config, | ||
errorContext, | ||
|
||
applyLayerFilters = true | ||
}: { | ||
config: KeplerMapConfig; | ||
|
||
/** By default `fetchBasemapProps` applies layers filters to style. Set this to `false` to disable it. */ | ||
applyLayerFilters?: boolean; | ||
errorContext?: APIErrorContext; | ||
}): Promise<Basemap | null> { | ||
const {mapStyle} = config; | ||
const styleType = mapStyle.styleType || DEFAULT_CARTO_STYLE; | ||
if (styleType.startsWith(CUSTOM_STYLE_ID_PREFIX)) { | ||
const currentCustomStyle = config.customBaseMaps?.customStyle; | ||
if (currentCustomStyle) { | ||
return { | ||
type: 'maplibre', | ||
props: { | ||
style: currentCustomStyle.style || currentCustomStyle.url, | ||
...mapLibreViewpros(config) | ||
}, | ||
attribution: currentCustomStyle.customAttribution | ||
}; | ||
} | ||
} | ||
|
||
if (CARTO_MAP_STYLES.includes(styleType)) { | ||
const {visibleLayerGroups} = mapStyle; | ||
const styleUrl = getStyleUrl(styleType); | ||
let style = styleUrl; | ||
let rawStyle = styleUrl; | ||
if (applyLayerFilters && visibleLayerGroups && someLayerGroupsDisabled(visibleLayerGroups)) { | ||
rawStyle = await fetchStyle({styleUrl, errorContext}); | ||
style = applyLayerGroupFilters(rawStyle, visibleLayerGroups); | ||
} | ||
return { | ||
type: 'maplibre', | ||
props: { | ||
style, | ||
...mapLibreViewpros(config) | ||
}, | ||
visibleLayerGroups, | ||
rawStyle | ||
}; | ||
} | ||
const googleBasemapDef = GOOGLE_BASEMAPS[styleType]; | ||
if (googleBasemapDef) { | ||
const {mapState} = config; | ||
return { | ||
type: 'google-maps', | ||
props: { | ||
...googleBasemapDef, | ||
center: {lat: mapState.latitude, lng: mapState.longitude}, | ||
zoom: mapState.zoom + 1, | ||
tilt: mapState.pitch, | ||
heading: mapState.bearing | ||
} | ||
}; | ||
} | ||
return { | ||
type: 'maplibre', | ||
props: { | ||
style: getStyleUrl(DEFAULT_CARTO_STYLE), | ||
...mapLibreViewpros(config) | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.