Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: source management #2

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading