UNPKG

@elastic/ems-client

Version:

JavaScript client library for the Elastic Maps Service

153 lines (152 loc) 4.43 kB
import { TMSService } from './tms_service'; import { EMSFormatType, FileLayer } from './file_layer'; import { FeatureCollection } from 'geojson'; export declare const LATEST_API_URL_PATH = "latest"; type LocalizedStrings = { [key: string]: string; }; type BaseClientConfig = { appName?: string; manifestServiceUrl?: string; tileApiUrl: string; fileApiUrl: string; emsVersion?: string; htmlSanitizer?: (x: string) => string; language?: string; landingPageUrl?: string; fetchFunction: (url: RequestInfo) => Promise<Response>; proxyPath?: string; cacheSize?: number; }; type DeprecatedClientConfig = BaseClientConfig & { kbnVersion: string; }; type ClientConfig = BaseClientConfig & { appVersion: string; }; type EmsCatalogService = { id?: string; name?: string; manifest: string; type: string; }; type EmsCatalogManifest = { version?: string; services: EmsCatalogService[]; }; type EmsTmsCatalog = { version?: string; services: TMSServiceConfig[]; }; export type EmsTmsFormat = { locale: string; format: string; url: string; }; export type BaseEmsServiceConfig = { attribution: EmsLayerAttribution[]; }; export type FileLayerConfig = BaseEmsServiceConfig & { layer_id: string; created_at: string; formats: (EmsFileLayerFormatGeoJson | EmsFileLayerFormatTopoJson)[]; fields: FileLayerField[]; legacy_ids: string[]; layer_name: LocalizedStrings; }; export type FileLayerField = { type: string; id: string; label: LocalizedStrings; values?: string[]; regex?: string; alias?: string[]; }; export type TMSServiceConfig = BaseEmsServiceConfig & { id: string; name: { en: string; }; formats: EmsTmsFormat[]; }; type EmsFileCatalog = { version?: string; layers: FileLayerConfig[]; }; export type EmsLayerAttribution = { label: LocalizedStrings; url: LocalizedStrings; }; export type EmsFileLayerFormatGeoJson = { type: EMSFormatType.geojson; url: string; legacy_default: boolean; }; export type EmsFileLayerFormatTopoJson = { type: EMSFormatType.topojson; url: string; legacy_default: boolean; meta: { feature_collection_path: string; }; }; export declare class EMSClient { readonly EMS_LOAD_TIMEOUT = 32000; private _queryParams; private readonly _appVersion; private readonly _fetchFunction; private readonly _sanitizer; private readonly _fileApiUrl; private readonly _tileApiUrl; private readonly _emsVersion; private readonly _emsLandingPageUrl; private readonly _language; private readonly _proxyPath; private readonly _cache; private readonly _isRestApi; /** * these methods are assigned outside the constructor */ private _getMainCatalog; private _getDefaultTMSCatalog; private _getDefaultFileCatalog; private _loadTMSServices; private _loadFileLayers; constructor(config: ClientConfig | DeprecatedClientConfig); getDefaultLocale(): string; getLocale(): string; getValueInLanguage(i18nObject: { [language: string]: string; }): string; /** * this internal method is overridden by the tests to simulate custom manifest. */ getManifest<T>(endpointUrl: string): Promise<T>; /** * Add optional query-parameters to all requests * * @param additionalQueryParams */ addQueryParams(additionalQueryParams: { [key: string]: string; }): void; getMainManifest(): Promise<EmsCatalogManifest>; getDefaultFileManifest(): Promise<EmsFileCatalog>; getDefaultTMSManifest(): Promise<EmsTmsCatalog>; getFileLayers(): Promise<FileLayer[]>; getTMSServices(): Promise<TMSService[]>; cacheGeoJson(layerId: string, geoJson: FeatureCollection): void; getCachedGeoJson(layerId: string): FeatureCollection<import("geojson").Geometry, import("geojson").GeoJsonProperties> | undefined; getEmsVersion(): string; getTileApiUrl(): string; getFileApiUrl(): string; getLandingPageUrl(): string; sanitizeHtml(html: string): string; extendUrlWithParams(url: string): string; findFileLayerById(id: string): Promise<FileLayer | undefined>; findTMSServiceById(id: string): Promise<TMSService | undefined>; private _getEmsVersion; private _fetchWithTimeout; private _invalidateSettings; } export {};