diff --git a/src/index.tsx b/src/index.tsx index d4db115..ca86285 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -36,7 +36,7 @@ interface Props { } const uri = - 'https://proximiio-map-mobile.ams3.cdn.digitaloceanspaces.com/1.0.0-b17/index.html'; + 'https://proximiio-map-mobile.ams3.cdn.digitaloceanspaces.com/1.0.0-b18/index.html'; export interface Feature { id: string; @@ -96,8 +96,117 @@ enum Action { addImage = 'addImage', hasImage = 'hasImage', removeImage = 'removeImage', + addSource = 'addSource', + getSource = 'getSource', + hasSource = 'hasSource', + removeSource = 'removeSource', } +export type PromoteIdSpecification = + | { + [_: string]: string; + } + | string; + +export type VectorSourceSpecification = { + type: 'vector'; + url?: string; + tiles?: Array; + bounds?: [number, number, number, number]; + scheme?: 'xyz' | 'tms'; + minzoom?: number; + maxzoom?: number; + attribution?: string; + promoteId?: PromoteIdSpecification; + volatile?: boolean; +}; + +export type RasterSourceSpecification = { + type: 'raster'; + url?: string; + tiles?: Array; + bounds?: [number, number, number, number]; + minzoom?: number; + maxzoom?: number; + tileSize?: number; + scheme?: 'xyz' | 'tms'; + attribution?: string; + volatile?: boolean; +}; + +export type RasterDEMSourceSpecification = { + type: 'raster-dem'; + url?: string; + tiles?: Array; + bounds?: [number, number, number, number]; + minzoom?: number; + maxzoom?: number; + tileSize?: number; + attribution?: string; + encoding?: 'terrarium' | 'mapbox' | 'custom'; + redFactor?: number; + blueFactor?: number; + greenFactor?: number; + baseShift?: number; + volatile?: boolean; +}; + +export type GeoJSONSourceSpecification = { + type: 'geojson'; + data: GeoJSON.GeoJSON | string; + maxzoom?: number; + attribution?: string; + buffer?: number; + filter?: unknown; + tolerance?: number; + cluster?: boolean; + clusterRadius?: number; + clusterMaxZoom?: number; + clusterMinPoints?: number; + clusterProperties?: unknown; + lineMetrics?: boolean; + generateId?: boolean; + promoteId?: PromoteIdSpecification; +}; + +export type VideoSourceSpecification = { + type: 'video'; + urls: Array; + coordinates: [ + [number, number], + [number, number], + [number, number], + [number, number], + ]; +}; + +export type ImageSourceSpecification = { + type: 'image'; + url: string; + coordinates: [ + [number, number], + [number, number], + [number, number], + [number, number], + ]; +}; + +export type SourceSpecification = + | VectorSourceSpecification + | RasterSourceSpecification + | RasterDEMSourceSpecification + | GeoJSONSourceSpecification + | VideoSourceSpecification + | ImageSourceSpecification; + +export type SourceInfo = { + id?: string; + type?: 'geojson' | 'vector' | 'raster' | 'raster-dem' | 'video' | 'image'; + minzoom?: number; + maxzoom?: number; + loaded: boolean; +}; + export function metersToSteps(meters: number) { return Math.round(meters * 1.31234); } @@ -123,6 +232,27 @@ export class ProximiioMap extends Component { return result as boolean; } + async addSource(id: string, source: SourceSpecification): Promise { + const params = `'${id}', '${JSON.stringify(source)}'`; + const result = await this.asyncTask(Action.addSource, params); + return result as boolean; + } + + async getSource(id: string): Promise { + const result = await this.asyncTask(Action.getSource, `'${id}'`); + return result as SourceInfo | undefined; + } + + async hasSource(id: string): Promise { + const result = await this.asyncTask(Action.hasSource, `'${id}'`); + return result as boolean; + } + + async removeSource(id: string): Promise { + const result = await this.asyncTask(Action.removeSource, `'${id}'`); + return result as boolean; + } + setCenter(lat: number, lng: number) { this.dispatch(`mapController.setCenter(${lat}, ${lng});`); }