Skip to content

Commit

Permalink
Merge pull request #2 from proximiio/feat/source-management
Browse files Browse the repository at this point in the history
feat: source management
  • Loading branch information
wirrareka authored Oct 16, 2024
2 parents 3035a7f + 4b1cfe1 commit f0a8f46
Showing 1 changed file with 131 additions and 1 deletion.
132 changes: 131 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string>;
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<string>;
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<string>;
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<string>;
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);
}
Expand All @@ -123,6 +232,27 @@ export class ProximiioMap extends Component<Props> {
return result as boolean;
}

async addSource(id: string, source: SourceSpecification): Promise<boolean> {
const params = `'${id}', '${JSON.stringify(source)}'`;
const result = await this.asyncTask(Action.addSource, params);
return result as boolean;
}

async getSource(id: string): Promise<SourceInfo | undefined> {
const result = await this.asyncTask(Action.getSource, `'${id}'`);
return result as SourceInfo | undefined;
}

async hasSource(id: string): Promise<boolean> {
const result = await this.asyncTask(Action.hasSource, `'${id}'`);
return result as boolean;
}

async removeSource(id: string): Promise<boolean> {
const result = await this.asyncTask(Action.removeSource, `'${id}'`);
return result as boolean;
}

setCenter(lat: number, lng: number) {
this.dispatch(`mapController.setCenter(${lat}, ${lng});`);
}
Expand Down

0 comments on commit f0a8f46

Please sign in to comment.