-
Notifications
You must be signed in to change notification settings - Fork 288
Expand file tree
/
Copy pathMapExtend.js
More file actions
42 lines (39 loc) · 1.59 KB
/
MapExtend.js
File metadata and controls
42 lines (39 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
* This program are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
import mapboxgl from 'mapbox-gl';
import { decryptSources } from './decryptSource';
import { getServiceKey } from '@supermapgis/iclient-common/util/EncryptRequest';
import { createMapExtendExtending } from '@supermapgis/iclient-common/util/MapExtend';
/**
* @function MapExtend
* @description 扩展 mapboxgl.Map。
* @private
*/
export var MapExtend = (function () {
if (mapboxgl.VectorTileSource && mapboxgl.VectorTileSource.prototype.beforeLoadBak === undefined) {
mapboxgl.VectorTileSource.prototype.beforeLoadBak = mapboxgl.VectorTileSource.prototype.beforeLoad;
mapboxgl.VectorTileSource.prototype.beforeLoad = async function (id, options) {
const url = options && options.tiles && options.tiles[0];
if (decryptSources.values.includes(id) && url) {
const res = await getServiceKey(url);
if (res) {
this.decryptOptions = {
key: res.serviceKey,
algorithm: res.algorithm
};
}
}
this.beforeLoadBak(id, options);
};
}
const originMapProto = mapboxgl.Map.prototype;
if (!originMapProto._inherit) {
mapboxgl.Map = class MapEnhance extends createMapExtendExtending(mapboxgl) {
constructor(options) {
super(options);
}
}
mapboxgl.Map.prototype._inherit = true;
}
})();