@maptiler/sdk 1.0.12 → 1.1.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/CHANGELOG.md +11 -0
- package/demos/maptiler-sdk.css +1 -1
- package/demos/maptiler-sdk.umd.js +219 -119
- package/demos/transform-request.html +81 -0
- package/dist/maptiler-sdk.css +1 -1
- package/dist/maptiler-sdk.d.ts +14 -4
- package/dist/maptiler-sdk.min.mjs +1 -1
- package/dist/maptiler-sdk.mjs +78 -35
- package/dist/maptiler-sdk.mjs.map +1 -1
- package/dist/maptiler-sdk.umd.js +219 -119
- package/dist/maptiler-sdk.umd.js.map +1 -1
- package/dist/maptiler-sdk.umd.min.js +67 -66
- package/package.json +3 -3
- package/src/Map.ts +25 -39
- package/src/MaptilerGeolocateControl.ts +2 -1
- package/src/MaptilerLogoControl.ts +3 -6
- package/src/config.ts +3 -0
- package/src/index.ts +2 -2
- package/src/tools.ts +74 -0
package/dist/maptiler-sdk.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import maplibregl__default from 'maplibre-gl';
|
|
2
2
|
export * from 'maplibre-gl';
|
|
3
3
|
import { Base64 } from 'js-base64';
|
|
4
|
-
import { v4 } from 'uuid';
|
|
5
4
|
import EventEmitter from 'events';
|
|
6
5
|
import { config as config$1, MapStyle, mapStylePresetList, expandMapStyle, MapStyleVariant, ReferenceMapStyle, geolocation } from '@maptiler/client';
|
|
7
6
|
export { LanguageGeocoding, MapStyle, MapStyleVariant, ReferenceMapStyle, ServiceError, coordinates, data, geocoding, geolocation, staticMaps } from '@maptiler/client';
|
|
7
|
+
import { v4 } from 'uuid';
|
|
8
8
|
|
|
9
9
|
const Language = {
|
|
10
10
|
/**
|
|
@@ -115,6 +115,7 @@ function getBrowserLanguage() {
|
|
|
115
115
|
return canditatelangs.length ? canditatelangs[0] : Language.LATIN;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
+
const MAPTILER_SESSION_ID = v4();
|
|
118
119
|
class SdkConfig extends EventEmitter {
|
|
119
120
|
constructor() {
|
|
120
121
|
super();
|
|
@@ -231,13 +232,10 @@ class MaptilerLogoControl extends LogoControl {
|
|
|
231
232
|
anchor.style.width = "100px";
|
|
232
233
|
anchor.style.height = "30px";
|
|
233
234
|
anchor.target = "_blank";
|
|
234
|
-
anchor.rel = "noopener
|
|
235
|
+
anchor.rel = "noopener";
|
|
235
236
|
anchor.href = this.linkURL;
|
|
236
|
-
anchor.setAttribute(
|
|
237
|
-
|
|
238
|
-
this._map._getUIString("LogoControl.Title")
|
|
239
|
-
);
|
|
240
|
-
anchor.setAttribute("rel", "noopener nofollow");
|
|
237
|
+
anchor.setAttribute("aria-label", "MapTiler logo");
|
|
238
|
+
anchor.setAttribute("rel", "noopener");
|
|
241
239
|
this._container.appendChild(anchor);
|
|
242
240
|
this._container.style.display = "block";
|
|
243
241
|
this._map.on("resize", this._updateCompact);
|
|
@@ -246,6 +244,22 @@ class MaptilerLogoControl extends LogoControl {
|
|
|
246
244
|
}
|
|
247
245
|
}
|
|
248
246
|
|
|
247
|
+
var __defProp$2 = Object.defineProperty;
|
|
248
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
249
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
250
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
251
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
252
|
+
var __spreadValues$2 = (a, b) => {
|
|
253
|
+
for (var prop in b || (b = {}))
|
|
254
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
255
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
256
|
+
if (__getOwnPropSymbols$2)
|
|
257
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
258
|
+
if (__propIsEnum$2.call(b, prop))
|
|
259
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
260
|
+
}
|
|
261
|
+
return a;
|
|
262
|
+
};
|
|
249
263
|
function enableRTL() {
|
|
250
264
|
if (maplibregl__default.getRTLTextPluginStatus() === "unavailable") {
|
|
251
265
|
maplibregl__default.setRTLTextPlugin(
|
|
@@ -277,6 +291,38 @@ function DOMremove(node) {
|
|
|
277
291
|
node.parentNode.removeChild(node);
|
|
278
292
|
}
|
|
279
293
|
}
|
|
294
|
+
function maptilerCloudTransformRequest(url, resourceType) {
|
|
295
|
+
let reqUrl = null;
|
|
296
|
+
try {
|
|
297
|
+
reqUrl = new URL(url);
|
|
298
|
+
} catch (e) {
|
|
299
|
+
return {
|
|
300
|
+
url
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
if (reqUrl.host === defaults.maptilerApiHost) {
|
|
304
|
+
if (!reqUrl.searchParams.has("key")) {
|
|
305
|
+
reqUrl.searchParams.append("key", config.apiKey);
|
|
306
|
+
}
|
|
307
|
+
if (config.session) {
|
|
308
|
+
reqUrl.searchParams.append("mtsid", MAPTILER_SESSION_ID);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return {
|
|
312
|
+
url: reqUrl.href
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
function combineTransformRequest(userDefinedRTF = null) {
|
|
316
|
+
return function(url, resourceType) {
|
|
317
|
+
if (userDefinedRTF) {
|
|
318
|
+
const rp = userDefinedRTF(url, resourceType);
|
|
319
|
+
const rp2 = maptilerCloudTransformRequest(rp.url);
|
|
320
|
+
return __spreadValues$2(__spreadValues$2({}, rp), rp2);
|
|
321
|
+
} else {
|
|
322
|
+
return maptilerCloudTransformRequest(url);
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
}
|
|
280
326
|
|
|
281
327
|
function styleToStyle(style) {
|
|
282
328
|
if (!style) {
|
|
@@ -429,6 +475,7 @@ var __spreadValues$1 = (a, b) => {
|
|
|
429
475
|
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
430
476
|
const Marker$1 = maplibregl__default.Marker;
|
|
431
477
|
const LngLat$1 = maplibregl__default.LngLat;
|
|
478
|
+
const LngLatBounds$1 = maplibregl__default.LngLatBounds;
|
|
432
479
|
class MaptilerGeolocateControl extends GeolocateControl {
|
|
433
480
|
constructor() {
|
|
434
481
|
super(...arguments);
|
|
@@ -456,7 +503,7 @@ class MaptilerGeolocateControl extends GeolocateControl {
|
|
|
456
503
|
if (currentMapZoom > this.options.fitBoundsOptions.maxZoom) {
|
|
457
504
|
options.zoom = currentMapZoom;
|
|
458
505
|
}
|
|
459
|
-
this._map.fitBounds(
|
|
506
|
+
this._map.fitBounds(LngLatBounds$1.fromLngLat(center, radius), options, {
|
|
460
507
|
geolocateSource: true
|
|
461
508
|
// tag this camera change so it won't cause the control to change to background state
|
|
462
509
|
});
|
|
@@ -635,7 +682,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
635
682
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
636
683
|
});
|
|
637
684
|
};
|
|
638
|
-
const MAPTILER_SESSION_ID = v4();
|
|
639
685
|
const GeolocationType = {
|
|
640
686
|
POINT: "POINT",
|
|
641
687
|
COUNTRY: "COUNTRY"
|
|
@@ -656,29 +702,7 @@ class Map extends maplibregl__default.Map {
|
|
|
656
702
|
super(__spreadProps(__spreadValues({}, options), {
|
|
657
703
|
style,
|
|
658
704
|
maplibreLogo: false,
|
|
659
|
-
transformRequest: (
|
|
660
|
-
let reqUrl = null;
|
|
661
|
-
try {
|
|
662
|
-
reqUrl = new URL(url);
|
|
663
|
-
} catch (e) {
|
|
664
|
-
return {
|
|
665
|
-
url,
|
|
666
|
-
headers: {}
|
|
667
|
-
};
|
|
668
|
-
}
|
|
669
|
-
if (reqUrl.host === defaults.maptilerApiHost) {
|
|
670
|
-
if (!reqUrl.searchParams.has("key")) {
|
|
671
|
-
reqUrl.searchParams.append("key", config.apiKey);
|
|
672
|
-
}
|
|
673
|
-
if (config.session) {
|
|
674
|
-
reqUrl.searchParams.append("mtsid", MAPTILER_SESSION_ID);
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
return {
|
|
678
|
-
url: reqUrl.href,
|
|
679
|
-
headers: {}
|
|
680
|
-
};
|
|
681
|
-
}
|
|
705
|
+
transformRequest: combineTransformRequest(options.transformRequest)
|
|
682
706
|
}));
|
|
683
707
|
this.isTerrainEnabled = false;
|
|
684
708
|
this.terrainExaggeration = 1;
|
|
@@ -788,7 +812,11 @@ class Map extends maplibregl__default.Map {
|
|
|
788
812
|
options.logoPosition
|
|
789
813
|
);
|
|
790
814
|
if (options.attributionControl === false) {
|
|
791
|
-
this.addControl(
|
|
815
|
+
this.addControl(
|
|
816
|
+
new AttributionControl({
|
|
817
|
+
customAttribution: options.customAttribution
|
|
818
|
+
})
|
|
819
|
+
);
|
|
792
820
|
}
|
|
793
821
|
} else if (options.maptilerLogo) {
|
|
794
822
|
this.addControl(new MaptilerLogoControl(), options.logoPosition);
|
|
@@ -1321,6 +1349,21 @@ class Map extends maplibregl__default.Map {
|
|
|
1321
1349
|
getMaptilerSessionId() {
|
|
1322
1350
|
return MAPTILER_SESSION_ID;
|
|
1323
1351
|
}
|
|
1352
|
+
/**
|
|
1353
|
+
* Updates the requestManager's transform request with a new function.
|
|
1354
|
+
*
|
|
1355
|
+
* @param transformRequest A callback run before the Map makes a request for an external URL. The callback can be used to modify the url, set headers, or set the credentials property for cross-origin requests.
|
|
1356
|
+
* Expected to return an object with a `url` property and optionally `headers` and `credentials` properties
|
|
1357
|
+
*
|
|
1358
|
+
* @returns {Map} `this`
|
|
1359
|
+
*
|
|
1360
|
+
* @example
|
|
1361
|
+
* map.setTransformRequest((url: string, resourceType: string) => {});
|
|
1362
|
+
*/
|
|
1363
|
+
setTransformRequest(transformRequest) {
|
|
1364
|
+
super.setTransformRequest(combineTransformRequest(transformRequest));
|
|
1365
|
+
return this;
|
|
1366
|
+
}
|
|
1324
1367
|
}
|
|
1325
1368
|
|
|
1326
1369
|
class Marker extends maplibregl__default.Marker {
|
|
@@ -1675,7 +1718,7 @@ class Point {
|
|
|
1675
1718
|
}
|
|
1676
1719
|
|
|
1677
1720
|
const {
|
|
1678
|
-
supported,
|
|
1721
|
+
// supported,
|
|
1679
1722
|
setRTLTextPlugin,
|
|
1680
1723
|
getRTLTextPluginStatus,
|
|
1681
1724
|
LngLat,
|
|
@@ -1711,5 +1754,5 @@ maplibregl__default.ScaleControl;
|
|
|
1711
1754
|
maplibregl__default.FullscreenControl;
|
|
1712
1755
|
maplibregl__default.TerrainControl;
|
|
1713
1756
|
|
|
1714
|
-
export { AJAXError, AttributionControl, CanvasSource, CanvasSourceMLGL, Evented, FullscreenControl, GeoJSONSource, GeoJSONSourceMLGL, GeolocateControl, GeolocationType, ImageSource, ImageSourceMLGL, Language, LngLat, LngLatBounds, LogoControl, Map, MapMLGL, MaptilerGeolocateControl, MaptilerLogoControl, MaptilerNavigationControl, MaptilerTerrainControl, Marker, MarkerMLGL, MercatorCoordinate, NavigationControl, Point, Popup, PopupMLGL, RasterDEMTileSource, RasterDEMTileSourceMLGL, RasterTileSource, RasterTileSourceMLGL, ScaleControl, SdkConfig, Style, StyleMLGL, TerrainControl, VectorTileSource, VectorTileSourceMLGL, VideoSource, VideoSourceMLGL, addProtocol, clearPrewarmedResources, config, getRTLTextPluginStatus, maxParallelImageRequests, prewarm, removeProtocol, setRTLTextPlugin,
|
|
1757
|
+
export { AJAXError, AttributionControl, CanvasSource, CanvasSourceMLGL, Evented, FullscreenControl, GeoJSONSource, GeoJSONSourceMLGL, GeolocateControl, GeolocationType, ImageSource, ImageSourceMLGL, Language, LngLat, LngLatBounds, LogoControl, Map, MapMLGL, MaptilerGeolocateControl, MaptilerLogoControl, MaptilerNavigationControl, MaptilerTerrainControl, Marker, MarkerMLGL, MercatorCoordinate, NavigationControl, Point, Popup, PopupMLGL, RasterDEMTileSource, RasterDEMTileSourceMLGL, RasterTileSource, RasterTileSourceMLGL, ScaleControl, SdkConfig, Style, StyleMLGL, TerrainControl, VectorTileSource, VectorTileSourceMLGL, VideoSource, VideoSourceMLGL, addProtocol, clearPrewarmedResources, config, getRTLTextPluginStatus, maxParallelImageRequests, prewarm, removeProtocol, setRTLTextPlugin, version, workerCount, workerUrl };
|
|
1715
1758
|
//# sourceMappingURL=maptiler-sdk.mjs.map
|