-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CARTO: Add example for boundaries (#8269)
- Loading branch information
1 parent
79b3e9d
commit 9a4375c
Showing
13 changed files
with
332 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
modules/carto/src/layers/schema/carto-properties-tile-loader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils'; | ||
|
||
import {Tile, TileReader} from './carto-properties-tile'; | ||
import {parsePbf} from './tile-loader-utils'; | ||
|
||
const CartoPropertiesTileLoader: LoaderWithParser = { | ||
name: 'CARTO Properties Tile', | ||
version: '1', | ||
id: 'cartoPropertiesTile', | ||
module: 'carto', | ||
extensions: ['pbf'], | ||
mimeTypes: ['application/vnd.carto-properties-tile'], | ||
category: 'geometry', | ||
worker: false, | ||
parse: async (arrayBuffer, options) => parseCartoPropertiesTile(arrayBuffer, options), | ||
parseSync: parseCartoPropertiesTile, | ||
options: {} | ||
}; | ||
|
||
function parseCartoPropertiesTile(arrayBuffer: ArrayBuffer, options?: LoaderOptions): Tile | null { | ||
if (!arrayBuffer) return null; | ||
return parsePbf(arrayBuffer, TileReader); | ||
} | ||
|
||
export default CartoPropertiesTileLoader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {QueryParameters} from '../api'; | ||
import {baseSource} from './base-source'; | ||
import type {SourceOptions, TilejsonResult} from './types'; | ||
|
||
export type BoundaryQuerySourceOptions = SourceOptions & { | ||
boundaryId: string; | ||
matchingColumn?: string; | ||
sqlQuery: string; | ||
queryParameters: QueryParameters; | ||
}; | ||
type UrlParameters = { | ||
boundaryId: string; | ||
matchingColumn: string; | ||
sqlQuery: string; | ||
queryParameters?: string; | ||
}; | ||
|
||
export const boundaryQuerySource = async function ( | ||
options: BoundaryQuerySourceOptions | ||
): Promise<TilejsonResult> { | ||
const {boundaryId, matchingColumn = 'id', sqlQuery, queryParameters} = options; | ||
const urlParameters: UrlParameters = { | ||
boundaryId, | ||
matchingColumn, | ||
sqlQuery | ||
}; | ||
if (queryParameters) { | ||
urlParameters.queryParameters = JSON.stringify(queryParameters); | ||
} | ||
return baseSource<UrlParameters>('boundary', options, urlParameters) as Promise<TilejsonResult>; | ||
}; |
Oops, something went wrong.