Skip to content

Commit

Permalink
CARTO: Add worker for cartoPropertiesTile loader (#9429)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixpalmer authored Feb 14, 2025
1 parent 705d0c3 commit 8721dfd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion modules/carto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"sideEffects": false,
"scripts": {
"build-bundle": "npm run build-workers && ocular-bundle ./bundle.ts",
"build-workers": "npm run build-worker --cartoloader=RasterTile && npm run build-worker --cartoloader=SpatialTile && npm run build-worker --cartoloader=VectorTile",
"build-workers": "npm run build-worker --cartoloader=RasterTile && npm run build-worker --cartoloader=SpatialTile && npm run build-worker --cartoloader=VectorTile && npm run build-worker --cartoloader=PropertiesTile",
"build-worker": "esbuild src/workers/carto$npm_config_cartoloader.ts --bundle --outfile=dist/carto$npm_config_cartoloader-worker.js --define:__VERSION__=\\\"$npm_package_version\\\"",
"prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env=dev"
},
Expand Down
22 changes: 19 additions & 3 deletions modules/carto/src/layers/schema/carto-properties-tile-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,35 @@ import {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';

import {Tile, TileReader} from './carto-properties-tile';
import {parsePbf} from './tile-loader-utils';
import {getWorkerUrl} from '../../utils';

const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
const id = 'cartoPropertiesTile';

type CartoPropertiesTileLoaderOptions = LoaderOptions & {
cartoPropertiesTile?: {
workerUrl: string;
};
};

const DEFAULT_OPTIONS: CartoPropertiesTileLoaderOptions = {
cartoPropertiesTile: {
workerUrl: getWorkerUrl(id, VERSION)
}
};

const CartoPropertiesTileLoader: LoaderWithParser = {
name: 'CARTO Properties Tile',
version: '1',
id: 'cartoPropertiesTile',
version: VERSION,
id,
module: 'carto',
extensions: ['pbf'],
mimeTypes: ['application/vnd.carto-properties-tile'],
category: 'geometry',
worker: true,
parse: async (arrayBuffer, options) => parseCartoPropertiesTile(arrayBuffer, options),
parseSync: parseCartoPropertiesTile,
options: {}
options: DEFAULT_OPTIONS
};

function parseCartoPropertiesTile(arrayBuffer: ArrayBuffer, options?: LoaderOptions): Tile | null {
Expand Down
8 changes: 8 additions & 0 deletions modules/carto/src/workers/cartoPropertiesTile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// deck.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import {createLoaderWorker} from '@loaders.gl/loader-utils';
import CartoPropertiesTileLoader from '../layers/schema/carto-properties-tile-loader';

createLoaderWorker(CartoPropertiesTileLoader);

0 comments on commit 8721dfd

Please sign in to comment.