@map.ir/services-sdk
Version:
JavaScript/TypeScript SDK for map.ir services
83 lines (82 loc) • 2.35 kB
TypeScript
import route from "./route";
import type { Point } from "geojson";
import type { LngLat } from "./types";
export default class Mapir {
apiKey: string;
baseURL?: string;
constructor(opt?: IConstructorOptions);
search(text: string, location: LngLat, autocomplete?: boolean): Promise<ISearchResult | undefined>;
reverseGeocode(location: LngLat): Promise<IReverseResult | undefined>;
route: typeof route;
staticMap(location: [LngLat] | [LngLat, LngLat], options?: IStaticMapOptions): Promise<Blob | undefined>;
}
export interface IConstructorOptions {
apiKey?: string;
baseURL?: string;
}
export type SearchMethod = "POST";
export interface ISearchPayload {
location: Point;
returnid: boolean;
text: string;
}
export interface ISearchResult {
"odata.count": number;
request_id: number;
value: Array<{
Address: string;
City: string;
Coordinate: {
lat: number;
lon: number;
};
FClass: string;
Id: string;
Province: string;
Text: string;
Title: string;
Type: string;
}>;
}
export type ReverseMethod = "POST";
export interface IReversePayload extends Record<string, string> {
lat: `${number}`;
lon: `${number}`;
}
export interface IReverseResult {
address: string;
address_compact: string;
city: string;
country: string;
county: string;
district: string;
geom: Point;
last: string;
name: string;
neighbourhood: string;
penult: string;
plaque: string;
poi: string;
postal_address: string;
postal_code: string;
primary: string;
province: string;
region: string;
rural_district: string;
village: string;
}
export interface IStaticMapOptions {
width?: number | `${number}`;
height?: number | `${number}`;
colors?: [string] | [string, string];
labels?: [string] | [string, string];
zoom?: number | `${number}`;
}
export type StaticMapMethod = "GET";
export interface IStaticMapPayload extends Record<string, string> {
width: `${number}`;
height: `${number}`;
markers: `color:${"red" | "blue"}|${number},${number}|${string}`;
zoom_level: `${number}`;
}
export type StaticMapResult = Blob;