@maptiler/sdk 2.4.2 → 3.0.0-rc.2
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/biome.json +3 -0
- package/dist/maptiler-sdk.css +11 -1
- package/dist/maptiler-sdk.mjs +1860 -1719
- package/dist/maptiler-sdk.mjs.map +1 -1
- package/dist/src/Map.d.ts +27 -0
- package/dist/src/MaptilerProjectionControl.d.ts +15 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/language.d.ts +25 -25
- package/package.json +4 -4
- package/readme.md +116 -0
package/dist/src/Map.d.ts
CHANGED
|
@@ -16,6 +16,11 @@ export declare const GeolocationType: {
|
|
|
16
16
|
POINT: "POINT";
|
|
17
17
|
COUNTRY: "COUNTRY";
|
|
18
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* The type of projection, `undefined` means it's decided by the style and if the style does not contain any projection info,
|
|
21
|
+
* if falls back to the default Mercator
|
|
22
|
+
*/
|
|
23
|
+
export type ProjectionTypes = "mercator" | "globe" | undefined;
|
|
19
24
|
/**
|
|
20
25
|
* Options to provide to the `Map` constructor
|
|
21
26
|
*/
|
|
@@ -111,6 +116,15 @@ export type MapOptions = Omit<MapOptionsML, "style" | "maplibreLogo"> & {
|
|
|
111
116
|
* Default: `false`
|
|
112
117
|
*/
|
|
113
118
|
geolocate?: (typeof GeolocationType)[keyof typeof GeolocationType] | boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Show the projection control. (default: `false`, will show if `true`)
|
|
121
|
+
*/
|
|
122
|
+
projectionControl?: boolean | ControlPosition;
|
|
123
|
+
/**
|
|
124
|
+
* Whether the projection should be "mercator" or "globe".
|
|
125
|
+
* If not provided, the style takes precedence. If provided, overwrite the style.
|
|
126
|
+
*/
|
|
127
|
+
projection?: ProjectionTypes;
|
|
114
128
|
};
|
|
115
129
|
/**
|
|
116
130
|
* The Map class can be instanciated to display a map in a `<div>`
|
|
@@ -128,6 +142,7 @@ export declare class Map extends maplibregl.Map {
|
|
|
128
142
|
private terrainAnimationDuration;
|
|
129
143
|
private monitoredStyleUrls;
|
|
130
144
|
private styleInProcess;
|
|
145
|
+
private curentProjection;
|
|
131
146
|
private originalLabelStyle;
|
|
132
147
|
private isStyleLocalized;
|
|
133
148
|
constructor(options: MapOptions);
|
|
@@ -358,4 +373,16 @@ export declare class Map extends maplibregl.Map {
|
|
|
358
373
|
* map.setTransformRequest((url: string, resourceType: string) => {});
|
|
359
374
|
*/
|
|
360
375
|
setTransformRequest(transformRequest: RequestTransformFunction): this;
|
|
376
|
+
/**
|
|
377
|
+
* Returns whether a globe projection is currently being used
|
|
378
|
+
*/
|
|
379
|
+
isGlobeProjection(): boolean;
|
|
380
|
+
/**
|
|
381
|
+
* Uses the globe projection. Animated by default, it can be disabled
|
|
382
|
+
*/
|
|
383
|
+
enableGlobeProjection(animate?: boolean): void;
|
|
384
|
+
/**
|
|
385
|
+
* Uses the Mercator projection. Animated by default, it can be disabled
|
|
386
|
+
*/
|
|
387
|
+
enableMercatorProjection(animate?: boolean): void;
|
|
361
388
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Map as SDKMap } from './Map';
|
|
2
|
+
import { IControl } from 'maplibre-gl';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A `MaptilerProjectionControl` control adds a button to switch from Mercator to Globe projection.
|
|
6
|
+
*/
|
|
7
|
+
export declare class MaptilerProjectionControl implements IControl {
|
|
8
|
+
map: SDKMap;
|
|
9
|
+
container: HTMLElement;
|
|
10
|
+
projectionButton: HTMLButtonElement;
|
|
11
|
+
onAdd(map: SDKMap): HTMLElement;
|
|
12
|
+
onRemove(): void;
|
|
13
|
+
private toggleProjection;
|
|
14
|
+
private updateProjectionIcon;
|
|
15
|
+
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -79,6 +79,7 @@ export * from './MaptilerGeolocateControl';
|
|
|
79
79
|
export * from './MaptilerLogoControl';
|
|
80
80
|
export * from './MaptilerTerrainControl';
|
|
81
81
|
export * from './MaptilerNavigationControl';
|
|
82
|
+
export * from './MaptilerProjectionControl';
|
|
82
83
|
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
84
|
export { getWebGLSupportError } from './tools';
|
|
84
85
|
export { config, SdkConfig } from './config';
|
package/dist/src/language.d.ts
CHANGED
|
@@ -1,80 +1,75 @@
|
|
|
1
1
|
import { LanguageInfo } from '@maptiler/client';
|
|
2
2
|
|
|
3
3
|
declare const Language: {
|
|
4
|
-
readonly
|
|
5
|
-
readonly LATIN: LanguageInfo;
|
|
6
|
-
readonly NON_LATIN: LanguageInfo;
|
|
7
|
-
readonly LOCAL: LanguageInfo;
|
|
4
|
+
readonly ALBANIAN: LanguageInfo;
|
|
8
5
|
readonly AMHARIC: LanguageInfo;
|
|
9
6
|
readonly ARABIC: LanguageInfo;
|
|
7
|
+
readonly ARMENIAN: LanguageInfo;
|
|
10
8
|
readonly AZERBAIJANI: LanguageInfo;
|
|
9
|
+
readonly BASQUE: LanguageInfo;
|
|
11
10
|
readonly BELARUSIAN: LanguageInfo;
|
|
12
|
-
readonly BULGARIAN: LanguageInfo;
|
|
13
11
|
readonly BENGALI: LanguageInfo;
|
|
14
|
-
readonly BRETON: LanguageInfo;
|
|
15
12
|
readonly BOSNIAN: LanguageInfo;
|
|
13
|
+
readonly BRETON: LanguageInfo;
|
|
14
|
+
readonly BULGARIAN: LanguageInfo;
|
|
16
15
|
readonly CATALAN: LanguageInfo;
|
|
17
16
|
readonly CHINESE: LanguageInfo;
|
|
18
17
|
readonly TRADITIONAL_CHINESE: LanguageInfo;
|
|
19
18
|
readonly SIMPLIFIED_CHINESE: LanguageInfo;
|
|
20
19
|
readonly CORSICAN: LanguageInfo;
|
|
20
|
+
readonly CROATIAN: LanguageInfo;
|
|
21
21
|
readonly CZECH: LanguageInfo;
|
|
22
|
-
readonly WELSH: LanguageInfo;
|
|
23
22
|
readonly DANISH: LanguageInfo;
|
|
23
|
+
readonly DUTCH: LanguageInfo;
|
|
24
24
|
readonly GERMAN: LanguageInfo;
|
|
25
25
|
readonly GREEK: LanguageInfo;
|
|
26
26
|
readonly ENGLISH: LanguageInfo;
|
|
27
27
|
readonly ESPERANTO: LanguageInfo;
|
|
28
|
-
readonly SPANISH: LanguageInfo;
|
|
29
28
|
readonly ESTONIAN: LanguageInfo;
|
|
30
|
-
readonly BASQUE: LanguageInfo;
|
|
31
29
|
readonly FINNISH: LanguageInfo;
|
|
32
30
|
readonly FRENCH: LanguageInfo;
|
|
33
31
|
readonly FRISIAN: LanguageInfo;
|
|
34
|
-
readonly
|
|
35
|
-
readonly SCOTTISH_GAELIC: LanguageInfo;
|
|
32
|
+
readonly GEORGIAN: LanguageInfo;
|
|
36
33
|
readonly HEBREW: LanguageInfo;
|
|
37
34
|
readonly HINDI: LanguageInfo;
|
|
38
|
-
readonly CROATIAN: LanguageInfo;
|
|
39
35
|
readonly HUNGARIAN: LanguageInfo;
|
|
40
|
-
readonly ARMENIAN: LanguageInfo;
|
|
41
|
-
readonly INDONESIAN: LanguageInfo;
|
|
42
36
|
readonly ICELANDIC: LanguageInfo;
|
|
37
|
+
readonly INDONESIAN: LanguageInfo;
|
|
38
|
+
readonly IRISH: LanguageInfo;
|
|
43
39
|
readonly ITALIAN: LanguageInfo;
|
|
44
40
|
readonly JAPANESE: LanguageInfo;
|
|
45
41
|
readonly JAPANESE_HIRAGANA: LanguageInfo;
|
|
46
42
|
readonly JAPANESE_2018: LanguageInfo;
|
|
47
43
|
readonly JAPANESE_KANA: LanguageInfo;
|
|
48
44
|
readonly JAPANESE_LATIN: LanguageInfo;
|
|
49
|
-
readonly GEORGIAN: LanguageInfo;
|
|
50
|
-
readonly KAZAKH: LanguageInfo;
|
|
51
45
|
readonly KANNADA: LanguageInfo;
|
|
46
|
+
readonly KAZAKH: LanguageInfo;
|
|
52
47
|
readonly KOREAN: LanguageInfo;
|
|
53
48
|
readonly KOREAN_LATIN: LanguageInfo;
|
|
54
49
|
readonly KURDISH: LanguageInfo;
|
|
55
50
|
readonly CLASSICAL_LATIN: LanguageInfo;
|
|
56
|
-
readonly LUXEMBOURGISH: LanguageInfo;
|
|
57
|
-
readonly LITHUANIAN: LanguageInfo;
|
|
58
51
|
readonly LATVIAN: LanguageInfo;
|
|
52
|
+
readonly LITHUANIAN: LanguageInfo;
|
|
53
|
+
readonly LUXEMBOURGISH: LanguageInfo;
|
|
59
54
|
readonly MACEDONIAN: LanguageInfo;
|
|
60
55
|
readonly MALAYALAM: LanguageInfo;
|
|
61
56
|
readonly MALTESE: LanguageInfo;
|
|
62
|
-
readonly DUTCH: LanguageInfo;
|
|
63
57
|
readonly NORWEGIAN: LanguageInfo;
|
|
64
58
|
readonly OCCITAN: LanguageInfo;
|
|
65
|
-
readonly POLISH: LanguageInfo;
|
|
66
59
|
readonly PERSIAN: LanguageInfo;
|
|
60
|
+
readonly POLISH: LanguageInfo;
|
|
61
|
+
readonly PORTUGUESE: LanguageInfo;
|
|
67
62
|
readonly PUNJABI: LanguageInfo;
|
|
68
63
|
readonly WESTERN_PUNJABI: LanguageInfo;
|
|
69
|
-
readonly PORTUGUESE: LanguageInfo;
|
|
70
|
-
readonly ROMANSH: LanguageInfo;
|
|
71
64
|
readonly ROMANIAN: LanguageInfo;
|
|
65
|
+
readonly ROMANSH: LanguageInfo;
|
|
72
66
|
readonly RUSSIAN: LanguageInfo;
|
|
73
|
-
readonly SLOVAK: LanguageInfo;
|
|
74
|
-
readonly SLOVENE: LanguageInfo;
|
|
75
|
-
readonly ALBANIAN: LanguageInfo;
|
|
76
67
|
readonly SERBIAN_CYRILLIC: LanguageInfo;
|
|
77
68
|
readonly SERBIAN_LATIN: LanguageInfo;
|
|
69
|
+
readonly SCOTTISH_GAELIC: LanguageInfo;
|
|
70
|
+
readonly SLOVAK: LanguageInfo;
|
|
71
|
+
readonly SLOVENE: LanguageInfo;
|
|
72
|
+
readonly SPANISH: LanguageInfo;
|
|
78
73
|
readonly SWEDISH: LanguageInfo;
|
|
79
74
|
readonly TAMIL: LanguageInfo;
|
|
80
75
|
readonly TELUGU: LanguageInfo;
|
|
@@ -82,6 +77,11 @@ declare const Language: {
|
|
|
82
77
|
readonly TURKISH: LanguageInfo;
|
|
83
78
|
readonly UKRAINIAN: LanguageInfo;
|
|
84
79
|
readonly VIETNAMESE: LanguageInfo;
|
|
80
|
+
readonly WELSH: LanguageInfo;
|
|
81
|
+
readonly AUTO: LanguageInfo;
|
|
82
|
+
readonly LATIN: LanguageInfo;
|
|
83
|
+
readonly NON_LATIN: LanguageInfo;
|
|
84
|
+
readonly LOCAL: LanguageInfo;
|
|
85
85
|
/**
|
|
86
86
|
* Language mode to display labels in both the local language and the language of the visitor's device, concatenated.
|
|
87
87
|
* Note that if those two languages are the same, labels won't be duplicated.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maptiler/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-rc.2",
|
|
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",
|
|
@@ -61,11 +61,11 @@
|
|
|
61
61
|
"vitest": "^0.34.2"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@maplibre/maplibre-gl-style-spec": "^
|
|
65
|
-
"@maptiler/client": "^2.
|
|
64
|
+
"@maplibre/maplibre-gl-style-spec": "^22.0.0",
|
|
65
|
+
"@maptiler/client": "^2.2.0",
|
|
66
66
|
"events": "^3.3.0",
|
|
67
67
|
"js-base64": "^3.7.4",
|
|
68
|
-
"maplibre-gl": "
|
|
68
|
+
"maplibre-gl": "^5.0.0-pre.7",
|
|
69
69
|
"uuid": "^9.0.0"
|
|
70
70
|
}
|
|
71
71
|
}
|
package/readme.md
CHANGED
|
@@ -261,6 +261,122 @@ And can even be provided in the URI form:
|
|
|
261
261
|
map.setStyle("maptiler://c912ffc8-2360-487a-973b-59d037fb15b8");
|
|
262
262
|
```
|
|
263
263
|
|
|
264
|
+
# Globe or Mercator projection?
|
|
265
|
+
The **Web Mercator projection** [*(Wikipedia)*](https://en.wikipedia.org/wiki/Web_Mercator_projection) has been the go-to standard in cartography since the early days or web mapping. Partly for technical reasons but also because it is great for navigation as well as for showing the entire world in one screen, with no hidden face. That being said, Mercator's heavy distorsion at high latitudes, as well a the discontinuity at the poles can be a limitation for data visualization and has been critisized for providing a biased view of the world.
|
|
266
|
+
|
|
267
|
+
The **globe projection**, available starting from MapTiler SDK v3, does not suffer from these biases and can feel overall more playfull than Mercator. It can be a great choice for semi-global data visualization, especially for data close to the poles, thanks to its geographic continuity.
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
| Mercator projection | Globe projection |
|
|
271
|
+
| :--------: | :-------: |
|
|
272
|
+
|  |  |
|
|
273
|
+
|
|
274
|
+
The choice between Mercator and Globe can be done at different levels and moments in the lifecycle of the map, yet, unless stated otherwise, **Mercator remains the default**.
|
|
275
|
+
|
|
276
|
+
- In the style, using the `projection` top-level property.
|
|
277
|
+
For globe:
|
|
278
|
+
```js
|
|
279
|
+
{
|
|
280
|
+
"version": ...,
|
|
281
|
+
"id": ...,
|
|
282
|
+
"name": ...,
|
|
283
|
+
"sources": ...,
|
|
284
|
+
"layers": ...,
|
|
285
|
+
|
|
286
|
+
// Make the style use the globe projection at load time
|
|
287
|
+
"projection": {
|
|
288
|
+
"type": "globe"
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// ...
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
or for Mercator:
|
|
295
|
+
```js
|
|
296
|
+
{
|
|
297
|
+
"version": ...,
|
|
298
|
+
"id": ...,
|
|
299
|
+
"name": ...,
|
|
300
|
+
"sources": ...,
|
|
301
|
+
"layers": ...,
|
|
302
|
+
|
|
303
|
+
// Make the style use the mercator projection at load time
|
|
304
|
+
"projection": {
|
|
305
|
+
"type": "mercator"
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// ...
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
- In the constructor of the `Map` class, using the `projection` option. For globe:
|
|
313
|
+
```ts
|
|
314
|
+
const map = new maptilersdk.Map({
|
|
315
|
+
container: "map",
|
|
316
|
+
projection: "globe", // Force a globe projection
|
|
317
|
+
});
|
|
318
|
+
```
|
|
319
|
+
or for Mercator:
|
|
320
|
+
```ts
|
|
321
|
+
const map = new maptilersdk.Map({
|
|
322
|
+
container: "map",
|
|
323
|
+
projection: "mercator", // Force a mercator projection
|
|
324
|
+
})
|
|
325
|
+
```
|
|
326
|
+
This will overwrite the `projection` property from the style (if any) and will persist it later if the map style was to change.
|
|
327
|
+
|
|
328
|
+
- Use the built-in methods:
|
|
329
|
+
```ts
|
|
330
|
+
const animate = false;
|
|
331
|
+
map.enableGlobeProjection(animate);
|
|
332
|
+
// or
|
|
333
|
+
map.enableMercatorProjection(animate);
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
The animated transition is enabled by default, but can be disabled by passing `false`, as in the example above. Similarly to the `projection` option in the constructor, this will overwrite the projection settings from style (if any) and persist it when the style is updated.
|
|
337
|
+
|
|
338
|
+
The projection setter built in Maplibre GL JS is also usable:
|
|
339
|
+
```ts
|
|
340
|
+
map.setProjection({type: "mercator"});
|
|
341
|
+
// or
|
|
342
|
+
map.setProjection({type: "globe"});
|
|
343
|
+
```
|
|
344
|
+
but this will not automatically animate the transition and may cause rendering glitches.
|
|
345
|
+
|
|
346
|
+
- Using the `MaptilerProjectionControl`. Not mounted by default, it can easily be added with a single option in the `Map` constructor:
|
|
347
|
+
```ts
|
|
348
|
+
const map = new maptilersdk.Map({
|
|
349
|
+
container: "map",
|
|
350
|
+
projectionControl: true, // or the position such as "top-left", "top-right",
|
|
351
|
+
}); // "bottom-right" or "bottom-left"
|
|
352
|
+
```
|
|
353
|
+
This dedicated control will show a globe icon <img src="images/screenshots/globe_icon.png" width="30px"/> to transition from Mercator to globe projection and will show a flat map icon <img src="images/screenshots/mercator_icon.png" width="30px"/> to transition from globe to Mercator projection. The chosen projection persist with future style changes.
|
|
354
|
+
|
|
355
|
+
## Field of view (FOV)
|
|
356
|
+
The internal camera has a default vertical field of view [*(wikipedia)*](https://en.wikipedia.org/wiki/Field_of_view) of a wide ~36.86 degrees. In globe mode, such a large *FOV* reduces the amount of the Earth that can be seen at once and exaggerates the central part, comparably to a fisheye lens. In many cases, a narrower *FOV* is preferable. Here is how to update if:
|
|
357
|
+
|
|
358
|
+
```ts
|
|
359
|
+
// Ajust de FOV, with values from 1 to 50
|
|
360
|
+
map.setVerticalFieldOfView(10);
|
|
361
|
+
```
|
|
362
|
+
> 📣 *__Note:__* with the Mercator projection, it is possible to set a FOV of `0`, which yields a true orthographic projection [*(wikipedia)*](https://en.wikipedia.org/wiki/Orthographic_projection), but the globe projection does not allow this.
|
|
363
|
+
|
|
364
|
+
Here is a table of FOV comparison:
|
|
365
|
+
| 01° | 10° | 20° | 30° | 40° | 50° |
|
|
366
|
+
| :--------: | :-------: |:-------: |:-------: |:-------: |:-------: |
|
|
367
|
+
|  |  |  |  |  |  |
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
## Globe screenshots
|
|
371
|
+

|
|
372
|
+

|
|
373
|
+

|
|
374
|
+

|
|
375
|
+

|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
> 📣 *__Note:__* Terrain is not fully compatible with the globe projection yet so it's better to disable it at low zoom level (from afar) and to choose the Mercator projection at higher zoom level (from up close).
|
|
379
|
+
|
|
264
380
|
# Centering the map on visitors
|
|
265
381
|
It is sometimes handy to center the map on the visitor's location, and there are multiple ways of doing it but for the SDK, we have decided to make this extra simple by using the [IP geolocation](#%EF%B8%8F%EF%B8%8F-geolocation) API provided by [MapTiler Cloud](https://docs.maptiler.com/cloud/api/geolocation/), directly exposed as a single option of the `Map` constructor. There are two strategies:
|
|
266
382
|
1. `POINT`: centering the map on the actual visitor location, optionally using the `zoom` option (zoom level `13` if none is provided). As a more precise option, if the user has previously granted access to the browser location (more precise) then this is going to be used.
|