@maptiler/sdk 2.4.2 → 3.0.0-rc.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/biome.json +3 -0
- package/dist/maptiler-sdk.css +11 -1
- package/dist/maptiler-sdk.mjs +1355 -1265
- 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/package.json +3 -3
- 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maptiler/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-rc.1",
|
|
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": "^
|
|
64
|
+
"@maplibre/maplibre-gl-style-spec": "^21.0.0",
|
|
65
65
|
"@maptiler/client": "^2.0.0",
|
|
66
66
|
"events": "^3.3.0",
|
|
67
67
|
"js-base64": "^3.7.4",
|
|
68
|
-
"maplibre-gl": "
|
|
68
|
+
"maplibre-gl": "5.0.0-pre.6",
|
|
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.
|