API / Sources
TopoJSON
Load TopoJSON data, convert it to GeoJSON, and add it to the map as a GeoJSON source. Give the data with data or with url. If you give both, url is used.
The conversion uses the topojson-client package, which you must install. objectName selects the object to convert. If you do not set it, the component uses the first object in the topology.
Place layer components inside this component's children and they use this source automatically. The children render only after the data is converted. ondata receives the converted FeatureCollection, and onerror receives an error message if the fetch or conversion fails. The other props pass through to GeoJSON.
import { TopoJSON } from 'svelte-maplibre'; Props
- data
TopologyA TopoJSON Topology object. Mutually exclusive with
url. - url
stringURL to a TopoJSON file. Fetched and converted automatically. Mutually exclusive with
data. - objectName
stringWhich named object to extract. Defaults to the first object key.
- id
stringDefault:
getId('topojson')Source ID. Defaults to
topojson-N. - generateId
booleanDefault:
falseGenerate a unique id for each feature. This will overwrite existing IDs.
- promoteId
stringUse this property on the feature as the ID. This will overwrite existing IDs.
- filter
ExpressionSpecification - lineMetrics
booleanTrue to calculate line lengths. Required to use a line layer that uses the "line-gradient" paint property.
-
Cluster configuration. Only applies to point-feature topologies — polygon/line geometries will silently ignore this option.
- maxzoom
number - attribution
string - buffer
number - tolerance
number - ondata
(fc: FeatureCollection) => voidCalled with the converted FeatureCollection when data is ready.
- onerror
(message: string) => voidCalled when fetch or conversion fails.
- children
Snippet
Source: src/lib/TopoJSON.svelte