UNPKG

@maptiler/leaflet-maptilersdk

Version:

Vector tiles basemap plugin for Leaflet - multi-lingual basemaps using MapTiler SDK

127 lines (126 loc) 4.6 kB
import { default as L } from 'leaflet'; import { HeatmapLayerOptions, LanguageInfo, MapStyleVariant, PointLayerOptions, PolygonLayerOptions, PolylineLayerOptions, ReferenceMapStyle, StyleSpecification, GeolocationType, Map as MapSDK } from '@maptiler/sdk'; export { Language, MapStyle } from '@maptiler/sdk'; /** * A Maptiler Layer for Leaflet consists in adding a MapTiler SDK Map * inside of Leaflet as a custom layer. */ interface MaptilerLayerInterface extends L.Layer { /** * Get the Maptiler Map instance out of the layer. * This can be convenient to add further events and logic. */ getMaptilerSDKMap: () => MapSDK; /** * Get the HTML Canvas element where the MapTiler Map is * instantiated. */ getCanvas: () => HTMLCanvasElement; /** * Set the style of the internal MapTiler Map instance. * The style can be one of the built-in list (as in `MaptilerStyle`) * or a raw URL. */ setStyle: (s: null | ReferenceMapStyle | MapStyleVariant | StyleSpecification | string) => void; /** * Set the language of the map from the built-in list of * supported languages (see `Language`) */ setLanguage: (l: LanguageInfo | string) => void; /** * Add a heatmap layer from a geoJSON datasource or a * dataset hosted on MapTiler Cloud account. * Read more about helpers at * https://github.com/maptiler/maptiler-sdk-js#vector-layer-helpers */ addHeatmap: (options: HeatmapLayerOptions) => { heatmapLayerId: string; heatmapSourceId: string; }; /** * Add a polygon layer from a geoJSON datasource or a * dataset hosted on MapTiler Cloud account. * Read more about helpers at * https://github.com/maptiler/maptiler-sdk-js#vector-layer-helpers */ addPolygon: (options: PolygonLayerOptions) => { polygonLayerId: string; polygonOutlineLayerId: string; polygonSourceId: string; }; /** * Add a point layer from a geoJSON datasource or a * dataset hosted on MapTiler Cloud account. * Read more about helpers at * https://github.com/maptiler/maptiler-sdk-js#vector-layer-helpers */ addPoint: (options: PointLayerOptions) => { pointLayerId: string; clusterLayerId: string; labelLayerId: string; pointSourceId: string; }; /** * Add a polyline layer from a geoJSON datasource or a * dataset hosted on MapTiler Cloud account. * Read more about helpers at * https://github.com/maptiler/maptiler-sdk-js#vector-layer-helpers */ addPolyline: (options: PolylineLayerOptions) => Promise<{ polylineLayerId: string; polylineOutlineLayerId: string; polylineSourceId: string; }>; /** * Take a screenshot of the displayed map. * Read more about this feature at * https://github.com/maptiler/maptiler-sdk-js#take-screenshots-programmatically */ takeScreenshot: (options?: { download?: boolean; filename?: string; }) => Promise<Blob>; } /** * Options to create a MaptilerLayer */ export type MaptilerLayerOptions = { /** * Maptiler Cloud API key */ apiKey: string; /** * Style hosted on MapTiler Cloud or raw URL. * Default: MapTiler Streets style */ style?: ReferenceMapStyle | MapStyleVariant | StyleSpecification | string; /** * Language for the map to display * Default: uses the language as defined in the style */ language?: LanguageInfo | string; /** * If the value is `true` or `"POINT"` then the positionning uses the MapTiler Cloud * Geolocation to find the non-GPS location point. * * If the value is `"COUNTRY"` then the map is centered around the bounding box of the country. * * If the value is `false`, no geolocation is performed and the map centering and zooming depends on other options or on * the built-in defaults. * * Default: `false` */ geolocate?: (typeof GeolocationType)[keyof typeof GeolocationType] | boolean; }; /** * A Maptiler Layer for Leaflet consists in adding a MapTiler SDK Map * inside of Leaflet as a custom layer. */ export declare const MaptilerLayer: { new (options: MaptilerLayerOptions): MaptilerLayerInterface; } & Omit<typeof L.Layer, "prototype">; /** * Factory function to instantiate a MaptilerLayer. * Does exactly the same as calling `new MaptilerLayer(options)` */ export declare function maptilerLayer(options: MaptilerLayerOptions): MaptilerLayerInterface;