MapComplete/src/Logic/Geocoding/GeocodingProvider.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

98 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-08-15 01:51:33 +02:00
import { BBox } from "../BBox"
2024-08-21 14:06:42 +02:00
import { Feature, Geometry } from "geojson"
import { DefaultPinIcon } from "../../Models/Constants"
2024-08-22 22:50:37 +02:00
import { Store } from "../UIEventSource"
2024-08-21 14:06:42 +02:00
export type GeocodingCategory = "coordinate" | "city" | "house" | "street" | "locality" | "country" | "train_station" | "county" | "airport"
2024-08-15 01:51:33 +02:00
export type GeoCodeResult = {
2024-08-21 14:06:42 +02:00
/**
* The name of the feature being displayed
*/
2024-08-15 01:51:33 +02:00
display_name: string
2024-08-21 14:06:42 +02:00
/**
* Some optional, extra information
*/
description?: string | Promise<string>,
2024-08-15 01:51:33 +02:00
feature?: Feature,
lat: number
lon: number
/**
* Format:
* [lat, lat, lon, lon]
*/
boundingbox?: number[]
osm_type?: "node" | "way" | "relation"
2024-08-21 14:06:42 +02:00
osm_id?: string,
category?: GeocodingCategory,
payload?: object
2024-08-15 01:51:33 +02:00
}
export interface GeocodingOptions {
bbox?: BBox,
limit?: number
}
export default interface GeocodingProvider {
search(query: string, options?: GeocodingOptions): Promise<GeoCodeResult[]>
/**
* @param query
* @param options
*/
2024-08-22 22:50:37 +02:00
suggest?(query: string, options?: GeocodingOptions): Store<GeoCodeResult[]>
2024-08-15 01:51:33 +02:00
}
2024-08-21 14:06:42 +02:00
export type ReverseGeocodingResult = Feature<Geometry,{
osm_id: number,
osm_type: "node" | "way" | "relation",
country: string,
city: string,
countrycode: string,
type: GeocodingCategory,
street: string
} >
2024-08-15 01:51:33 +02:00
export interface ReverseGeocodingProvider {
reverseSearch(
coordinate: { lon: number; lat: number },
zoom: number,
language?: string
2024-08-21 14:06:42 +02:00
): Promise<ReverseGeocodingResult[]> ;
}
export class GeocodingUtils {
public static categoryToZoomLevel: Record<GeocodingCategory, number> = {
city: 12,
county: 10,
coordinate: 16,
country: 8,
house: 16,
locality: 14,
street: 15,
train_station: 14,
airport: 13
}
public static categoryToIcon: Record<GeocodingCategory, DefaultPinIcon> = {
city: "building_office_2",
coordinate: "globe_alt",
country: "globe_alt",
house: "house",
locality: "building_office_2",
street: "globe_alt",
train_station: "train",
county: "building_office_2",
airport: "airport"
}
2024-08-15 01:51:33 +02:00
}