Svelte Maplibre

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 Topology

    A TopoJSON Topology object. Mutually exclusive with url.

  • url string

    URL to a TopoJSON file. Fetched and converted automatically. Mutually exclusive with data.

  • objectName string

    Which named object to extract. Defaults to the first object key.

  • id string

    Default: getId('topojson')

    Source ID. Defaults to topojson-N.

  • generateId boolean

    Default: false

    Generate a unique id for each feature. This will overwrite existing IDs.

  • promoteId string

    Use this property on the feature as the ID. This will overwrite existing IDs.

  • filter ExpressionSpecification
  • lineMetrics boolean

    True 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
  • buffer number
  • tolerance number
  • ondata (fc: FeatureCollection) => void

    Called with the converted FeatureCollection when data is ready.

  • onerror (message: string) => void

    Called when fetch or conversion fails.

  • children Snippet

Source: src/lib/TopoJSON.svelte