@maptiler/sdk 1.1.2 → 1.2.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/.eslintrc.cjs +15 -5
- package/.github/pull_request_template.md +11 -0
- package/.github/workflows/format-lint.yml +24 -0
- package/CHANGELOG.md +94 -51
- package/colorramp.md +93 -0
- package/dist/maptiler-sdk.d.ts +1207 -123
- package/dist/maptiler-sdk.min.mjs +3 -1
- package/dist/maptiler-sdk.mjs +3561 -485
- package/dist/maptiler-sdk.mjs.map +1 -1
- package/dist/maptiler-sdk.umd.js +3825 -869
- package/dist/maptiler-sdk.umd.js.map +1 -1
- package/dist/maptiler-sdk.umd.min.js +51 -49
- package/package.json +27 -13
- package/readme.md +298 -0
- package/rollup.config.js +2 -16
- package/src/Map.ts +489 -357
- package/src/MaptilerGeolocateControl.ts +23 -20
- package/src/MaptilerLogoControl.ts +3 -3
- package/src/MaptilerNavigationControl.ts +9 -6
- package/src/MaptilerTerrainControl.ts +15 -14
- package/src/Minimap.ts +373 -0
- package/src/Point.ts +3 -5
- package/src/colorramp.ts +1216 -0
- package/src/config.ts +4 -3
- package/src/converters/index.ts +1 -0
- package/src/converters/xml.ts +681 -0
- package/src/defaults.ts +1 -1
- package/src/helpers/index.ts +27 -0
- package/src/helpers/stylehelper.ts +395 -0
- package/src/helpers/vectorlayerhelpers.ts +1511 -0
- package/src/index.ts +10 -0
- package/src/language.ts +116 -79
- package/src/mapstyle.ts +4 -2
- package/src/tools.ts +68 -16
- package/tsconfig.json +8 -5
- package/vite.config.ts +10 -0
- package/demos/maptiler-sdk.css +0 -147
- package/demos/maptiler-sdk.umd.js +0 -4041
- package/demos/mountain.html +0 -67
- package/demos/simple.html +0 -67
- package/demos/transform-request.html +0 -81
package/src/index.ts
CHANGED
|
@@ -170,10 +170,12 @@ import type { Matrix2 } from "./Point";
|
|
|
170
170
|
import { config, SdkConfig } from "./config";
|
|
171
171
|
import { Language, LanguageString, LanguageKey } from "./language";
|
|
172
172
|
import type { Unit } from "./unit";
|
|
173
|
+
import type { MinimapOptionsInput } from "./Minimap";
|
|
173
174
|
|
|
174
175
|
// Exporting types
|
|
175
176
|
export type {
|
|
176
177
|
MapOptions,
|
|
178
|
+
MinimapOptionsInput,
|
|
177
179
|
LoadWithTerrainEvent,
|
|
178
180
|
GeocodingOptions,
|
|
179
181
|
BBox,
|
|
@@ -190,6 +192,12 @@ export type {
|
|
|
190
192
|
Matrix2,
|
|
191
193
|
};
|
|
192
194
|
|
|
195
|
+
// Export convert functions 'str2xml', 'xml2str', 'gpx', and 'kml'
|
|
196
|
+
export * from "./converters";
|
|
197
|
+
|
|
198
|
+
// Export the color ramp logic and all the built-in color ramps
|
|
199
|
+
export * from "./colorramp";
|
|
200
|
+
|
|
193
201
|
// Exporting classes, objects, functions, etc.
|
|
194
202
|
export {
|
|
195
203
|
Map,
|
|
@@ -230,3 +238,5 @@ export {
|
|
|
230
238
|
MaptilerTerrainControl,
|
|
231
239
|
MaptilerNavigationControl,
|
|
232
240
|
};
|
|
241
|
+
|
|
242
|
+
export * from "./helpers";
|
package/src/language.ts
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
* Languages. Note that not all the languages of this list are available but the compatibility list may be expanded in the future.
|
|
3
3
|
*/
|
|
4
4
|
const Language = {
|
|
5
|
+
/**
|
|
6
|
+
* The visitor language mode concatenates the prefered language from the user settings and the "default name".
|
|
7
|
+
* Note: The "default name" is equivalent to OSM's `{name}`, which can be the most recognized names a global
|
|
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
|
+
VISITOR: "visitor",
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The visitor language mode concatenates English and the "default name".
|
|
16
|
+
* Note: The "default name" is equivalent to OSM's `{name}`, which can be the most recognized names a global
|
|
17
|
+
* scale or the local name.
|
|
18
|
+
* This mode is helpful in the context where a user needs to access both the local names and the names in their
|
|
19
|
+
* own language, for instance when traveling abroad, where signs likely to be only available in the local language.
|
|
20
|
+
*/
|
|
21
|
+
VISITOR_ENGLISH: "visitor_en",
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Language as the style is designed. Not that this is the default state and one
|
|
25
|
+
* the language has been changed to another than `STYLE`, then it cannot be set back to `STYLE`.
|
|
26
|
+
*/
|
|
27
|
+
STYLE: "style",
|
|
28
|
+
|
|
5
29
|
/**
|
|
6
30
|
* AUTO mode uses the language of the browser
|
|
7
31
|
*/
|
|
@@ -17,88 +41,101 @@ const Language = {
|
|
|
17
41
|
/**
|
|
18
42
|
* Default fallback languages that uses latin charaters
|
|
19
43
|
*/
|
|
20
|
-
LATIN: "latin",
|
|
44
|
+
LATIN: "name:latin",
|
|
21
45
|
|
|
22
46
|
/**
|
|
23
47
|
* Default fallback languages that uses non-latin charaters
|
|
24
48
|
*/
|
|
25
|
-
NON_LATIN: "nonlatin",
|
|
49
|
+
NON_LATIN: "name:nonlatin",
|
|
26
50
|
|
|
27
51
|
/**
|
|
28
52
|
* Labels are in their local language, when available
|
|
29
53
|
*/
|
|
30
|
-
LOCAL: "",
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
54
|
+
LOCAL: "name",
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* International name
|
|
58
|
+
*/
|
|
59
|
+
INTERNATIONAL: "name_int",
|
|
60
|
+
|
|
61
|
+
ALBANIAN: "name:sq",
|
|
62
|
+
AMHARIC: "name:am",
|
|
63
|
+
ARABIC: "name:ar",
|
|
64
|
+
ARMENIAN: "name:hy",
|
|
65
|
+
AZERBAIJANI: "name:az",
|
|
66
|
+
BASQUE: "name:eu",
|
|
67
|
+
BELORUSSIAN: "name:be",
|
|
68
|
+
BENGALI: "name:bn",
|
|
69
|
+
BOSNIAN: "name:bs",
|
|
70
|
+
BRETON: "name:br",
|
|
71
|
+
BULGARIAN: "name:bg",
|
|
72
|
+
CATALAN: "name:ca",
|
|
73
|
+
CHINESE: "name:zh",
|
|
74
|
+
TRADITIONAL_CHINESE: "name:zh-Hant",
|
|
75
|
+
SIMPLIFIED_CHINESE: "name:zh-Hans",
|
|
76
|
+
CORSICAN: "name:co",
|
|
77
|
+
CROATIAN: "name:hr",
|
|
78
|
+
CZECH: "name:cs",
|
|
79
|
+
DANISH: "name:da",
|
|
80
|
+
DUTCH: "name:nl",
|
|
81
|
+
ENGLISH: "name:en",
|
|
82
|
+
ESPERANTO: "name:eo",
|
|
83
|
+
ESTONIAN: "name:et",
|
|
84
|
+
FINNISH: "name:fi",
|
|
85
|
+
FRENCH: "name:fr",
|
|
86
|
+
FRISIAN: "name:fy",
|
|
87
|
+
GEORGIAN: "name:ka",
|
|
88
|
+
GERMAN: "name:de",
|
|
89
|
+
GREEK: "name:el",
|
|
90
|
+
HEBREW: "name:he",
|
|
91
|
+
HINDI: "name:hi",
|
|
92
|
+
HUNGARIAN: "name:hu",
|
|
93
|
+
ICELANDIC: "name:is",
|
|
94
|
+
INDONESIAN: "name:id",
|
|
95
|
+
IRISH: "name:ga",
|
|
96
|
+
ITALIAN: "name:it",
|
|
97
|
+
JAPANESE: "name:ja",
|
|
98
|
+
JAPANESE_HIRAGANA: "name:ja-Hira",
|
|
99
|
+
JAPANESE_KANA: "name:ja_kana",
|
|
100
|
+
JAPANESE_LATIN: "name:ja_rm",
|
|
101
|
+
JAPANESE_2018: "name:ja-Latn",
|
|
102
|
+
KANNADA: "name:kn",
|
|
103
|
+
KAZAKH: "name:kk",
|
|
104
|
+
KOREAN: "name:ko",
|
|
105
|
+
KOREAN_LATIN: "name:ko-Latn",
|
|
106
|
+
KURDISH: "name:ku",
|
|
107
|
+
ROMAN_LATIN: "name:la",
|
|
108
|
+
LATVIAN: "name:lv",
|
|
109
|
+
LITHUANIAN: "name:lt",
|
|
110
|
+
LUXEMBOURGISH: "name:lb",
|
|
111
|
+
MACEDONIAN: "name:mk",
|
|
112
|
+
MALAYALAM: "name:ml",
|
|
113
|
+
MALTESE: "name:mt",
|
|
114
|
+
NORWEGIAN: "name:no",
|
|
115
|
+
OCCITAN: "name:oc",
|
|
116
|
+
PERSIAN: "name:fa",
|
|
117
|
+
POLISH: "name:pl",
|
|
118
|
+
PORTUGUESE: "name:pt",
|
|
119
|
+
PUNJABI: "name:pa",
|
|
120
|
+
WESTERN_PUNJABI: "name:pnb",
|
|
121
|
+
ROMANIAN: "name:ro",
|
|
122
|
+
ROMANSH: "name:rm",
|
|
123
|
+
RUSSIAN: "name:ru",
|
|
124
|
+
SCOTTISH_GAELIC: "name:gd",
|
|
125
|
+
SERBIAN_CYRILLIC: "name:sr",
|
|
126
|
+
SERBIAN_LATIN: "name:sr-Latn",
|
|
127
|
+
SLOVAK: "name:sk",
|
|
128
|
+
SLOVENE: "name:sl",
|
|
129
|
+
SPANISH: "name:es",
|
|
130
|
+
SWEDISH: "name:sv",
|
|
131
|
+
TAMIL: "name:ta",
|
|
132
|
+
TELUGU: "name:te",
|
|
133
|
+
THAI: "name:th",
|
|
134
|
+
TURKISH: "name:tr",
|
|
135
|
+
UKRAINIAN: "name:uk",
|
|
136
|
+
URDU: "name:ur",
|
|
137
|
+
VIETNAMIAN_LATIN: "name:vi",
|
|
138
|
+
WELSH: "name:cy",
|
|
102
139
|
} as const;
|
|
103
140
|
|
|
104
141
|
const languagesIsoSet = new Set(Object.values(Language) as Array<string>);
|
|
@@ -123,18 +160,18 @@ type LanguageString = Values<typeof Language>;
|
|
|
123
160
|
|
|
124
161
|
function getBrowserLanguage(): LanguageString {
|
|
125
162
|
if (typeof navigator === "undefined") {
|
|
126
|
-
return
|
|
127
|
-
.resolvedOptions()
|
|
128
|
-
|
|
163
|
+
return `name:${
|
|
164
|
+
Intl.DateTimeFormat().resolvedOptions().locale.split("-")[0]
|
|
165
|
+
}` as LanguageString;
|
|
129
166
|
}
|
|
130
167
|
|
|
131
168
|
const canditatelangs = Array.from(
|
|
132
|
-
new Set(navigator.languages.map((l) => l.split("-")[0]))
|
|
169
|
+
new Set(navigator.languages.map((l) => `name:${l.split("-")[0]}`)),
|
|
133
170
|
).filter((l) => languageCodeSet.has(l as LanguageString));
|
|
134
171
|
|
|
135
172
|
return canditatelangs.length
|
|
136
173
|
? (canditatelangs[0] as LanguageString)
|
|
137
|
-
: Language.
|
|
174
|
+
: Language.LOCAL;
|
|
138
175
|
}
|
|
139
176
|
|
|
140
177
|
export {
|
package/src/mapstyle.ts
CHANGED
|
@@ -13,10 +13,12 @@ export function styleToStyle(
|
|
|
13
13
|
| MapStyleVariant
|
|
14
14
|
| maplibregl.StyleSpecification
|
|
15
15
|
| null
|
|
16
|
-
| undefined
|
|
16
|
+
| undefined,
|
|
17
17
|
): string | maplibregl.StyleSpecification {
|
|
18
18
|
if (!style) {
|
|
19
|
-
return MapStyle[
|
|
19
|
+
return MapStyle[
|
|
20
|
+
mapStylePresetList[0].referenceStyleID as keyof typeof MapStyle
|
|
21
|
+
]
|
|
20
22
|
.getDefaultVariant()
|
|
21
23
|
.getExpandedStyleURL();
|
|
22
24
|
}
|
package/src/tools.ts
CHANGED
|
@@ -13,19 +13,20 @@ export function enableRTL() {
|
|
|
13
13
|
if (maplibregl.getRTLTextPluginStatus() === "unavailable") {
|
|
14
14
|
maplibregl.setRTLTextPlugin(
|
|
15
15
|
defaults.rtlPluginURL,
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
(err?: Error | undefined) => {
|
|
17
|
+
if (err) console.error(err);
|
|
18
|
+
},
|
|
19
|
+
true, // Lazy load the plugin
|
|
18
20
|
);
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
// This comes from:
|
|
23
25
|
// https://github.com/maplibre/maplibre-gl-js/blob/v2.4.0/src/util/util.ts#L223
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
27
|
export function bindAll(fns: Array<string>, context: any): void {
|
|
25
28
|
fns.forEach((fn) => {
|
|
26
|
-
if (
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
+
if (typeof context[fn] !== "function") return;
|
|
29
30
|
context[fn] = context[fn].bind(context);
|
|
30
31
|
});
|
|
31
32
|
}
|
|
@@ -35,7 +36,7 @@ export function bindAll(fns: Array<string>, context: any): void {
|
|
|
35
36
|
export function DOMcreate<K extends keyof HTMLElementTagNameMap>(
|
|
36
37
|
tagName: K,
|
|
37
38
|
className?: string,
|
|
38
|
-
container?: HTMLElement
|
|
39
|
+
container?: HTMLElement,
|
|
39
40
|
): HTMLElementTagNameMap[K] {
|
|
40
41
|
const el = window.document.createElement(tagName);
|
|
41
42
|
if (className !== undefined) el.className = className;
|
|
@@ -55,13 +56,12 @@ export function DOMremove(node: HTMLElement) {
|
|
|
55
56
|
* This function is meant to be used as transformRequest by any Map instance created.
|
|
56
57
|
* It adds the session ID as well as the MapTiler Cloud key from the config to all the requests
|
|
57
58
|
* performed on MapTiler Cloud servers.
|
|
58
|
-
* @param url
|
|
59
|
-
* @param resourceType
|
|
60
|
-
* @returns
|
|
61
59
|
*/
|
|
62
60
|
export function maptilerCloudTransformRequest(
|
|
63
61
|
url: string,
|
|
64
|
-
|
|
62
|
+
// keep incase we need it in the future
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
64
|
+
_resourceType?: ResourceType,
|
|
65
65
|
): RequestParameters {
|
|
66
66
|
let reqUrl = null;
|
|
67
67
|
|
|
@@ -94,19 +94,17 @@ export function maptilerCloudTransformRequest(
|
|
|
94
94
|
/**
|
|
95
95
|
* This combines a user-defined tranformRequest function (optionnal)
|
|
96
96
|
* with the MapTiler Cloud-specific one: maptilerCloudTransformRequest
|
|
97
|
-
* @param userDefinedRTF
|
|
98
|
-
* @returns
|
|
99
97
|
*/
|
|
100
98
|
export function combineTransformRequest(
|
|
101
|
-
userDefinedRTF
|
|
99
|
+
userDefinedRTF?: RequestTransformFunction,
|
|
102
100
|
): RequestTransformFunction {
|
|
103
101
|
return function (
|
|
104
102
|
url: string,
|
|
105
|
-
resourceType?: ResourceType
|
|
103
|
+
resourceType?: ResourceType,
|
|
106
104
|
): RequestParameters {
|
|
107
|
-
if (userDefinedRTF) {
|
|
105
|
+
if (userDefinedRTF !== undefined) {
|
|
108
106
|
const rp = userDefinedRTF(url, resourceType);
|
|
109
|
-
const rp2 = maptilerCloudTransformRequest(rp
|
|
107
|
+
const rp2 = maptilerCloudTransformRequest(rp?.url ?? "");
|
|
110
108
|
|
|
111
109
|
return {
|
|
112
110
|
...rp,
|
|
@@ -117,3 +115,57 @@ export function combineTransformRequest(
|
|
|
117
115
|
}
|
|
118
116
|
};
|
|
119
117
|
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Generate a random string. Handy to create random IDs
|
|
121
|
+
*/
|
|
122
|
+
export function generateRandomString(): string {
|
|
123
|
+
return Math.random().toString(36).substring(2);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Check if a given string is in a uuid format
|
|
128
|
+
*/
|
|
129
|
+
export function isUUID(s: string): boolean {
|
|
130
|
+
// Regular expression to check if string is a valid UUID
|
|
131
|
+
const regexExp =
|
|
132
|
+
/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi;
|
|
133
|
+
return regexExp.test(s);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Attempt a JSON parse of a string but does not throw if the string is not valid JSON, returns `null` instead.
|
|
138
|
+
*/
|
|
139
|
+
export function jsonParseNoThrow<T>(doc: string): T | null {
|
|
140
|
+
try {
|
|
141
|
+
return JSON.parse(doc);
|
|
142
|
+
} catch (e) {
|
|
143
|
+
// pass
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Simple function to check if an object is a GeoJSON
|
|
151
|
+
*/
|
|
152
|
+
export function isValidGeoJSON<T>(obj: T & { type: string }): boolean {
|
|
153
|
+
if (typeof obj !== "object" || Array.isArray(obj) || obj === null)
|
|
154
|
+
return false;
|
|
155
|
+
if (!("type" in obj)) return false;
|
|
156
|
+
|
|
157
|
+
const validTypes = [
|
|
158
|
+
"Feature",
|
|
159
|
+
"FeatureCollection",
|
|
160
|
+
"Point",
|
|
161
|
+
"MultiPoint",
|
|
162
|
+
"LineString",
|
|
163
|
+
"MultiLineString",
|
|
164
|
+
"Polygon",
|
|
165
|
+
"MultiPolygon",
|
|
166
|
+
"GeometryCollection",
|
|
167
|
+
];
|
|
168
|
+
|
|
169
|
+
if (validTypes.includes(obj.type)) return true;
|
|
170
|
+
return false;
|
|
171
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"moduleResolution": "
|
|
3
|
+
"moduleResolution": "Bundler",
|
|
4
|
+
"forceConsistentCasingInFileNames": true,
|
|
5
|
+
"strict": true,
|
|
4
6
|
"target": "es6",
|
|
5
7
|
"declaration": true,
|
|
6
8
|
"allowSyntheticDefaultImports": true,
|
|
7
9
|
"resolveJsonModule": true,
|
|
8
|
-
"esModuleInterop": true
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
"esModuleInterop": true
|
|
11
|
+
},
|
|
12
|
+
"include": ["src/**/*.ts", "src/**/*.tsx", "vite.config.ts"],
|
|
13
|
+
"exclude": ["node_modules", "dist", "demos", "scripts", "docs", "**/*.js", "**/*.cjs"]
|
|
14
|
+
}
|