@maptiler/sdk 1.1.2 → 1.2.1
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 +105 -51
- package/colorramp.md +93 -0
- package/dist/maptiler-sdk.d.ts +1226 -124
- package/dist/maptiler-sdk.min.mjs +3 -1
- package/dist/maptiler-sdk.mjs +3582 -483
- package/dist/maptiler-sdk.mjs.map +1 -1
- package/dist/maptiler-sdk.umd.js +4524 -863
- 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 +493 -5
- package/rollup.config.js +2 -16
- package/src/Map.ts +515 -359
- 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 +90 -121
- 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
|
@@ -2,14 +2,11 @@
|
|
|
2
2
|
* Maplibre export first, then extensions can overload the exports.
|
|
3
3
|
*/
|
|
4
4
|
export * from "maplibre-gl";
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* To perform explicit named export so that they are included in the UMD bundle
|
|
8
7
|
*/
|
|
9
8
|
// import * as ML from "maplibre-gl";
|
|
10
|
-
|
|
11
9
|
import maplibregl from "maplibre-gl";
|
|
12
|
-
|
|
13
10
|
const {
|
|
14
11
|
// supported,
|
|
15
12
|
setRTLTextPlugin,
|
|
@@ -28,7 +25,6 @@ const {
|
|
|
28
25
|
addProtocol,
|
|
29
26
|
removeProtocol,
|
|
30
27
|
} = maplibregl;
|
|
31
|
-
|
|
32
28
|
// We still want to export maplibregl.Map, but as a different name
|
|
33
29
|
const MapMLGL = maplibregl.Map;
|
|
34
30
|
const MarkerMLGL = maplibregl.Marker;
|
|
@@ -48,7 +44,6 @@ const LogoControlMLGL = maplibregl.LogoControl;
|
|
|
48
44
|
const ScaleControlMLGL = maplibregl.ScaleControl;
|
|
49
45
|
const FullscreenControlMLGL = maplibregl.FullscreenControl;
|
|
50
46
|
const TerrainControlMLGL = maplibregl.TerrainControl;
|
|
51
|
-
|
|
52
47
|
export {
|
|
53
48
|
// supported,
|
|
54
49
|
setRTLTextPlugin,
|
|
@@ -78,7 +73,6 @@ export {
|
|
|
78
73
|
removeProtocol,
|
|
79
74
|
MapMLGL,
|
|
80
75
|
};
|
|
81
|
-
|
|
82
76
|
// Exporting types of class instances from MapLibre:
|
|
83
77
|
export type NavigationControlMLGL = InstanceType<typeof NavigationControlMLGL>;
|
|
84
78
|
export type GeolocateControlMLGL = InstanceType<typeof GeolocateControlMLGL>;
|
|
@@ -107,126 +101,101 @@ export type RasterTileSourceMLGL = InstanceType<typeof RasterTileSourceMLGL>;
|
|
|
107
101
|
export type VectorTileSourceMLGL = InstanceType<typeof VectorTileSourceMLGL>;
|
|
108
102
|
export type VideoSourceMLGL = InstanceType<typeof VideoSourceMLGL>;
|
|
109
103
|
export type MapMLGL = InstanceType<typeof MapMLGL>;
|
|
110
|
-
|
|
111
104
|
// SDK specific
|
|
112
|
-
import { Map, GeolocationType } from "./Map";
|
|
113
|
-
import type { MapOptions, LoadWithTerrainEvent } from "./Map";
|
|
114
|
-
|
|
115
|
-
import { Marker } from "./Marker";
|
|
116
|
-
import { Popup } from "./Popup";
|
|
117
|
-
import { Style } from "./Style";
|
|
118
|
-
import { CanvasSource } from "./CanvasSource";
|
|
119
|
-
import { GeoJSONSource } from "./GeoJSONSource";
|
|
120
|
-
import { ImageSource } from "./ImageSource";
|
|
121
|
-
import { RasterTileSource } from "./RasterTileSource";
|
|
122
|
-
import { RasterDEMTileSource } from "./RasterDEMTileSource";
|
|
123
|
-
import { VectorTileSource } from "./VectorTileSource";
|
|
124
|
-
import { VideoSource } from "./VideoSource";
|
|
125
|
-
import { NavigationControl } from "./NavigationControl";
|
|
126
|
-
import { GeolocateControl } from "./GeolocateControl";
|
|
127
|
-
import { AttributionControl } from "./AttributionControl";
|
|
128
|
-
import { LogoControl } from "./LogoControl";
|
|
129
|
-
import { ScaleControl } from "./ScaleControl";
|
|
130
|
-
import { FullscreenControl } from "./FullscreenControl";
|
|
131
|
-
import { TerrainControl } from "./TerrainControl";
|
|
132
|
-
|
|
133
|
-
// Import of modified versions of the controls
|
|
134
|
-
import { MaptilerGeolocateControl } from "./MaptilerGeolocateControl";
|
|
135
|
-
import { MaptilerLogoControl } from "./MaptilerLogoControl";
|
|
136
|
-
import { MaptilerTerrainControl } from "./MaptilerTerrainControl";
|
|
137
|
-
import { MaptilerNavigationControl } from "./MaptilerNavigationControl";
|
|
138
|
-
|
|
139
|
-
// importing client functions to expose them as part of the SDK
|
|
140
|
-
import type {
|
|
141
|
-
BBox,
|
|
142
|
-
Position,
|
|
143
|
-
GeocodingOptions,
|
|
144
|
-
CoordinatesSearchOptions,
|
|
145
|
-
CenteredStaticMapOptions,
|
|
146
|
-
AutomaticStaticMapOptions,
|
|
147
|
-
BoundedStaticMapOptions,
|
|
148
|
-
} from "@maptiler/client";
|
|
149
|
-
|
|
150
|
-
import {
|
|
151
|
-
geocoding,
|
|
152
|
-
geolocation,
|
|
153
|
-
coordinates,
|
|
154
|
-
data,
|
|
155
|
-
staticMaps,
|
|
156
|
-
ServiceError,
|
|
157
|
-
LanguageGeocoding,
|
|
158
|
-
LanguageGeocodingString,
|
|
159
|
-
ReferenceMapStyle,
|
|
160
|
-
MapStyle,
|
|
161
|
-
MapStyleVariant,
|
|
162
|
-
} from "@maptiler/client";
|
|
163
|
-
|
|
164
|
-
import type { MapStyleType } from "@maptiler/client";
|
|
165
|
-
|
|
166
|
-
import { Point } from "./Point";
|
|
167
|
-
import type { Matrix2 } from "./Point";
|
|
168
|
-
|
|
169
|
-
// Importing enums and configs
|
|
170
|
-
import { config, SdkConfig } from "./config";
|
|
171
|
-
import { Language, LanguageString, LanguageKey } from "./language";
|
|
172
|
-
import type { Unit } from "./unit";
|
|
173
|
-
|
|
174
|
-
// Exporting types
|
|
175
|
-
export type {
|
|
176
|
-
MapOptions,
|
|
177
|
-
LoadWithTerrainEvent,
|
|
178
|
-
GeocodingOptions,
|
|
179
|
-
BBox,
|
|
180
|
-
Position,
|
|
181
|
-
CoordinatesSearchOptions,
|
|
182
|
-
CenteredStaticMapOptions,
|
|
183
|
-
BoundedStaticMapOptions,
|
|
184
|
-
AutomaticStaticMapOptions,
|
|
185
|
-
LanguageString,
|
|
186
|
-
LanguageKey,
|
|
187
|
-
LanguageGeocodingString,
|
|
188
|
-
Unit,
|
|
189
|
-
MapStyleType,
|
|
190
|
-
Matrix2,
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
// Exporting classes, objects, functions, etc.
|
|
194
105
|
export {
|
|
195
106
|
Map,
|
|
196
|
-
Marker,
|
|
197
|
-
Popup,
|
|
198
|
-
Style,
|
|
199
|
-
CanvasSource,
|
|
200
|
-
GeoJSONSource,
|
|
201
|
-
ImageSource,
|
|
202
|
-
RasterTileSource,
|
|
203
|
-
RasterDEMTileSource,
|
|
204
|
-
VideoSource,
|
|
205
|
-
NavigationControl,
|
|
206
|
-
GeolocateControl,
|
|
207
|
-
AttributionControl,
|
|
208
|
-
LogoControl,
|
|
209
|
-
ScaleControl,
|
|
210
|
-
FullscreenControl,
|
|
211
|
-
TerrainControl,
|
|
212
|
-
VectorTileSource,
|
|
213
107
|
GeolocationType,
|
|
214
|
-
|
|
215
|
-
|
|
108
|
+
type MapOptions,
|
|
109
|
+
type LoadWithTerrainEvent,
|
|
110
|
+
} from "./Map";
|
|
111
|
+
export { Marker } from "./Marker";
|
|
112
|
+
export { Popup } from "./Popup";
|
|
113
|
+
export { Style } from "./Style";
|
|
114
|
+
export { CanvasSource } from "./CanvasSource";
|
|
115
|
+
export { GeoJSONSource } from "./GeoJSONSource";
|
|
116
|
+
export { ImageSource } from "./ImageSource";
|
|
117
|
+
export { RasterTileSource } from "./RasterTileSource";
|
|
118
|
+
export { RasterDEMTileSource } from "./RasterDEMTileSource";
|
|
119
|
+
export { VectorTileSource } from "./VectorTileSource";
|
|
120
|
+
export { VideoSource } from "./VideoSource";
|
|
121
|
+
export { NavigationControl } from "./NavigationControl";
|
|
122
|
+
export { GeolocateControl } from "./GeolocateControl";
|
|
123
|
+
export { AttributionControl } from "./AttributionControl";
|
|
124
|
+
export { LogoControl } from "./LogoControl";
|
|
125
|
+
export { ScaleControl } from "./ScaleControl";
|
|
126
|
+
export { FullscreenControl } from "./FullscreenControl";
|
|
127
|
+
export { TerrainControl } from "./TerrainControl";
|
|
128
|
+
// Export of modified versions of the controls
|
|
129
|
+
export * from "./MaptilerGeolocateControl";
|
|
130
|
+
export * from "./MaptilerLogoControl";
|
|
131
|
+
export * from "./MaptilerTerrainControl";
|
|
132
|
+
export * from "./MaptilerNavigationControl";
|
|
133
|
+
export {
|
|
134
|
+
type AutomaticStaticMapOptions,
|
|
135
|
+
type BoundedStaticMapOptions,
|
|
136
|
+
type BufferToPixelDataFunction,
|
|
137
|
+
type ByIdGeocodingOptions,
|
|
138
|
+
type CenteredStaticMapOptions,
|
|
139
|
+
type CommonForwardAndReverseGeocodingOptions,
|
|
140
|
+
type CoordinateExport,
|
|
141
|
+
type CoordinateGrid,
|
|
142
|
+
type CoordinateId,
|
|
143
|
+
type CoordinateSearch,
|
|
144
|
+
type CoordinateSearchResult,
|
|
145
|
+
type CoordinateTransformResult,
|
|
146
|
+
type CoordinateTransformation,
|
|
147
|
+
type Coordinates,
|
|
148
|
+
type CoordinatesSearchOptions,
|
|
149
|
+
type CoordinatesTransformOptions,
|
|
150
|
+
type DefaultTransformation,
|
|
151
|
+
type ElevationAtOptions,
|
|
152
|
+
type ElevationBatchOptions,
|
|
153
|
+
type FeatureHierarchy,
|
|
154
|
+
type FetchFunction,
|
|
155
|
+
type GeocodingFeature,
|
|
156
|
+
type GeocodingOptions,
|
|
157
|
+
type GeocodingSearchResult,
|
|
158
|
+
type GeolocationInfoOptions,
|
|
159
|
+
type GeolocationResult,
|
|
160
|
+
type GetDataOptions,
|
|
161
|
+
LanguageGeocoding,
|
|
162
|
+
type LanguageGeocodingOptions,
|
|
163
|
+
type LanguageGeocodingString,
|
|
164
|
+
MapStyle,
|
|
165
|
+
type MapStylePreset,
|
|
166
|
+
type MapStyleType,
|
|
167
|
+
MapStyleVariant,
|
|
168
|
+
type PixelData,
|
|
169
|
+
ReferenceMapStyle,
|
|
170
|
+
type ReverseGeocodingOptions,
|
|
216
171
|
ServiceError,
|
|
217
|
-
|
|
218
|
-
|
|
172
|
+
type StaticMapBaseOptions,
|
|
173
|
+
type StaticMapMarker,
|
|
174
|
+
type TileJSON,
|
|
175
|
+
type XYZ,
|
|
176
|
+
bufferToPixelDataBrowser,
|
|
177
|
+
circumferenceAtLatitude,
|
|
219
178
|
coordinates,
|
|
220
179
|
data,
|
|
180
|
+
elevation,
|
|
181
|
+
expandMapStyle,
|
|
182
|
+
geocoding,
|
|
183
|
+
geolocation,
|
|
184
|
+
getAutoLanguageGeocoding,
|
|
185
|
+
getBufferToPixelDataParser,
|
|
186
|
+
getTileCache,
|
|
187
|
+
mapStylePresetList,
|
|
188
|
+
math,
|
|
189
|
+
misc,
|
|
221
190
|
staticMaps,
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
191
|
+
styleToStyle,
|
|
192
|
+
} from "@maptiler/client";
|
|
193
|
+
|
|
194
|
+
export * from "./Point";
|
|
195
|
+
export { config, SdkConfig } from "./config";
|
|
196
|
+
export * from "./language";
|
|
197
|
+
export { type Unit } from "./unit";
|
|
198
|
+
export * from "./Minimap";
|
|
199
|
+
export * from "./converters";
|
|
200
|
+
export * from "./colorramp";
|
|
201
|
+
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
|
+
}
|