This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (50 loc) · 1.45 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { MVTLayer } from "deck.gl";
import { PMTiles } from "pmtiles";
export class PMTilesLayer extends MVTLayer {
static layerName = "PMTilesLayer";
async _updateTileData() {
let data = this.props.data;
let tileJSON = null;
let pmtiles = new PMTiles(data);
this.setState({ data, tileJSON, pmtiles });
}
getTileData(loadProps) {
const { data, binary, pmtiles } = this.state;
const { index, signal } = loadProps;
const { x, y, z } = index;
let loadOptions = this.getLoadOptions();
const { fetch } = this.props;
const zxyPromise = pmtiles.getZxy(z, x, y);
return zxyPromise.then((val) => {
if (!val) {
return null;
}
loadOptions = {
...loadOptions,
mimeType: "application/x-protobuf",
mvt: {
...loadOptions?.mvt,
coordinates: this.context.viewport.resolution ? "wgs84" : "local",
tileIndex: index,
// Local worker debug
// workerUrl: `modules/mvt/dist/mvt-loader.worker.js`
// Set worker to null to skip web workers
// workerUrl: null
},
gis: binary ? { format: "binary" } : {},
fetch: {
headers: {
Range: "bytes=" + val.offset + "-" + (val.offset + val.length - 1),
},
},
};
return fetch(data, {
propName: "data",
layer: this,
loadOptions,
signal,
});
});
}
}
export default PMTilesLayer;