Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial MLT support #1

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 61 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@mapbox/vector-tile": "^1.3.1",
"@mapbox/whoots-js": "^3.1.0",
"@maplibre/maplibre-gl-style-spec": "^20.3.0",
"@maplibre/maplibre-tile-spec": "^0.0.1-alpha.4",
"@types/geojson": "^7946.0.14",
"@types/geojson-vt": "3.2.5",
"@types/junit-report-builder": "^3.0.2",
Expand Down
4 changes: 4 additions & 0 deletions src/source/vector_tile_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,12 @@ export class VectorTileSource extends Evented implements Source {

async loadTile(tile: Tile): Promise<void> {
const url = tile.tileID.canonical.url(this.tiles, this.map.getPixelRatio(), this.scheme);
// Note: this need to load a separate meta.pbf is temporary and will not exist in the near future.
// See https://github.com/maplibre/maplibre-tile-spec/issues/214 for details
const metadataUrl = tile.tileID.canonical.url(this.tiles, this.map.getPixelRatio(), this.scheme) + '.meta.pbf';
ebrelsford marked this conversation as resolved.
Show resolved Hide resolved
const params = {
request: this.map._requestManager.transformRequest(url, ResourceType.Tile),
metadataRequest: this.map._requestManager.transformRequest(metadataUrl, ResourceType.Tile),
uid: tile.uid,
tileID: tile.tileID,
zoom: tile.tileID.overscaledZ,
Expand Down
15 changes: 13 additions & 2 deletions src/source/vector_tile_worker_source.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {ExpiryData, getArrayBuffer} from '../util/ajax';

import vt from '@mapbox/vector-tile';
import { MltDecoder, TileSetMetadata } from '@maplibre/maplibre-tile-spec';
import * as vt from '@maplibre/maplibre-tile-spec/dist/src/mlt-vector-tile-js';
import Protobuf from 'pbf';
import {WorkerTile} from './worker_tile';
import {extend} from '../util/util';
Expand Down Expand Up @@ -66,8 +67,18 @@ export class VectorTileWorkerSource implements WorkerSource {
*/
async loadVectorTile(params: WorkerTileParameters, abortController: AbortController): Promise<LoadVectorTileResult> {
const response = await getArrayBuffer(params.request, abortController);
const metadataResponse = await getArrayBuffer({
url: params.metadataRequest.url,
}, new AbortController());

try {
const vectorTile = new vt.VectorTile(new Protobuf(response.data));
const metadata = new Uint8Array(metadataResponse.data);
const tilesetMetadata = TileSetMetadata.fromBinary(metadata);

const vectorTile = new vt.VectorTile(
new Uint8Array(response.data),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new Uint8Array allocation may be expensive. We should investigate why this seems needed and how to avoid this so we can pass the response.data directly. Perhaps create a ticket on this and I can take a closer look?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm down to open an issue for this, the root of it is that the decoder needs a Uint8Array but we're getting an ArrayBuffer here. It seems like Uint8Array is the common type between node and the browser here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A similar conversion may be happening in pbf here.

tilesetMetadata,
);
return {
vectorTile,
rawData: response.data,
Expand Down
1 change: 1 addition & 0 deletions src/source/worker_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type TileParameters = {
export type WorkerTileParameters = TileParameters & {
tileID: OverscaledTileID;
request?: RequestParameters;
metadataRequest?: RequestParameters;
zoom: number;
maxZoom?: number;
tileSize: number;
Expand Down