UNPKG

@deck.gl/carto

Version:

CARTO official integration with Deck.gl. Build geospatial applications using CARTO and Deck.gl.

26 lines (21 loc) 824 B
// deck.gl // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors import {NumericProp, NumericPropKeyValueReader, PropertiesReader} from './carto-tile'; // Tile ======================================== export interface Tile { properties: Record<string, string>[]; numericProps: Record<string, NumericProp>; } export class TileReader { static read(pbf, end?: number): Tile { return pbf.readFields(TileReader._readField, {properties: [], numericProps: {}}, end); } static _readField(this: void, tag: number, obj: Tile, pbf) { if (tag === 1) obj.properties.push(PropertiesReader.read(pbf, pbf.readVarint() + pbf.pos)); else if (tag === 2) { const entry = NumericPropKeyValueReader.read(pbf, pbf.readVarint() + pbf.pos); obj.numericProps[entry.key] = entry.value; } } }