MapScale Docs
Platforms & SDKs

Upload a dataset and serve it as tiles

Upload GeoJSON to your MapScale account, get a vector tileset, and draw it on a MapLibre map.

Beginner

Before you start

A dataset is a GeoJSON FeatureCollection stored in your account and served as vector tiles. Supported geometries are Point, MultiPoint, LineString, MultiLineString, Polygon and MultiPolygon in WGS84 longitude/latitude. Uploading and managing datasets needs a secret key (sk_), so run those calls from your terminal or server. Reading tiles and styles in the browser needs only a publishable key (pk_) from the same account. Per-account quotas apply to the number of datasets, features per dataset and upload size.

Before you start
{
	"type": "FeatureCollection",
	"features": [
		{
			"type": "Feature",
			"geometry": { "type": "Point", "coordinates": [100.5018, 13.7563] },
			"properties": { "name": "Bangkok", "staff": 42 }
		},
		{
			"type": "Feature",
			"geometry": { "type": "Point", "coordinates": [98.9853, 18.7883] },
			"properties": { "name": "Chiang Mai", "staff": 12 }
		}
	]
}

Upload GeoJSON

POST the FeatureCollection as the request body. The slug becomes the layer name inside the tiles. Datasets are private to your account unless you add public=true.

Upload GeoJSON
# Save the sample above as branches.geojson, then upload it.
# name is required. slug (the layer name inside the tiles) and public are optional.
curl -X POST "https://api.mapscale.io/v1/datasets?name=Branches&slug=branches" \
  -H "x-api-key: sk_live_YOUR_SECRET_KEY" \
  -H "content-type: application/json" \
  --data-binary @branches.geojson

# The response includes the dataset id, its slug and its tilesetId:
#   "tilesetId": "ds_0b3f6f6e-5c6e-4f43-9f43-1d1a1c1e1f10"

Check what you uploaded

List your datasets, or fetch one by id, to see its status, feature count, geometry type and bounding box.

Check what you uploaded
curl "https://api.mapscale.io/v1/datasets" \
  -H "x-api-key: sk_live_YOUR_SECRET_KEY"

# One dataset:
curl "https://api.mapscale.io/v1/datasets/DATASET_ID" \
  -H "x-api-key: sk_live_YOUR_SECRET_KEY"

Draw it on a map

Add a vector source that points at /tiles/v1/ds_{id}/{z}/{x}/{y}.mvt and a layer whose source-layer is the dataset slug. MapLibre cannot set headers on tile requests, so pass your publishable key as the key query parameter.

Draw it on a map
<link rel="stylesheet" href="https://unpkg.com/maplibre-gl@5/dist/maplibre-gl.css" />
<script src="https://unpkg.com/maplibre-gl@5/dist/maplibre-gl.js"></script>
<div id="map" style="height: 480px"></div>
<script>
	// Publishable key from the account that owns the dataset.
	const key = "pk_live_YOUR_PUBLISHABLE_KEY"
	const tilesetId = "ds_YOUR_DATASET_ID" // tilesetId from the upload response
	const slug = "branches" // slug from the upload response

	const map = new maplibregl.Map({
		container: "map",
		style: "https://api.mapscale.io/styles/v1/streets?lang=en&key=" + key,
		center: [100.5018, 13.7563],
		zoom: 5,
	})

	map.on("load", () => {
		map.addSource("branches", {
			type: "vector",
			tiles: ["https://api.mapscale.io/tiles/v1/" + tilesetId + "/{z}/{x}/{y}.mvt?key=" + key],
			maxzoom: 14,
		})
		map.addLayer({
			id: "branches-circle",
			type: "circle",
			source: "branches",
			"source-layer": slug, // the layer name inside the tiles is the dataset slug
			paint: { "circle-color": "#0c4a4a", "circle-radius": 7 },
		})
	})
</script>

Use it in React

The MapScale React kit includes a DatasetLayer component. It adds the vector source and the right layer types for the dataset geometry, and puts them back after a basemap style swap.

Use it in React
// npx shadcn@latest add https://mapscale.io/r/geojson-layer.json
import { DatasetLayer } from "@/components/mapscale/dataset-layer"
import { Map } from "@/components/mapscale/map"

export function BranchesMap() {
	return (
		<div style={{ height: 480 }}>
			<Map center={[100.5018, 13.7563]} zoom={5}>
				<DatasetLayer
					tilesetId="ds_YOUR_DATASET_ID"
					sourceLayer="branches"
					geometryType="Point"
					apiKey={process.env.NEXT_PUBLIC_MAPSCALE_KEY}
				/>
			</Map>
		</div>
	)
}

Remove a dataset

Deleting a dataset removes its features and stops its tiles from being served.

Remove a dataset
curl -X DELETE "https://api.mapscale.io/v1/datasets/DATASET_ID" \
  -H "x-api-key: sk_live_YOUR_SECRET_KEY"
# { "id": "...", "deleted": true }

On this page

Analytics settings