← All components

GeoJSON layer

Declare a source and layer in JSX. It survives style changes.

Previews run on MapScale's public Thailand archive.

Install

npx shadcn@latest add https://mapscale.io/r/geojson-layer.json

Usage

import { GeoJSONLayer } from "@/components/mapscale/geojson-layer"

<Map>
	<GeoJSONLayer
		id="zones"
		type="fill"
		data={zones}
		paint={{ "fill-color": "#2563eb", "fill-opacity": 0.25 }}
	/>
</Map>

Props

PropTypeDefaultDescription
idstring-Used as both the source id and the layer id.
dataGeoJSON | string-GeoJSON object or URL. Updated in place when it changes.
typestring-fill, line, circle, symbol, heatmap or fill-extrusion.
paintobject{}MapLibre paint properties. Changes apply without re-adding the layer.
layoutobject{}MapLibre layout properties.
beforeIdstring-Insert the layer below this existing layer.

Keys

Maps, autocomplete and place details use a publishable pk_ key that is safe in the browser. Routing and isochrones need a secret sk_ key, so they go through the proxy route your app serves.