mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 02:41:09 +00:00
openlayers: add copy of code for script includes; migrate examples [#3]
This commit is contained in:
1
.github/workflows/actions.yml
vendored
1
.github/workflows/actions.yml
vendored
@@ -25,6 +25,7 @@ jobs:
|
||||
- run: cd serverless/cloudflare && cp wrangler.toml.example wrangler.toml && npm install && npm run build && cp dist/index.js ../../app/dist
|
||||
- run: cd spec/v3 && cp *.pmtiles ../../app/dist
|
||||
- run: cd js/examples && mkdir ../../app/dist/examples && cp *.html ../../app/dist/examples/
|
||||
- run: cd openlayers/examples && mkdir ../../app/dist/examples/openlayers && cp *.html ../../app/dist/examples/openlayers
|
||||
- name: build_app
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
if: ${{ github.ref == 'refs/heads/main' }}
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>PMTiles OpenLayers Vector Example</title>
|
||||
<meta charset="utf-8"/>
|
||||
<script src="https://cdn.jsdelivr.net/npm/ol@v7.3.0/dist/ol.js"></script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@v7.3.0/ol.css">
|
||||
<script src="https://unpkg.com/pmtiles@2.7.2/dist/index.js"></script>
|
||||
<style>
|
||||
body, #map {
|
||||
height:100vh;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map"></div>
|
||||
<script type="text/javascript">
|
||||
class VectorPMTilesSource extends ol.source.VectorTile {
|
||||
tileLoadFunction = (tile,url) => {
|
||||
// the URL construction is done internally by OL, so we need to parse it
|
||||
// back out here using a hacky regex
|
||||
const re = new RegExp(/pmtiles:\/\/(.+)\/(\d+)\/(\d+)\/(\d+)/);
|
||||
const result = url.match(re);
|
||||
const z = +result[2];
|
||||
const x = +result[3];
|
||||
const y = +result[4];
|
||||
|
||||
tile.setLoader((extent, resolution, projection) => {
|
||||
tile.setState(1); // LOADING
|
||||
this._p.getZxy(z,x,y).then((tile_result) => {
|
||||
if (tile_result) {
|
||||
const format = tile.getFormat();
|
||||
const features = format.readFeatures(tile_result.data.buffer, {
|
||||
extent: extent,
|
||||
featureProjection: projection
|
||||
});
|
||||
tile.setFeatures(features);
|
||||
tile.setState(2); // LOADED
|
||||
} else {
|
||||
tile.setFeatures([]);
|
||||
tile.setState(4); // EMPTY
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
super({
|
||||
state:"loading",
|
||||
url: "pmtiles://" + options.url + "/{z}/{x}/{y}",
|
||||
format: new ol.format.MVT(),
|
||||
attributions: options.attributions
|
||||
});
|
||||
|
||||
this._p = new pmtiles.PMTiles(options.url);
|
||||
this._p.getHeader().then(h => {
|
||||
if (h.tileType !== pmtiles.TileType.Mvt) {
|
||||
console.warn("Warning: pmtiles tile type is not mvt");
|
||||
}
|
||||
this.tileGrid.minZoom = h.minZoom;
|
||||
this.tileGrid.maxZoom = h.maxZoom;
|
||||
this.setTileLoadFunction(this.tileLoadFunction);
|
||||
this.setState("ready");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const vectorLayer = new ol.layer.VectorTile({
|
||||
declutter: true,
|
||||
source: new VectorPMTilesSource({
|
||||
url: "https://r2-public.protomaps.com/protomaps-sample-datasets/nz-buildings-v3.pmtiles",
|
||||
attributions: ["© Land Information New Zealand"]
|
||||
}),
|
||||
style: new ol.style.Style({
|
||||
stroke: new ol.style.Stroke({
|
||||
color: 'gray',
|
||||
width: 1,
|
||||
}),
|
||||
fill: new ol.style.Fill({
|
||||
color: 'rgba(20,20,20,0.9)',
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
ol.proj.useGeographic();
|
||||
const map = new ol.Map({
|
||||
layers: [vectorLayer],
|
||||
target: 'map',
|
||||
view: new ol.View({
|
||||
center: [172.606201,-43.556510],
|
||||
zoom: 7
|
||||
}),
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,75 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>PMTiles OpenLayers Raster Example</title>
|
||||
<meta charset="utf-8"/>
|
||||
<script src="https://cdn.jsdelivr.net/npm/ol@v7.3.0/dist/ol.js"></script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@v7.3.0/ol.css">
|
||||
<script src="https://unpkg.com/pmtiles@2.7.2/dist/index.js"></script>
|
||||
<style>
|
||||
body, #map {
|
||||
height:100vh;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map"></div>
|
||||
<script type="text/javascript">
|
||||
class RasterPMTilesSource extends ol.source.DataTile {
|
||||
loadImage = (src) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const img = new Image();
|
||||
img.addEventListener('load', () => resolve(img));
|
||||
img.addEventListener('error', () => reject(new Error('load failed')));
|
||||
img.src = src;
|
||||
});
|
||||
}
|
||||
|
||||
constructor(options) {
|
||||
super({
|
||||
state: "loading",
|
||||
attributions: options.attributions,
|
||||
tileSize: options.tileSize
|
||||
});
|
||||
|
||||
const p = new pmtiles.PMTiles(options.url);
|
||||
p.getHeader().then(h => {
|
||||
if (h.tileType !== pmtiles.TileType.Jpeg && h.tileType !== pmtiles.TileType.Png && h.tileType !== pmtiles.TileType.Webp) {
|
||||
console.warn("Warning: pmtiles tile type is not jpeg, png, or webp");
|
||||
}
|
||||
this.tileGrid.minZoom = h.minZoom;
|
||||
this.tileGrid.maxZoom = h.maxZoom;
|
||||
this.setLoader(async (z,x,y) => {
|
||||
const response = await p.getZxy(z, x, y);
|
||||
const blob = new Blob([response.data]);
|
||||
const src = URL.createObjectURL(blob);
|
||||
const image = await this.loadImage(src);
|
||||
URL.revokeObjectURL(src);
|
||||
return image;
|
||||
});
|
||||
this.setState("ready");
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const rasterLayer = new ol.layer.WebGLTile({
|
||||
source: new RasterPMTilesSource({
|
||||
url:"https://r2-public.protomaps.com/protomaps-sample-datasets/terrarium_z9.pmtiles",
|
||||
attributions:["https://github.com/tilezen/joerd/blob/master/docs/attribution.md"],
|
||||
tileSize: [512,512]
|
||||
})
|
||||
});
|
||||
|
||||
ol.proj.useGeographic();
|
||||
const map = new ol.Map({
|
||||
layers: [rasterLayer],
|
||||
target: 'map',
|
||||
view: new ol.View({
|
||||
center: [0,0],
|
||||
zoom: 1,
|
||||
multiWorld: true
|
||||
}),
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
1
openlayers/.gitignore
vendored
Normal file
1
openlayers/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
dist
|
||||
39
openlayers/examples/raster.html
Normal file
39
openlayers/examples/raster.html
Normal file
@@ -0,0 +1,39 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>PMTiles OpenLayers Raster Example</title>
|
||||
<meta charset="utf-8"/>
|
||||
<script src="https://cdn.jsdelivr.net/npm/ol@v7.3.0/dist/ol.js"></script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@v7.3.0/ol.css">
|
||||
<script src="https://unpkg.com/ol-pmtiles@0.1.0/dist/olpmtiles.js"></script>
|
||||
<style>
|
||||
body, #map {
|
||||
height:100vh;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map"></div>
|
||||
<script type="text/javascript">
|
||||
const rasterLayer = new ol.layer.WebGLTile({
|
||||
source: new olpmtiles.PMTilesRasterSource({
|
||||
url:"https://r2-public.protomaps.com/protomaps-sample-datasets/terrarium_z9.pmtiles",
|
||||
attributions:["https://github.com/tilezen/joerd/blob/master/docs/attribution.md"],
|
||||
tileSize: [512,512]
|
||||
})
|
||||
});
|
||||
|
||||
ol.proj.useGeographic();
|
||||
|
||||
const map = new ol.Map({
|
||||
layers: [rasterLayer],
|
||||
target: 'map',
|
||||
view: new ol.View({
|
||||
center: [0,0],
|
||||
zoom: 1,
|
||||
multiWorld: true
|
||||
}),
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
46
openlayers/examples/vector.html
Normal file
46
openlayers/examples/vector.html
Normal file
@@ -0,0 +1,46 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>PMTiles OpenLayers Vector Example</title>
|
||||
<meta charset="utf-8"/>
|
||||
<script src="https://cdn.jsdelivr.net/npm/ol@v7.3.0/dist/ol.js"></script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@v7.3.0/ol.css">
|
||||
<script src="https://unpkg.com/ol-pmtiles@0.1.0/dist/olpmtiles.js"></script>
|
||||
<style>
|
||||
body, #map {
|
||||
height:100vh;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map"></div>
|
||||
<script type="text/javascript">
|
||||
const vectorLayer = new ol.layer.VectorTile({
|
||||
declutter: true,
|
||||
source: new olpmtiles.PMTilesVectorSource({
|
||||
url: "https://r2-public.protomaps.com/protomaps-sample-datasets/nz-buildings-v3.pmtiles",
|
||||
attributions: ["© Land Information New Zealand"]
|
||||
}),
|
||||
style: new ol.style.Style({
|
||||
stroke: new ol.style.Stroke({
|
||||
color: 'gray',
|
||||
width: 1,
|
||||
}),
|
||||
fill: new ol.style.Fill({
|
||||
color: 'rgba(20,20,20,0.9)',
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
ol.proj.useGeographic();
|
||||
const map = new ol.Map({
|
||||
layers: [vectorLayer],
|
||||
target: 'map',
|
||||
view: new ol.View({
|
||||
center: [172.606201,-43.556510],
|
||||
zoom: 7
|
||||
}),
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
397
openlayers/package-lock.json
generated
397
openlayers/package-lock.json
generated
@@ -1,21 +1,55 @@
|
||||
{
|
||||
"name": "ol-pmtiles",
|
||||
"version": "0.0.3",
|
||||
"version": "0.1.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "ol-pmtiles",
|
||||
"version": "0.0.3",
|
||||
"version": "0.1.0",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"pmtiles": "^2.7.0"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"devDependencies": {
|
||||
"esbuild": "^0.15.11"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"ol": ">=7.3.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/android-arm": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.15.18.tgz",
|
||||
"integrity": "sha512-5GT+kcs2WVGjVs7+boataCkO5Fg0y4kCjzkB5bAip7H4jfnOS3dA6KPiww9W1OEKTKeAcUVhdZGvgI65OXmUnw==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"android"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-loong64": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.15.18.tgz",
|
||||
"integrity": "sha512-L4jVKS82XVhw2nvzLg/19ClLWg0y27ulRwuP7lcyL6AbUWB5aPglXY3M21mauDQMDfRLs8cQmeT03r/+X3cZYQ==",
|
||||
"cpu": [
|
||||
"loong64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@mapbox/jsonlint-lines-primitives": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@mapbox/jsonlint-lines-primitives/-/jsonlint-lines-primitives-2.0.2.tgz",
|
||||
@@ -77,6 +111,363 @@
|
||||
"integrity": "sha512-/pjZsA1b4RPHbeWZQn66SWS8nZZWLQQ23oE3Eam7aroEFGEvwKAsJfZ9ytiEMycfzXWpca4FA9QIOehf7PocBQ==",
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/esbuild": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.15.18.tgz",
|
||||
"integrity": "sha512-x/R72SmW3sSFRm5zrrIjAhCeQSAWoni3CmHEqfQrZIQTM3lVCdehdwuIqaOtfC2slvpdlLa62GYoN8SxT23m6Q==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"bin": {
|
||||
"esbuild": "bin/esbuild"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@esbuild/android-arm": "0.15.18",
|
||||
"@esbuild/linux-loong64": "0.15.18",
|
||||
"esbuild-android-64": "0.15.18",
|
||||
"esbuild-android-arm64": "0.15.18",
|
||||
"esbuild-darwin-64": "0.15.18",
|
||||
"esbuild-darwin-arm64": "0.15.18",
|
||||
"esbuild-freebsd-64": "0.15.18",
|
||||
"esbuild-freebsd-arm64": "0.15.18",
|
||||
"esbuild-linux-32": "0.15.18",
|
||||
"esbuild-linux-64": "0.15.18",
|
||||
"esbuild-linux-arm": "0.15.18",
|
||||
"esbuild-linux-arm64": "0.15.18",
|
||||
"esbuild-linux-mips64le": "0.15.18",
|
||||
"esbuild-linux-ppc64le": "0.15.18",
|
||||
"esbuild-linux-riscv64": "0.15.18",
|
||||
"esbuild-linux-s390x": "0.15.18",
|
||||
"esbuild-netbsd-64": "0.15.18",
|
||||
"esbuild-openbsd-64": "0.15.18",
|
||||
"esbuild-sunos-64": "0.15.18",
|
||||
"esbuild-windows-32": "0.15.18",
|
||||
"esbuild-windows-64": "0.15.18",
|
||||
"esbuild-windows-arm64": "0.15.18"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-android-64": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-android-64/-/esbuild-android-64-0.15.18.tgz",
|
||||
"integrity": "sha512-wnpt3OXRhcjfIDSZu9bnzT4/TNTDsOUvip0foZOUBG7QbSt//w3QV4FInVJxNhKc/ErhUxc5z4QjHtMi7/TbgA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"android"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-android-arm64": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-android-arm64/-/esbuild-android-arm64-0.15.18.tgz",
|
||||
"integrity": "sha512-G4xu89B8FCzav9XU8EjsXacCKSG2FT7wW9J6hOc18soEHJdtWu03L3TQDGf0geNxfLTtxENKBzMSq9LlbjS8OQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"android"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-darwin-64": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.15.18.tgz",
|
||||
"integrity": "sha512-2WAvs95uPnVJPuYKP0Eqx+Dl/jaYseZEUUT1sjg97TJa4oBtbAKnPnl3b5M9l51/nbx7+QAEtuummJZW0sBEmg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-darwin-arm64": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.15.18.tgz",
|
||||
"integrity": "sha512-tKPSxcTJ5OmNb1btVikATJ8NftlyNlc8BVNtyT/UAr62JFOhwHlnoPrhYWz09akBLHI9nElFVfWSTSRsrZiDUA==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-freebsd-64": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-freebsd-64/-/esbuild-freebsd-64-0.15.18.tgz",
|
||||
"integrity": "sha512-TT3uBUxkteAjR1QbsmvSsjpKjOX6UkCstr8nMr+q7zi3NuZ1oIpa8U41Y8I8dJH2fJgdC3Dj3CXO5biLQpfdZA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"freebsd"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-freebsd-arm64": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.15.18.tgz",
|
||||
"integrity": "sha512-R/oVr+X3Tkh+S0+tL41wRMbdWtpWB8hEAMsOXDumSSa6qJR89U0S/PpLXrGF7Wk/JykfpWNokERUpCeHDl47wA==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"freebsd"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-linux-32": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-linux-32/-/esbuild-linux-32-0.15.18.tgz",
|
||||
"integrity": "sha512-lphF3HiCSYtaa9p1DtXndiQEeQDKPl9eN/XNoBf2amEghugNuqXNZA/ZovthNE2aa4EN43WroO0B85xVSjYkbg==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-linux-64": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.15.18.tgz",
|
||||
"integrity": "sha512-hNSeP97IviD7oxLKFuii5sDPJ+QHeiFTFLoLm7NZQligur8poNOWGIgpQ7Qf8Balb69hptMZzyOBIPtY09GZYw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-linux-arm": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-linux-arm/-/esbuild-linux-arm-0.15.18.tgz",
|
||||
"integrity": "sha512-UH779gstRblS4aoS2qpMl3wjg7U0j+ygu3GjIeTonCcN79ZvpPee12Qun3vcdxX+37O5LFxz39XeW2I9bybMVA==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-linux-arm64": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-linux-arm64/-/esbuild-linux-arm64-0.15.18.tgz",
|
||||
"integrity": "sha512-54qr8kg/6ilcxd+0V3h9rjT4qmjc0CccMVWrjOEM/pEcUzt8X62HfBSeZfT2ECpM7104mk4yfQXkosY8Quptug==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-linux-mips64le": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.15.18.tgz",
|
||||
"integrity": "sha512-Mk6Ppwzzz3YbMl/ZZL2P0q1tnYqh/trYZ1VfNP47C31yT0K8t9s7Z077QrDA/guU60tGNp2GOwCQnp+DYv7bxQ==",
|
||||
"cpu": [
|
||||
"mips64el"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-linux-ppc64le": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.15.18.tgz",
|
||||
"integrity": "sha512-b0XkN4pL9WUulPTa/VKHx2wLCgvIAbgwABGnKMY19WhKZPT+8BxhZdqz6EgkqCLld7X5qiCY2F/bfpUUlnFZ9w==",
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-linux-riscv64": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.15.18.tgz",
|
||||
"integrity": "sha512-ba2COaoF5wL6VLZWn04k+ACZjZ6NYniMSQStodFKH/Pu6RxzQqzsmjR1t9QC89VYJxBeyVPTaHuBMCejl3O/xg==",
|
||||
"cpu": [
|
||||
"riscv64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-linux-s390x": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-linux-s390x/-/esbuild-linux-s390x-0.15.18.tgz",
|
||||
"integrity": "sha512-VbpGuXEl5FCs1wDVp93O8UIzl3ZrglgnSQ+Hu79g7hZu6te6/YHgVJxCM2SqfIila0J3k0csfnf8VD2W7u2kzQ==",
|
||||
"cpu": [
|
||||
"s390x"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-netbsd-64": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-netbsd-64/-/esbuild-netbsd-64-0.15.18.tgz",
|
||||
"integrity": "sha512-98ukeCdvdX7wr1vUYQzKo4kQ0N2p27H7I11maINv73fVEXt2kyh4K4m9f35U1K43Xc2QGXlzAw0K9yoU7JUjOg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"netbsd"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-openbsd-64": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-openbsd-64/-/esbuild-openbsd-64-0.15.18.tgz",
|
||||
"integrity": "sha512-yK5NCcH31Uae076AyQAXeJzt/vxIo9+omZRKj1pauhk3ITuADzuOx5N2fdHrAKPxN+zH3w96uFKlY7yIn490xQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"openbsd"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-sunos-64": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-sunos-64/-/esbuild-sunos-64-0.15.18.tgz",
|
||||
"integrity": "sha512-On22LLFlBeLNj/YF3FT+cXcyKPEI263nflYlAhz5crxtp3yRG1Ugfr7ITyxmCmjm4vbN/dGrb/B7w7U8yJR9yw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"sunos"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-windows-32": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-windows-32/-/esbuild-windows-32-0.15.18.tgz",
|
||||
"integrity": "sha512-o+eyLu2MjVny/nt+E0uPnBxYuJHBvho8vWsC2lV61A7wwTWC3jkN2w36jtA+yv1UgYkHRihPuQsL23hsCYGcOQ==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-windows-64": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.15.18.tgz",
|
||||
"integrity": "sha512-qinug1iTTaIIrCorAUjR0fcBk24fjzEedFYhhispP8Oc7SFvs+XeW3YpAKiKp8dRpizl4YYAhxMjlftAMJiaUw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-windows-arm64": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-windows-arm64/-/esbuild-windows-arm64-0.15.18.tgz",
|
||||
"integrity": "sha512-q9bsYzegpZcLziq0zgUi5KqGVtfhjxGbnksaBFYmWLxeV/S1fK4OLdq2DFYnXcLMjlZw2L0jLsk1eGoB522WXQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/fflate": {
|
||||
"version": "0.7.4",
|
||||
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.7.4.tgz",
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
{
|
||||
"name": "ol-pmtiles",
|
||||
"version": "0.0.3",
|
||||
"version": "0.1.0",
|
||||
"description": "PMTiles sources for OpenLayers",
|
||||
"type": "module",
|
||||
"main": "src/index.js",
|
||||
"files": [
|
||||
"dist/olpmtiles.js",
|
||||
"src/index.js"
|
||||
],
|
||||
"repository": {
|
||||
@@ -20,6 +21,7 @@
|
||||
],
|
||||
"license": "BSD-3-Clause",
|
||||
"scripts": {
|
||||
"build-iife": "esbuild src/script_includes.js --outfile=dist/olpmtiles.js --target=es6 --global-name=olpmtiles --bundle --format=iife",
|
||||
"prettier": "prettier --write *.js",
|
||||
"prettier-check": "prettier --check *.js"
|
||||
},
|
||||
@@ -27,6 +29,7 @@
|
||||
"pmtiles": "^2.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"esbuild": "^0.15.11"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"ol": ">=7.3.0"
|
||||
|
||||
98
openlayers/src/script_includes.js
Normal file
98
openlayers/src/script_includes.js
Normal file
@@ -0,0 +1,98 @@
|
||||
// IMPORTANT: this file is manually edited!
|
||||
// copy any changes made from src/index.js to here
|
||||
|
||||
// import DataTile from "ol/source/DataTile";
|
||||
// import VectorTile from "ol/source/VectorTile";
|
||||
// import TileState from "ol/TileState";
|
||||
// import { MVT } from "ol/format";
|
||||
import * as pmtiles from "pmtiles";
|
||||
|
||||
export class PMTilesRasterSource extends ol.source.DataTile {
|
||||
loadImage = (src) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const img = new Image();
|
||||
img.addEventListener("load", () => resolve(img));
|
||||
img.addEventListener("error", () => reject(new Error("load failed")));
|
||||
img.src = src;
|
||||
});
|
||||
};
|
||||
|
||||
constructor(options) {
|
||||
super({
|
||||
...options,
|
||||
...{
|
||||
state: "loading",
|
||||
},
|
||||
});
|
||||
|
||||
const p = new pmtiles.PMTiles(options.url);
|
||||
p.getHeader().then((h) => {
|
||||
this.tileGrid.minZoom = h.minZoom;
|
||||
this.tileGrid.maxZoom = h.maxZoom;
|
||||
this.setLoader(async (z, x, y) => {
|
||||
const response = await p.getZxy(z, x, y);
|
||||
const src = URL.createObjectURL(new Blob([response.data]));
|
||||
const image = await this.loadImage(src);
|
||||
URL.revokeObjectURL(src);
|
||||
return image;
|
||||
});
|
||||
this.setState("ready");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class PMTilesVectorSource extends ol.source.VectorTile {
|
||||
tileLoadFunction = (tile, url) => {
|
||||
// the URL construction is done internally by OL, so we need to parse it
|
||||
// back out here using a hacky regex
|
||||
const re = new RegExp(/pmtiles:\/\/(.+)\/(\d+)\/(\d+)\/(\d+)/);
|
||||
const result = url.match(re);
|
||||
const z = +result[2];
|
||||
const x = +result[3];
|
||||
const y = +result[4];
|
||||
|
||||
tile.setLoader((extent, resolution, projection) => {
|
||||
tile.setState(1);
|
||||
this.pmtiles_
|
||||
.getZxy(z, x, y)
|
||||
.then((tile_result) => {
|
||||
if (tile_result) {
|
||||
const format = tile.getFormat();
|
||||
tile.setFeatures(
|
||||
format.readFeatures(tile_result.data.buffer, {
|
||||
extent: extent,
|
||||
featureProjection: projection,
|
||||
})
|
||||
);
|
||||
tile.setState(2);
|
||||
} else {
|
||||
tile.setFeatures([]);
|
||||
tile.setState(4);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
tile.setFeatures([]);
|
||||
tile.setState(3);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
constructor(options) {
|
||||
super({
|
||||
...options,
|
||||
...{
|
||||
state: "loading",
|
||||
url: "pmtiles://" + options.url + "/{z}/{x}/{y}",
|
||||
format: new ol.format.MVT(),
|
||||
},
|
||||
});
|
||||
|
||||
this.pmtiles_ = new pmtiles.PMTiles(options.url);
|
||||
this.pmtiles_.getHeader().then((h) => {
|
||||
this.tileGrid.minZoom = h.minZoom;
|
||||
this.tileGrid.maxZoom = h.maxZoom;
|
||||
this.setTileLoadFunction(this.tileLoadFunction);
|
||||
this.setState("ready");
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user