Skip to content

Instantly share code, notes, and snippets.

@bdon
Created October 13, 2022 03:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdon/a106219d5714ed9dc80aa5327900aa89 to your computer and use it in GitHub Desktop.
Save bdon/a106219d5714ed9dc80aa5327900aa89 to your computer and use it in GitHub Desktop.
example use of pmtiles 2.0.0 with maplibre
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Display a map</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<script src="https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.js"></script>
<link href="https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.css" rel="stylesheet" />
<script src="https://unpkg.com/pmtiles@2.0.0/dist/index.js"></script>
<style>
body { margin: 0; padding: 0; }
#map { position: absolute; top: 0; bottom: 0; width: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script>
let protocol = new pmtiles.Protocol();
maplibregl.addProtocol("pmtiles",protocol.tile);
var map = new maplibregl.Map({
container: 'map',
style: {
version: 8,
sources: {
example_source: {
type: "vector",
tiles: ["pmtiles://https://protomaps-static.sfo3.digitaloceanspaces.com/cb_2018_us_zcta510_500k_gzip.pmtiles/{z}/{x}/{y}"]
}
},
layers: [
{
id: "zcta",
type: "fill",
source: "example_source",
"source-layer":"zcta",
paint: {
"fill-color":"steelblue"
}
}
]
},
center: [-100, 36],
zoom: 3
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment