@maptiler/sdk 2.2.2 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/maptiler-sdk.css +1 -1
- package/dist/maptiler-sdk.mjs +8468 -1404
- package/dist/maptiler-sdk.mjs.map +1 -1
- package/dist/src/Map.d.ts +13 -4
- package/dist/src/MaptilerGeolocateControl.d.ts +1 -1
- package/dist/src/MaptilerNavigationControl.d.ts +2 -1
- package/dist/src/config.d.ts +3 -3
- package/dist/src/defaults.d.ts +2 -2
- package/dist/src/helpers/index.d.ts +2 -0
- package/dist/src/helpers/screenshot.d.ts +19 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/language.d.ts +96 -130
- package/dist/src/mapstyle.d.ts +16 -1
- package/dist/src/tools.d.ts +4 -0
- package/package.json +13 -10
- package/readme.md +132 -0
- package/vite.config-es.ts +1 -1
- package/vite.config-umd.ts +3 -1
package/dist/src/Map.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { default as maplibregl, StyleSpecification, MapOptions as MapOptionsML, ControlPosition, StyleSwapOptions, StyleOptions, RequestTransformFunction, LayerSpecification, SourceSpecification, CustomLayerInterface, FilterSpecification, StyleSetterOptions } from 'maplibre-gl';
|
|
2
2
|
import { ReferenceMapStyle, MapStyleVariant } from '@maptiler/client';
|
|
3
3
|
import { SdkConfig } from './config';
|
|
4
|
-
import {
|
|
4
|
+
import { LanguageInfo } from './language';
|
|
5
5
|
import { MinimapOptionsInput } from './Minimap';
|
|
6
6
|
|
|
7
7
|
export type LoadWithTerrainEvent = {
|
|
@@ -32,7 +32,7 @@ export type MapOptions = Omit<MapOptionsML, "style" | "maplibreLogo"> & {
|
|
|
32
32
|
* or with a built-in shorthand (eg. Language.ENGLISH).
|
|
33
33
|
* Note that this is equivalent to setting the `config.primaryLanguage` and will overwrite it.
|
|
34
34
|
*/
|
|
35
|
-
language?:
|
|
35
|
+
language?: LanguageInfo;
|
|
36
36
|
/**
|
|
37
37
|
* Define the MapTiler Cloud API key to be used. This is strictly equivalent to setting
|
|
38
38
|
* `config.apiKey` and will overwrite it.
|
|
@@ -124,7 +124,15 @@ export declare class Map extends maplibregl.Map {
|
|
|
124
124
|
private forceLanguageUpdate;
|
|
125
125
|
private languageAlwaysBeenStyle;
|
|
126
126
|
private isReady;
|
|
127
|
+
private terrainAnimationDuration;
|
|
128
|
+
private monitoredStyleUrls;
|
|
129
|
+
private styleInProcess;
|
|
127
130
|
constructor(options: MapOptions);
|
|
131
|
+
/**
|
|
132
|
+
* Set the duration (millisec) of the terrain animation for growing or flattening.
|
|
133
|
+
* Must be positive. (Built-in default: `1000` milliseconds)
|
|
134
|
+
*/
|
|
135
|
+
setTerrainAnimationDuration(d: number): void;
|
|
128
136
|
/**
|
|
129
137
|
* Awaits for _this_ Map instance to be "loaded" and returns a Promise to the Map.
|
|
130
138
|
* If _this_ Map instance is already loaded, the Promise is resolved directly,
|
|
@@ -149,6 +157,7 @@ export declare class Map extends maplibregl.Map {
|
|
|
149
157
|
* @returns
|
|
150
158
|
*/
|
|
151
159
|
onLoadWithTerrainAsync(): Promise<Map>;
|
|
160
|
+
private monitorStyleUrl;
|
|
152
161
|
/**
|
|
153
162
|
* Update the style of the map.
|
|
154
163
|
* Can be:
|
|
@@ -277,7 +286,7 @@ export declare class Map extends maplibregl.Map {
|
|
|
277
286
|
/**
|
|
278
287
|
* Define the primary language of the map. Note that not all the languages shorthands provided are available.
|
|
279
288
|
*/
|
|
280
|
-
setLanguage(language:
|
|
289
|
+
setLanguage(language: LanguageInfo | string): void;
|
|
281
290
|
/**
|
|
282
291
|
* Define the primary language of the map. Note that not all the languages shorthands provided are available.
|
|
283
292
|
*/
|
|
@@ -286,7 +295,7 @@ export declare class Map extends maplibregl.Map {
|
|
|
286
295
|
* Get the primary language
|
|
287
296
|
* @returns
|
|
288
297
|
*/
|
|
289
|
-
getPrimaryLanguage():
|
|
298
|
+
getPrimaryLanguage(): LanguageInfo;
|
|
290
299
|
/**
|
|
291
300
|
* Get the exaggeration factor applied to the terrain
|
|
292
301
|
* @returns
|
|
@@ -15,7 +15,7 @@ export declare class MaptilerGeolocateControl extends GeolocateControl {
|
|
|
15
15
|
* @private
|
|
16
16
|
*/
|
|
17
17
|
_updateCamera: (position: GeolocationPosition) => void;
|
|
18
|
-
|
|
18
|
+
_finishSetupUI: (supported: boolean) => void;
|
|
19
19
|
_updateCircleRadius(): void;
|
|
20
20
|
_onZoom: () => void;
|
|
21
21
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { NavigationControlOptions } from 'maplibre-gl';
|
|
1
2
|
import { NavigationControl } from './MLAdapters/NavigationControl';
|
|
2
3
|
|
|
3
4
|
type HTMLButtonElementPlus = HTMLButtonElement & {
|
|
4
5
|
clickFunction: (e?: Event) => unknown;
|
|
5
6
|
};
|
|
6
7
|
export declare class MaptilerNavigationControl extends NavigationControl {
|
|
7
|
-
constructor();
|
|
8
|
+
constructor(options?: NavigationControlOptions);
|
|
8
9
|
/**
|
|
9
10
|
* Overloading: the button now stores its click callback so that we can later on delete it and replace it
|
|
10
11
|
*/
|
package/dist/src/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { default as EventEmitter } from 'events';
|
|
2
|
-
import {
|
|
2
|
+
import { LanguageInfo } from './language';
|
|
3
3
|
import { FetchFunction } from '@maptiler/client';
|
|
4
4
|
import { Unit } from './unit';
|
|
5
5
|
|
|
@@ -11,12 +11,12 @@ declare class SdkConfig extends EventEmitter {
|
|
|
11
11
|
/**
|
|
12
12
|
* The primary language. By default, the language of the web browser is used.
|
|
13
13
|
*/
|
|
14
|
-
primaryLanguage:
|
|
14
|
+
primaryLanguage: LanguageInfo;
|
|
15
15
|
/**
|
|
16
16
|
* The secondary language, to overwrite the default language defined in the map style.
|
|
17
17
|
* This settings is highly dependant on the style compatibility and may not work in most cases.
|
|
18
18
|
*/
|
|
19
|
-
secondaryLanguage?:
|
|
19
|
+
secondaryLanguage?: LanguageInfo;
|
|
20
20
|
/**
|
|
21
21
|
* Setting on whether of not the SDK runs with a session logic.
|
|
22
22
|
* A "session" is started at the initialization of the SDK and finished when the browser
|
package/dist/src/defaults.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ declare const defaults: {
|
|
|
6
6
|
maptilerURL: string;
|
|
7
7
|
maptilerApiHost: string;
|
|
8
8
|
rtlPluginURL: string;
|
|
9
|
-
primaryLanguage:
|
|
10
|
-
secondaryLanguage:
|
|
9
|
+
primaryLanguage: import('@maptiler/client').LanguageInfo;
|
|
10
|
+
secondaryLanguage: import('@maptiler/client').LanguageInfo;
|
|
11
11
|
terrainSourceURL: string;
|
|
12
12
|
terrainSourceId: string;
|
|
13
13
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { takeScreenshot } from './screenshot';
|
|
1
2
|
import { addPolyline, addPolygon, addPoint, addHeatmap } from './vectorlayerhelpers';
|
|
2
3
|
|
|
3
4
|
export type { ZoomStringValues, ZoomNumberValues, PropertyValues, CommonShapeLayerOptions, PolylineLayerOptions, PolygonLayerOptions, PointLayerOptions, HeatmapLayerOptions, } from './vectorlayerhelpers';
|
|
@@ -9,4 +10,5 @@ export declare const helpers: {
|
|
|
9
10
|
addPolygon: typeof addPolygon;
|
|
10
11
|
addPoint: typeof addPoint;
|
|
11
12
|
addHeatmap: typeof addHeatmap;
|
|
13
|
+
takeScreenshot: typeof takeScreenshot;
|
|
12
14
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Map as MapSDK } from '../Map';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Takes a screenshot (PNG file) of the curent map view.
|
|
5
|
+
* Depending on the options, this function can automatically trigger a download of te file.
|
|
6
|
+
*/
|
|
7
|
+
export declare function takeScreenshot(map: MapSDK, options?: {
|
|
8
|
+
/**
|
|
9
|
+
* If `true`, this function will trigger a download in addition to returning a blob.
|
|
10
|
+
* Default: `false`
|
|
11
|
+
*/
|
|
12
|
+
download?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Only if `options.download` is `true`. Indicates the filename under which
|
|
15
|
+
* the file will be downloaded.
|
|
16
|
+
* Default: `"maptiler_screenshot.png"`
|
|
17
|
+
*/
|
|
18
|
+
filename?: string;
|
|
19
|
+
}): Promise<Blob>;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -79,7 +79,8 @@ export * from './MaptilerGeolocateControl';
|
|
|
79
79
|
export * from './MaptilerLogoControl';
|
|
80
80
|
export * from './MaptilerTerrainControl';
|
|
81
81
|
export * from './MaptilerNavigationControl';
|
|
82
|
-
export { type AutomaticStaticMapOptions, type BoundedStaticMapOptions, type BufferToPixelDataFunction, type ByIdGeocodingOptions, type CenteredStaticMapOptions, type CommonForwardAndReverseGeocodingOptions, type CoordinateExport, type CoordinateGrid, type CoordinateId, type CoordinateSearch, type CoordinateSearchResult, type CoordinateTransformResult, type CoordinateTransformation, type Coordinates, type CoordinatesSearchOptions, type CoordinatesTransformOptions, type DefaultTransformation, type ElevationAtOptions, type ElevationBatchOptions, type FeatureHierarchy, type FetchFunction, type GeocodingFeature, type GeocodingOptions, type GeocodingSearchResult, type GeolocationInfoOptions, type GeolocationResult, type GetDataOptions,
|
|
82
|
+
export { type AutomaticStaticMapOptions, type BoundedStaticMapOptions, type BufferToPixelDataFunction, type ByIdGeocodingOptions, type CenteredStaticMapOptions, type CommonForwardAndReverseGeocodingOptions, type CoordinateExport, type CoordinateGrid, type CoordinateId, type CoordinateSearch, type CoordinateSearchResult, type CoordinateTransformResult, type CoordinateTransformation, type Coordinates, type CoordinatesSearchOptions, type CoordinatesTransformOptions, type DefaultTransformation, type ElevationAtOptions, type ElevationBatchOptions, type FeatureHierarchy, type FetchFunction, type GeocodingFeature, type GeocodingOptions, type GeocodingSearchResult, type GeolocationInfoOptions, type GeolocationResult, type GetDataOptions, type LanguageGeocodingOptions, MapStyle, type MapStylePreset, type MapStyleType, MapStyleVariant, type PixelData, ReferenceMapStyle, type ReverseGeocodingOptions, ServiceError, type StaticMapBaseOptions, type StaticMapMarker, type TileJSON, type XYZ, bufferToPixelDataBrowser, circumferenceAtLatitude, coordinates, data, elevation, expandMapStyle, geocoding, geolocation, getBufferToPixelDataParser, getTileCache, mapStylePresetList, math, misc, staticMaps, styleToStyle, type LanguageInfo, areSameLanguages, toLanguageInfo, isLanguageInfo, getAutoLanguage, getLanguageInfoFromFlag, getLanguageInfoFromCode, getLanguageInfoFromKey, } from '@maptiler/client';
|
|
83
|
+
export { getWebGLSupportError } from './tools';
|
|
83
84
|
export { config, SdkConfig } from './config';
|
|
84
85
|
export * from './language';
|
|
85
86
|
export { type Unit } from './unit';
|
package/dist/src/language.d.ts
CHANGED
|
@@ -1,142 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
1
|
+
import { LanguageInfo } from '@maptiler/client';
|
|
2
|
+
|
|
4
3
|
declare const Language: {
|
|
4
|
+
readonly AUTO: LanguageInfo;
|
|
5
|
+
readonly LATIN: LanguageInfo;
|
|
6
|
+
readonly NON_LATIN: LanguageInfo;
|
|
7
|
+
readonly LOCAL: LanguageInfo;
|
|
8
|
+
readonly AMHARIC: LanguageInfo;
|
|
9
|
+
readonly ARABIC: LanguageInfo;
|
|
10
|
+
readonly AZERBAIJANI: LanguageInfo;
|
|
11
|
+
readonly BELARUSIAN: LanguageInfo;
|
|
12
|
+
readonly BULGARIAN: LanguageInfo;
|
|
13
|
+
readonly BENGALI: LanguageInfo;
|
|
14
|
+
readonly BRETON: LanguageInfo;
|
|
15
|
+
readonly BOSNIAN: LanguageInfo;
|
|
16
|
+
readonly CATALAN: LanguageInfo;
|
|
17
|
+
readonly CHINESE: LanguageInfo;
|
|
18
|
+
readonly TRADITIONAL_CHINESE: LanguageInfo;
|
|
19
|
+
readonly SIMPLIFIED_CHINESE: LanguageInfo;
|
|
20
|
+
readonly CORSICAN: LanguageInfo;
|
|
21
|
+
readonly CZECH: LanguageInfo;
|
|
22
|
+
readonly WELSH: LanguageInfo;
|
|
23
|
+
readonly DANISH: LanguageInfo;
|
|
24
|
+
readonly GERMAN: LanguageInfo;
|
|
25
|
+
readonly GREEK: LanguageInfo;
|
|
26
|
+
readonly ENGLISH: LanguageInfo;
|
|
27
|
+
readonly ESPERANTO: LanguageInfo;
|
|
28
|
+
readonly SPANISH: LanguageInfo;
|
|
29
|
+
readonly ESTONIAN: LanguageInfo;
|
|
30
|
+
readonly BASQUE: LanguageInfo;
|
|
31
|
+
readonly FINNISH: LanguageInfo;
|
|
32
|
+
readonly FRENCH: LanguageInfo;
|
|
33
|
+
readonly FRISIAN: LanguageInfo;
|
|
34
|
+
readonly IRISH: LanguageInfo;
|
|
35
|
+
readonly SCOTTISH_GAELIC: LanguageInfo;
|
|
36
|
+
readonly HEBREW: LanguageInfo;
|
|
37
|
+
readonly HINDI: LanguageInfo;
|
|
38
|
+
readonly CROATIAN: LanguageInfo;
|
|
39
|
+
readonly HUNGARIAN: LanguageInfo;
|
|
40
|
+
readonly ARMENIAN: LanguageInfo;
|
|
41
|
+
readonly INDONESIAN: LanguageInfo;
|
|
42
|
+
readonly ICELANDIC: LanguageInfo;
|
|
43
|
+
readonly ITALIAN: LanguageInfo;
|
|
44
|
+
readonly JAPANESE: LanguageInfo;
|
|
45
|
+
readonly JAPANESE_HIRAGANA: LanguageInfo;
|
|
46
|
+
readonly JAPANESE_2018: LanguageInfo;
|
|
47
|
+
readonly JAPANESE_KANA: LanguageInfo;
|
|
48
|
+
readonly JAPANESE_LATIN: LanguageInfo;
|
|
49
|
+
readonly GEORGIAN: LanguageInfo;
|
|
50
|
+
readonly KAZAKH: LanguageInfo;
|
|
51
|
+
readonly KANNADA: LanguageInfo;
|
|
52
|
+
readonly KOREAN: LanguageInfo;
|
|
53
|
+
readonly KOREAN_LATIN: LanguageInfo;
|
|
54
|
+
readonly KURDISH: LanguageInfo;
|
|
55
|
+
readonly CLASSICAL_LATIN: LanguageInfo;
|
|
56
|
+
readonly LUXEMBOURGISH: LanguageInfo;
|
|
57
|
+
readonly LITHUANIAN: LanguageInfo;
|
|
58
|
+
readonly LATVIAN: LanguageInfo;
|
|
59
|
+
readonly MACEDONIAN: LanguageInfo;
|
|
60
|
+
readonly MALAYALAM: LanguageInfo;
|
|
61
|
+
readonly MALTESE: LanguageInfo;
|
|
62
|
+
readonly DUTCH: LanguageInfo;
|
|
63
|
+
readonly NORWEGIAN: LanguageInfo;
|
|
64
|
+
readonly OCCITAN: LanguageInfo;
|
|
65
|
+
readonly POLISH: LanguageInfo;
|
|
66
|
+
readonly PERSIAN: LanguageInfo;
|
|
67
|
+
readonly PUNJABI: LanguageInfo;
|
|
68
|
+
readonly WESTERN_PUNJABI: LanguageInfo;
|
|
69
|
+
readonly PORTUGUESE: LanguageInfo;
|
|
70
|
+
readonly ROMANSH: LanguageInfo;
|
|
71
|
+
readonly ROMANIAN: LanguageInfo;
|
|
72
|
+
readonly RUSSIAN: LanguageInfo;
|
|
73
|
+
readonly SLOVAK: LanguageInfo;
|
|
74
|
+
readonly SLOVENE: LanguageInfo;
|
|
75
|
+
readonly ALBANIAN: LanguageInfo;
|
|
76
|
+
readonly SERBIAN_CYRILLIC: LanguageInfo;
|
|
77
|
+
readonly SERBIAN_LATIN: LanguageInfo;
|
|
78
|
+
readonly SWEDISH: LanguageInfo;
|
|
79
|
+
readonly TAMIL: LanguageInfo;
|
|
80
|
+
readonly TELUGU: LanguageInfo;
|
|
81
|
+
readonly THAI: LanguageInfo;
|
|
82
|
+
readonly TURKISH: LanguageInfo;
|
|
83
|
+
readonly UKRAINIAN: LanguageInfo;
|
|
84
|
+
readonly VIETNAMESE: LanguageInfo;
|
|
5
85
|
/**
|
|
6
|
-
*
|
|
7
|
-
* Note
|
|
8
|
-
* scale or the local name.
|
|
9
|
-
* This mode is helpful in the context where a user needs to access both the local names and the names in their
|
|
10
|
-
* own language, for instance when traveling abroad, where signs likely to be only available in the local language.
|
|
11
|
-
*/
|
|
12
|
-
readonly VISITOR: "visitor";
|
|
13
|
-
/**
|
|
14
|
-
* The visitor language mode concatenates English and the "default name".
|
|
15
|
-
* Note: The "default name" is equivalent to OSM's `{name}`, which can be the most recognized names a global
|
|
16
|
-
* scale or the local name.
|
|
17
|
-
* This mode is helpful in the context where a user needs to access both the local names and the names in their
|
|
18
|
-
* own language, for instance when traveling abroad, where signs likely to be only available in the local language.
|
|
19
|
-
*/
|
|
20
|
-
readonly VISITOR_ENGLISH: "visitor_en";
|
|
21
|
-
/**
|
|
22
|
-
* Language as the style is designed. Not that this is the default state and one
|
|
23
|
-
* the language has been changed to another than `STYLE`, then it cannot be set back to `STYLE`.
|
|
24
|
-
*/
|
|
25
|
-
readonly STYLE: "style";
|
|
26
|
-
/**
|
|
27
|
-
* AUTO mode uses the language of the browser
|
|
28
|
-
*/
|
|
29
|
-
readonly AUTO: "auto";
|
|
30
|
-
/**
|
|
31
|
-
* STYLE is a custom flag to keep the language of the map as defined into the style.
|
|
32
|
-
* If STYLE is set in the constructor, then further modification of the language
|
|
33
|
-
* with `.setLanguage()` is not possible.
|
|
86
|
+
* Language mode to display labels in both the local language and the language of the visitor's device, concatenated.
|
|
87
|
+
* Note that if those two languages are the same, labels won't be duplicated.
|
|
34
88
|
*/
|
|
35
|
-
readonly
|
|
89
|
+
readonly VISITOR: LanguageInfo;
|
|
36
90
|
/**
|
|
37
|
-
*
|
|
91
|
+
* Language mode to display labels in both the local language and English, concatenated.
|
|
92
|
+
* Note that if those two languages are the same, labels won't be duplicated.
|
|
38
93
|
*/
|
|
39
|
-
readonly
|
|
94
|
+
readonly VISITOR_ENGLISH: LanguageInfo;
|
|
40
95
|
/**
|
|
41
|
-
*
|
|
96
|
+
* Language mode to display labels in a language enforced in the style.
|
|
42
97
|
*/
|
|
43
|
-
readonly
|
|
98
|
+
readonly STYLE: LanguageInfo;
|
|
44
99
|
/**
|
|
45
|
-
*
|
|
100
|
+
* Language mode to display labels in a language enforced in the style. The language cannot be further modified.
|
|
46
101
|
*/
|
|
47
|
-
readonly
|
|
48
|
-
/**
|
|
49
|
-
* International name
|
|
50
|
-
*/
|
|
51
|
-
readonly INTERNATIONAL: "name_int";
|
|
52
|
-
readonly ALBANIAN: "name:sq";
|
|
53
|
-
readonly AMHARIC: "name:am";
|
|
54
|
-
readonly ARABIC: "name:ar";
|
|
55
|
-
readonly ARMENIAN: "name:hy";
|
|
56
|
-
readonly AZERBAIJANI: "name:az";
|
|
57
|
-
readonly BASQUE: "name:eu";
|
|
58
|
-
readonly BELORUSSIAN: "name:be";
|
|
59
|
-
readonly BENGALI: "name:bn";
|
|
60
|
-
readonly BOSNIAN: "name:bs";
|
|
61
|
-
readonly BRETON: "name:br";
|
|
62
|
-
readonly BULGARIAN: "name:bg";
|
|
63
|
-
readonly CATALAN: "name:ca";
|
|
64
|
-
readonly CHINESE: "name:zh";
|
|
65
|
-
readonly TRADITIONAL_CHINESE: "name:zh-Hant";
|
|
66
|
-
readonly SIMPLIFIED_CHINESE: "name:zh-Hans";
|
|
67
|
-
readonly CORSICAN: "name:co";
|
|
68
|
-
readonly CROATIAN: "name:hr";
|
|
69
|
-
readonly CZECH: "name:cs";
|
|
70
|
-
readonly DANISH: "name:da";
|
|
71
|
-
readonly DUTCH: "name:nl";
|
|
72
|
-
readonly ENGLISH: "name:en";
|
|
73
|
-
readonly ESPERANTO: "name:eo";
|
|
74
|
-
readonly ESTONIAN: "name:et";
|
|
75
|
-
readonly FINNISH: "name:fi";
|
|
76
|
-
readonly FRENCH: "name:fr";
|
|
77
|
-
readonly FRISIAN: "name:fy";
|
|
78
|
-
readonly GEORGIAN: "name:ka";
|
|
79
|
-
readonly GERMAN: "name:de";
|
|
80
|
-
readonly GREEK: "name:el";
|
|
81
|
-
readonly HEBREW: "name:he";
|
|
82
|
-
readonly HINDI: "name:hi";
|
|
83
|
-
readonly HUNGARIAN: "name:hu";
|
|
84
|
-
readonly ICELANDIC: "name:is";
|
|
85
|
-
readonly INDONESIAN: "name:id";
|
|
86
|
-
readonly IRISH: "name:ga";
|
|
87
|
-
readonly ITALIAN: "name:it";
|
|
88
|
-
readonly JAPANESE: "name:ja";
|
|
89
|
-
readonly JAPANESE_HIRAGANA: "name:ja-Hira";
|
|
90
|
-
readonly JAPANESE_KANA: "name:ja_kana";
|
|
91
|
-
readonly JAPANESE_LATIN: "name:ja_rm";
|
|
92
|
-
readonly JAPANESE_2018: "name:ja-Latn";
|
|
93
|
-
readonly KANNADA: "name:kn";
|
|
94
|
-
readonly KAZAKH: "name:kk";
|
|
95
|
-
readonly KOREAN: "name:ko";
|
|
96
|
-
readonly KOREAN_LATIN: "name:ko-Latn";
|
|
97
|
-
readonly KURDISH: "name:ku";
|
|
98
|
-
readonly ROMAN_LATIN: "name:la";
|
|
99
|
-
readonly LATVIAN: "name:lv";
|
|
100
|
-
readonly LITHUANIAN: "name:lt";
|
|
101
|
-
readonly LUXEMBOURGISH: "name:lb";
|
|
102
|
-
readonly MACEDONIAN: "name:mk";
|
|
103
|
-
readonly MALAYALAM: "name:ml";
|
|
104
|
-
readonly MALTESE: "name:mt";
|
|
105
|
-
readonly NORWEGIAN: "name:no";
|
|
106
|
-
readonly OCCITAN: "name:oc";
|
|
107
|
-
readonly PERSIAN: "name:fa";
|
|
108
|
-
readonly POLISH: "name:pl";
|
|
109
|
-
readonly PORTUGUESE: "name:pt";
|
|
110
|
-
readonly PUNJABI: "name:pa";
|
|
111
|
-
readonly WESTERN_PUNJABI: "name:pnb";
|
|
112
|
-
readonly ROMANIAN: "name:ro";
|
|
113
|
-
readonly ROMANSH: "name:rm";
|
|
114
|
-
readonly RUSSIAN: "name:ru";
|
|
115
|
-
readonly SCOTTISH_GAELIC: "name:gd";
|
|
116
|
-
readonly SERBIAN_CYRILLIC: "name:sr";
|
|
117
|
-
readonly SERBIAN_LATIN: "name:sr-Latn";
|
|
118
|
-
readonly SLOVAK: "name:sk";
|
|
119
|
-
readonly SLOVENE: "name:sl";
|
|
120
|
-
readonly SPANISH: "name:es";
|
|
121
|
-
readonly SWEDISH: "name:sv";
|
|
122
|
-
readonly TAMIL: "name:ta";
|
|
123
|
-
readonly TELUGU: "name:te";
|
|
124
|
-
readonly THAI: "name:th";
|
|
125
|
-
readonly TURKISH: "name:tr";
|
|
126
|
-
readonly UKRAINIAN: "name:uk";
|
|
127
|
-
readonly URDU: "name:ur";
|
|
128
|
-
readonly VIETNAMIAN_LATIN: "name:vi";
|
|
129
|
-
readonly WELSH: "name:cy";
|
|
102
|
+
readonly STYLE_LOCK: LanguageInfo;
|
|
130
103
|
};
|
|
131
|
-
declare function isLanguageSupported(lang: string): boolean;
|
|
132
|
-
/**
|
|
133
|
-
* Type representing the key of the Language object
|
|
134
|
-
*/
|
|
135
|
-
type LanguageKey = keyof typeof Language;
|
|
136
|
-
type Values<T> = T[keyof T];
|
|
137
104
|
/**
|
|
138
|
-
*
|
|
105
|
+
* Get the browser language
|
|
139
106
|
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
export { Language, type LanguageString, type LanguageKey, getBrowserLanguage, isLanguageSupported };
|
|
107
|
+
export declare function getBrowserLanguage(): LanguageInfo;
|
|
108
|
+
export { Language, type LanguageInfo };
|
package/dist/src/mapstyle.d.ts
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
1
|
import { ReferenceMapStyle, MapStyleVariant } from '@maptiler/client';
|
|
2
2
|
|
|
3
|
-
export declare function styleToStyle(style: string | ReferenceMapStyle | MapStyleVariant | maplibregl.StyleSpecification | null | undefined):
|
|
3
|
+
export declare function styleToStyle(style: string | ReferenceMapStyle | MapStyleVariant | maplibregl.StyleSpecification | null | undefined): {
|
|
4
|
+
style: string | maplibregl.StyleSpecification;
|
|
5
|
+
requiresUrlMonitoring: boolean;
|
|
6
|
+
isFallback: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* makes sure a URL is absolute
|
|
10
|
+
*/
|
|
11
|
+
export declare function urlToAbsoluteUrl(url: string): string;
|
|
12
|
+
type StyleValidationReport = {
|
|
13
|
+
isValidJSON: boolean;
|
|
14
|
+
isValidStyle: boolean;
|
|
15
|
+
styleObject: maplibregl.StyleSpecification | null;
|
|
16
|
+
};
|
|
17
|
+
export declare function convertToStyleSpecificationString(str: string): StyleValidationReport;
|
|
18
|
+
export {};
|
package/dist/src/tools.d.ts
CHANGED
|
@@ -44,3 +44,7 @@ export declare function getWebGLSupportError(): string | null;
|
|
|
44
44
|
* Display an error message in the Map div if WebGL2 is not supported
|
|
45
45
|
*/
|
|
46
46
|
export declare function displayNoWebGlWarning(container: HTMLElement | string): void;
|
|
47
|
+
/**
|
|
48
|
+
* Display an error message in the Map div if WebGL2 is not supported
|
|
49
|
+
*/
|
|
50
|
+
export declare function displayWebGLContextLostWarning(container: HTMLElement | string): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maptiler/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "The Javascript & TypeScript map SDK tailored for MapTiler Cloud",
|
|
5
5
|
"module": "dist/maptiler-sdk.mjs",
|
|
6
6
|
"types": "dist/maptiler-sdk.d.ts",
|
|
@@ -39,30 +39,33 @@
|
|
|
39
39
|
"doc": "rm -rf docs/* && typedoc --out docs && cp -r images docs/",
|
|
40
40
|
"test": "vitest run",
|
|
41
41
|
"build-css": "node scripts/replace-path-with-content.js src/style/style_template.css dist/tmp_maptiler-sdk.css && cat node_modules/maplibre-gl/dist/maplibre-gl.css dist/tmp_maptiler-sdk.css > dist/maptiler-sdk.css && rm dist/tmp_maptiler-sdk.css && cp dist/maptiler-sdk.css build/maptiler-sdk.css",
|
|
42
|
-
"build-umd": "NODE_ENV=production
|
|
43
|
-
"build-es": "NODE_ENV=production
|
|
42
|
+
"build-umd": "tsc && NODE_ENV=production vite build -c vite.config-umd.ts",
|
|
43
|
+
"build-es": "tsc && NODE_ENV=production vite build -c vite.config-es.ts",
|
|
44
44
|
"build": "npm run build-es; npm run build-umd; npm run build-css",
|
|
45
|
-
"make": "npm run biome:fix && npm run build"
|
|
45
|
+
"make": "npm run biome:fix && npm run build",
|
|
46
|
+
"dev-umd": "npm run build-css && tsc && NODE_ENV=dev vite build -w -c vite.config-umd.ts",
|
|
47
|
+
"help": "vite build --help"
|
|
46
48
|
},
|
|
47
49
|
"author": "MapTiler",
|
|
48
50
|
"devDependencies": {
|
|
49
51
|
"@biomejs/biome": "1.8.3",
|
|
50
52
|
"@types/uuid": "^9.0.2",
|
|
51
53
|
"@types/xmldom": "^0.1.31",
|
|
54
|
+
"@xmldom/xmldom": "^0.8.10",
|
|
52
55
|
"serve": "^14.2.0",
|
|
53
56
|
"terser": "^5.17.1",
|
|
54
57
|
"typedoc": "^0.24.8",
|
|
55
58
|
"typescript": "^5.1.6",
|
|
56
|
-
"vitest": "^0.34.2",
|
|
57
59
|
"vite": "^5.3.4",
|
|
58
|
-
"vite-plugin-dts": "^4.0.0-beta.0"
|
|
60
|
+
"vite-plugin-dts": "^4.0.0-beta.0",
|
|
61
|
+
"vitest": "^0.34.2"
|
|
59
62
|
},
|
|
60
63
|
"dependencies": {
|
|
61
|
-
"@
|
|
64
|
+
"@maplibre/maplibre-gl-style-spec": "^20.3.1",
|
|
65
|
+
"@maptiler/client": "^2.0.0",
|
|
62
66
|
"events": "^3.3.0",
|
|
63
67
|
"js-base64": "^3.7.4",
|
|
64
|
-
"maplibre-gl": "4.
|
|
65
|
-
"uuid": "^9.0.0"
|
|
66
|
-
"xmldom": "^0.6.0"
|
|
68
|
+
"maplibre-gl": "4.7.1",
|
|
69
|
+
"uuid": "^9.0.0"
|
|
67
70
|
}
|
|
68
71
|
}
|
package/readme.md
CHANGED
|
@@ -76,6 +76,37 @@ For example, with a [NextJS](https://nextjs.org/) app, this can take place at th
|
|
|
76
76
|
import "@maptiler/sdk/dist/maptiler-sdk.css";
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
+
### TypeScript
|
|
80
|
+
The SDK is fully typed, but it may happen that types defined in Maplibre GL JS are not visible in your project. This is a known issue that comes from Maplibre being a CommonJS bundle.
|
|
81
|
+
|
|
82
|
+
There are mainly two ways to addess this issue and access to the complete type definition.
|
|
83
|
+
|
|
84
|
+
1. **With `esModuleInterop`**
|
|
85
|
+
|
|
86
|
+
Set the following in your `tsconfig.json`:
|
|
87
|
+
```js
|
|
88
|
+
{
|
|
89
|
+
"compilerOptions": {
|
|
90
|
+
// ...
|
|
91
|
+
"esModuleInterop": true,
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
2. **With `moduleResolution`**
|
|
97
|
+
|
|
98
|
+
Set the following in your `tsconfig.json`:
|
|
99
|
+
```js
|
|
100
|
+
{
|
|
101
|
+
"compilerOptions": {
|
|
102
|
+
// ...
|
|
103
|
+
"moduleResolution": "Bundler",
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
Note that this second option is not always possible as some frameworks and other dependencies won't let you use the "Bundler" mode.
|
|
108
|
+
|
|
109
|
+
|
|
79
110
|
|
|
80
111
|
## With CDN
|
|
81
112
|
The SDK hosted on our CDN is bundled as *[Universal Module Definition](https://github.com/umdjs/umd)* (UMD) to make it standalone and contain all its dependencies. The CDN also serves the style sheet (CSS).
|
|
@@ -340,6 +371,55 @@ map.disableTerrain()
|
|
|
340
371
|
|
|
341
372
|
> 📣 *__Note 2:__* please be aware that due to the volume and elevation of the map floor in 3D space, the navigation with the terrain enabled is slightly different than without.
|
|
342
373
|
|
|
374
|
+
By default, enabling, disabling or even just updating the terrain exaggeration will result in a 1-second animation. This is possible to modify with the following `Map` method:
|
|
375
|
+
|
|
376
|
+
```ts
|
|
377
|
+
// Duration in milliseconds
|
|
378
|
+
map.setTerrainAnimationDuration(500);
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
## Terrain events
|
|
382
|
+
- `"terrain"` event
|
|
383
|
+
|
|
384
|
+
As an extension of Maplibre GL JS, MapTiler SDK is also exposing the terrain event `"terrain"`. This event is triggered when a terrain source is added or removed:
|
|
385
|
+
|
|
386
|
+
```ts
|
|
387
|
+
map.on("terrain", (e) => {
|
|
388
|
+
// your logic here
|
|
389
|
+
})
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
Since MapTiler SDK adds animation and the terrain data is necessary all along, the `"terrain"` event will be called at the very begining of the terrain animation when enabling and at the very end when disabling.
|
|
393
|
+
|
|
394
|
+
- `"terrainAnimationStart"` and `"terrainAnimationStop"` events
|
|
395
|
+
|
|
396
|
+
With the animation of the terrain, it can sometimes be convenient to know when the animation starts and ends. These two events are made just for that, here are how they work:
|
|
397
|
+
|
|
398
|
+
```ts
|
|
399
|
+
map.on("terrainAnimationStart", (event) => {
|
|
400
|
+
console.log("Terrain animation is starting...");
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
map.on("terrainAnimationStop", (event) => {
|
|
404
|
+
console.log("Terrain animation is finished");
|
|
405
|
+
});
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
The `event` argument is an object that contains (amond other things) a `terrain` attribute. In the case of `"terrainAnimationStop"`, this terrain attribute is `null` if the animation was about disabling the terrain, otherwise, this is just a propagation of `map.terrain`.
|
|
409
|
+
|
|
410
|
+
In the following example, we decide to associate the terrain animation with a change of camera, e.g. from clicking on the terrain control:
|
|
411
|
+
- when the terrain is enabled, it pops up with an animation and only **then** the camera is animated to take a lower point of view
|
|
412
|
+
- when the terrain is disabled, it is flattened with an animation and only **then** the camera is animated to a top view
|
|
413
|
+
|
|
414
|
+
```ts
|
|
415
|
+
map.on("terrainAnimationStop", (e) => {
|
|
416
|
+
map.easeTo({
|
|
417
|
+
pitch: e.terrain ? 60 : 0,
|
|
418
|
+
duration: 500,
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
```
|
|
422
|
+
|
|
343
423
|
|
|
344
424
|
# Easy language switching
|
|
345
425
|
The language generally depends on the style but we made it possible to easily set and update from a built-in list of languages.
|
|
@@ -565,6 +645,27 @@ We believe that the *promise* approach is better because it does not nest scopes
|
|
|
565
645
|
|
|
566
646
|
> 📣 *__Note:__* Generally speaking, *promises* are not a go to replacement for all event+callback and are suitable only for events that are called only once in the lifecycle of a Map instance. This is the reason why we have decided to provide a *promise* equivalent only for the `load`, `ready` and `loadWithTerrain` events but not for events that may be called multiple time such as interaction events.
|
|
567
647
|
|
|
648
|
+
### The `webglContextLost` event
|
|
649
|
+
The maps is rendered with WebGL, that leverages the GPU to provide high-performance graphics. In some cases, the host machine, operating system or the graphics driver, can decide that continuing to run such high performance graphics is unsustainable, and will abort the process. This is called a "WebGL context loss". Such situation happens when the ressources are running low or when multiple browser tabs are competing to access graphics memory.
|
|
650
|
+
|
|
651
|
+
The best course of action in such situation varies from an app to another. Sometimes a page refresh is the best thing to do, in other cases, instantiating a new Map dynmicaly at application level is more appropriate because it hides a technical failure to the end user. The event `webglContextLost` is exposed so that the most appropriate scenario can be implemented at application level.
|
|
652
|
+
|
|
653
|
+
Here is how to respond to a WebGL context loss with a simple page refresh:
|
|
654
|
+
```ts
|
|
655
|
+
|
|
656
|
+
// Init the map
|
|
657
|
+
const map = new maptilersdk.Map({
|
|
658
|
+
container: "map-container",
|
|
659
|
+
hash: true,
|
|
660
|
+
})
|
|
661
|
+
|
|
662
|
+
// Refresh the page if context is lost.
|
|
663
|
+
// Since `hash` is true, the location will be the same as before
|
|
664
|
+
map.on("webglContextLost", (e) => {
|
|
665
|
+
location.reload();
|
|
666
|
+
})
|
|
667
|
+
```
|
|
668
|
+
|
|
568
669
|
# Color Ramps
|
|
569
670
|
A color ramp is a color gradient defined in a specific interval, for instance in [0, 1], and for any value within this interval will retrieve a color. They are defined by at least a color at each bound and usually additional colors within the range.
|
|
570
671
|
|
|
@@ -862,6 +963,37 @@ Turning off *zoom compensation* allows for more accurate adjustments to the visu
|
|
|
862
963
|
|
|
863
964
|
All the other options are documented on [our reference page](https://docs.maptiler.com/sdk-js/api/helpers/#heatmap) and more examples are available [here](https://docs.maptiler.com/sdk-js/examples/?q=heatmap+helper).
|
|
864
965
|
|
|
966
|
+
# Other helper
|
|
967
|
+
## Take Screenshots, programmatically
|
|
968
|
+
There are two different ways to create screenshot, corresponding to two very different usecases. Note that screenshots will not contain *DOM elements* such as `Marker` and `Popup`, since those are not part of the rendering context.
|
|
969
|
+
|
|
970
|
+
**1. Get a `blob` of a screenshot, PNG encoded:**
|
|
971
|
+
```ts
|
|
972
|
+
import { Map, helpers } from "@maptiler/sdk";
|
|
973
|
+
|
|
974
|
+
// ... initialize a Map instance, wait for the "load" or "ready" event ...
|
|
975
|
+
|
|
976
|
+
// Inside an async function, or with using .then()
|
|
977
|
+
const blob = await helpers.takeScreenshot(map);
|
|
978
|
+
```
|
|
979
|
+
The returned `Blob` of a PNG image file can be very handy if the goal is to programmatically further manipulate the screenshot, such as sending it to some feedback endpoint with a POST request.
|
|
980
|
+
|
|
981
|
+
**2. Download a PNG file:**
|
|
982
|
+
```ts
|
|
983
|
+
import { Map, helpers } from "@maptiler/sdk";
|
|
984
|
+
|
|
985
|
+
// ... initialize a Map instance, wait for the "load" or "ready" event ...
|
|
986
|
+
|
|
987
|
+
// No need to be inside an async function, the download will be triggered when the file is ready
|
|
988
|
+
maptilersdk.helpers.takeScreenshot(map, {
|
|
989
|
+
download: true,
|
|
990
|
+
filename: "map_screenshot.png"
|
|
991
|
+
});
|
|
992
|
+
```
|
|
993
|
+
Getting a file directly is a nice option that can be useful to share some debugging context with colleagues, compare multiple styles, or share your creation on social media.
|
|
994
|
+
|
|
995
|
+
> 📣 *__Note:__* Keep in mind that MapTiler Cloud data are copyrighted and their usage is restricted. This include MapTiler built-in styles and tilesets, among others. In case of doubt, do not hesitate to read our [terms](https://www.maptiler.com/terms/) or to ask our [support team](https://www.maptiler.com/contacts/).
|
|
996
|
+
|
|
865
997
|
# Caching
|
|
866
998
|
Starting from v2, MapTiler SDK introduced the **caching** of tiles and fonts served by MapTiler Cloud, which can represent a large chunk of the data being fetched when browsing a map. This caching leverages modern browsers caching API so it's well-managed and there is no risk of bloating! When we update **MapTiler Planet** or our **official styles**, the caching logic will detect it and automatically invalidate older versions of the tiles that were previously cached.
|
|
867
999
|
|
package/vite.config-es.ts
CHANGED
|
@@ -12,6 +12,7 @@ export default defineConfig({
|
|
|
12
12
|
mode: isProduction ? "production" : "development",
|
|
13
13
|
build: {
|
|
14
14
|
minify: isProduction,
|
|
15
|
+
emptyOutDir: isProduction,
|
|
15
16
|
outDir: "dist",
|
|
16
17
|
sourcemap: true,
|
|
17
18
|
lib: {
|
|
@@ -35,7 +36,6 @@ export default defineConfig({
|
|
|
35
36
|
"events",
|
|
36
37
|
"js-base64",
|
|
37
38
|
"geojson-validation",
|
|
38
|
-
"xmldom",
|
|
39
39
|
],
|
|
40
40
|
output: {
|
|
41
41
|
// Provide global variables to use in the UMD build
|