diff --git a/docs/admin_docs/configuration/map-tiles.mdx b/docs/admin_docs/configuration/map-tiles.mdx index 922f15364568..54ed42b030ea 100644 --- a/docs/admin_docs/configuration/map-tiles.mdx +++ b/docs/admin_docs/configuration/map-tiles.mdx @@ -78,7 +78,7 @@ Setting `DECKGL_BASE_MAP` overwrite default values After defining your map tiles, set them in these variables: - `CORS_OPTIONS` -- `connect-src` of `TALISMAN_CONFIG` and `TALISMAN_CONFIG_DEV` variables. +- `connect-src` of `TALISMAN_CONFIG` and `TALISMAN_DEV_CONFIG` variables. ```python ENABLE_CORS = True @@ -109,3 +109,32 @@ TALISMAN_CONFIG = { ... } ``` + +## Vector tiles + +The deck.gl Vector Tiles chart draws data from a vector tile server, such as +[Martin](https://maplibre.org/martin/), pg_tileserv or GeoServer, instead of from a +Superset query. This is separate from DECKGL_BASE_MAP, which only sets the background map. + +To use the chart: + +1. Serve Mapbox Vector Tiles (MVT) at a URL containing `{z}`, `{x}` and `{y}`. Optionally, + also serve a TileJSON document, which the chart uses to list the properties in the tiles. +2. Allow cross-origin requests from Superset on the tile server. Martin allows them by default. +3. Add the tile server to `connect-src` in both `TALISMAN_CONFIG` and `TALISMAN_DEV_CONFIG`. + Otherwise, the browser blocks the requests and the chart shows an empty map. + +```python +TALISMAN_CONFIG = { + "content_security_policy": { + ... + "connect-src": [ + "'self'", + "https://api.mapbox.com", + "https://events.mapbox.com", + "https://tiles.example.com", + ], + ... + }, +} +``` diff --git a/docs/admin_docs/security/security.mdx b/docs/admin_docs/security/security.mdx index 91c54fc3b6b9..f4616eeb0cb2 100644 --- a/docs/admin_docs/security/security.mdx +++ b/docs/admin_docs/security/security.mdx @@ -952,6 +952,16 @@ this warning using the `CONTENT_SECURITY_POLICY_WARNING` key in `config.py`. - Cartodiagram charts request map data (image and json) from external resources that can be edited by users, and therefore either require a list of allowed domains to request from or a wildcard (`'*'`) for `img-src` and `connect-src`. +- deck.gl Vector Tiles charts load vector tiles and TileJSON directly from the tile server URLs + entered in each chart, which users can edit. Add the allowed tile servers to `connect-src` + (or use a wildcard, with the same trade-off as for Cartodiagram charts): + + ``` + connect-src 'self' https://tiles.example.com + ``` + + See [Map tiles](/admin-docs/configuration/map-tiles#vector-tiles) for the full setup. + - Other CSP directives default to `'self'` to limit content to the same origin as the Superset server. In order to adjust provided CSP configuration to your needs, follow the instructions and examples provided in diff --git a/superset-frontend/jest.config.js b/superset-frontend/jest.config.js index 6cd5e3d3f712..13768bfb4e3e 100644 --- a/superset-frontend/jest.config.js +++ b/superset-frontend/jest.config.js @@ -115,7 +115,10 @@ export default { // @deck.gl/maplibre@9.4.0 ships ESM-only (no dist/*.cjs), unlike every // other @deck.gl/* package - allowed through so babel-jest can convert // its import/export syntax (see the moduleNameMapper entry above). - 'node_modules/(?!@ant-design/(colors|fast-color)|@formatjs/.*|d3-(array|interpolate|color|time|scale|time-format|format|selection|hierarchy)|internmap|@mapbox/tiny-sdf|@deck.gl/maplibre|remark-gfm|(?!@ngrx|(?!deck.gl)|d3-scale)|markdown-table|micromark-*.|decode-named-character-reference|character-entities|mdast-util-*.|unist-util-*.|ccount|escape-string-regexp|nanoid|uuid|@rjsf/*.|@x0k/.*|echarts|zrender|fetch-mock|pretty-ms|parse-ms|ol|@babel/runtime|@emotion|cheerio|cheerio/lib|parse5|dom-serializer|entities|htmlparser2|rehype-sanitize|hast-util-sanitize|unified|react-markdown|vfile|web-namespaces|html-void-elements|html-url-attributes|estree-util-is-identifier-name|trim-lines|is-plain-obj|trough|unist-.*|hast-.*|hastscript|refractor|rehype-.*|remark-.*|mdast-.*|micromark-.*|parse-entities|character-reference-invalid|is-alphanumerical|is-alphabetical|is-decimal|is-hexadecimal|property-information|space-separated-tokens|comma-separated-tokens|bail|devlop|zwitch|longest-streak|geostyler|geostyler-.*|@turf/.*|(?!geostyler)lodash|react-error-boundary|react-json-tree|react-base16-styling|color|color-(convert|string|name)|lodash-es|rbush|quickselect|react-diff-viewer-continued|storybook/*.|json-stringify-pretty-compact|@x0k/json-schema-merge|content-disposition|gettext-parser|react-resize-detector|http-proxy-middleware|httpxy)', + // + // meshoptimizer is ESM-only and reaches the deck.gl plugin through + // @deck.gl/geo-layers -> @loaders.gl/gltf (used by the Vector Tiles chart). + 'node_modules/(?!@ant-design/(colors|fast-color)|@formatjs/.*|d3-(array|interpolate|color|time|scale|time-format|format|selection|hierarchy)|internmap|@mapbox/tiny-sdf|@deck.gl/maplibre|meshoptimizer|remark-gfm|(?!@ngrx|(?!deck.gl)|d3-scale)|markdown-table|micromark-*.|decode-named-character-reference|character-entities|mdast-util-*.|unist-util-*.|ccount|escape-string-regexp|nanoid|uuid|@rjsf/*.|@x0k/.*|echarts|zrender|fetch-mock|pretty-ms|parse-ms|ol|@babel/runtime|@emotion|cheerio|cheerio/lib|parse5|dom-serializer|entities|htmlparser2|rehype-sanitize|hast-util-sanitize|unified|react-markdown|vfile|web-namespaces|html-void-elements|html-url-attributes|estree-util-is-identifier-name|trim-lines|is-plain-obj|trough|unist-.*|hast-.*|hastscript|refractor|rehype-.*|remark-.*|mdast-.*|micromark-.*|parse-entities|character-reference-invalid|is-alphanumerical|is-alphabetical|is-decimal|is-hexadecimal|property-information|space-separated-tokens|comma-separated-tokens|bail|devlop|zwitch|longest-streak|geostyler|geostyler-.*|@turf/.*|(?!geostyler)lodash|react-error-boundary|react-json-tree|react-base16-styling|color|color-(convert|string|name)|lodash-es|rbush|quickselect|react-diff-viewer-continued|storybook/*.|json-stringify-pretty-compact|@x0k/json-schema-merge|content-disposition|gettext-parser|react-resize-detector|http-proxy-middleware|httpxy)', ], transform: { '^.+\\.(mjs|js|jsx|ts|tsx)$': 'babel-jest', diff --git a/superset-frontend/package-lock.json b/superset-frontend/package-lock.json index 01960ad87ea5..8242cae24d33 100644 --- a/superset-frontend/package-lock.json +++ b/superset-frontend/package-lock.json @@ -40537,12 +40537,14 @@ "@deck.gl/mapbox": "~9.4.0", "@deck.gl/maplibre": "~9.4.0", "@deck.gl/mesh-layers": "~9.4.0", + "@loaders.gl/mvt": "^4.4.3", "@luma.gl/constants": "~9.4.0", "@luma.gl/core": "~9.4.0", "@luma.gl/engine": "~9.4.0", "@luma.gl/shadertools": "~9.4.0", "@luma.gl/webgl": "~9.4.0", "@mapbox/geojson-extent": "^1.0.1", + "@maplibre/maplibre-gl-style-spec": "^26.4.4", "@math.gl/web-mercator": "^4.1.0", "@types/d3-array": "^3.2.2", "@types/geojson": "^7946.0.16", diff --git a/superset-frontend/plugins/preset-chart-deckgl/package.json b/superset-frontend/plugins/preset-chart-deckgl/package.json index 9fe67d2da38d..d0b15c18f48d 100644 --- a/superset-frontend/plugins/preset-chart-deckgl/package.json +++ b/superset-frontend/plugins/preset-chart-deckgl/package.json @@ -35,12 +35,14 @@ "@deck.gl/mapbox": "~9.4.0", "@deck.gl/maplibre": "~9.4.0", "@deck.gl/mesh-layers": "~9.4.0", + "@loaders.gl/mvt": "^4.4.3", "@luma.gl/constants": "~9.4.0", "@luma.gl/core": "~9.4.0", "@luma.gl/engine": "~9.4.0", "@luma.gl/shadertools": "~9.4.0", "@luma.gl/webgl": "~9.4.0", "@mapbox/geojson-extent": "^1.0.1", + "@maplibre/maplibre-gl-style-spec": "^26.4.4", "@math.gl/web-mercator": "^4.1.0", "@types/d3-array": "^3.2.2", "@types/geojson": "^7946.0.16", diff --git a/superset-frontend/plugins/preset-chart-deckgl/src/layers/VectorTile/TilePropertyControl.tsx b/superset-frontend/plugins/preset-chart-deckgl/src/layers/VectorTile/TilePropertyControl.tsx new file mode 100644 index 000000000000..4a340ccdb0a6 --- /dev/null +++ b/superset-frontend/plugins/preset-chart-deckgl/src/layers/VectorTile/TilePropertyControl.tsx @@ -0,0 +1,108 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { useMemo } from 'react'; +import { t } from '@apache-superset/core/translation'; +import { Select } from '@superset-ui/core/components'; +import { ControlHeader } from '@superset-ui/chart-controls'; +import { useTileJsonProperties, isNumericTileType } from './tileJson'; + +export interface TilePropertyControlProps { + name: string; + label?: string; + description?: string; + value?: string | string[] | null; + multi?: boolean; + onChange: (value: string | string[] | undefined) => void; + tileJsonUrl?: string; + sourceLayer?: string; + /** [column_name, display name] pairs from the dataset, the fallback list. */ + datasetChoices: string[][]; + numericOnly?: boolean; +} + +/** + * Select for tile property names (one or many). Lists TileJSON properties when + * a TileJSON URL loads, otherwise the dataset's columns; numericOnly hides + * non-numeric ones. + */ +export default function TilePropertyControl({ + name, + label, + description, + value, + multi = true, + onChange, + tileJsonUrl, + sourceLayer, + datasetChoices, + numericOnly = false, +}: TilePropertyControlProps) { + const { properties, loading, error } = useTileJsonProperties( + tileJsonUrl, + sourceLayer, + ); + const useTileJson = Boolean(tileJsonUrl?.trim()) && !error; + + const options = useMemo( + () => + useTileJson + ? properties + .filter( + property => !numericOnly || isNumericTileType(property.type), + ) + .map(property => ({ + value: property.name, + label: property.name, + })) + : datasetChoices.map(([column, displayName]) => ({ + value: column, + label: displayName, + })), + [useTileJson, properties, datasetChoices, numericOnly], + ); + + return ( +