aviation-chart 2.0.8 → 2.0.10
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/dist/nav-sdk.d.ts +5 -2
- package/dist/nav-sdk.esm.js +169 -36
- package/package.json +1 -1
package/dist/nav-sdk.d.ts
CHANGED
|
@@ -535,6 +535,7 @@ interface MapSDKOptions {
|
|
|
535
535
|
staticUrl?: string;
|
|
536
536
|
apiUrl?: string;
|
|
537
537
|
apiVersion?: string;
|
|
538
|
+
licenseKey?: string;
|
|
538
539
|
spriteUrl?: string;
|
|
539
540
|
terrainUrl?: string;
|
|
540
541
|
layers?: Record<string, boolean>;
|
|
@@ -833,8 +834,8 @@ interface GeometryFeature {
|
|
|
833
834
|
};
|
|
834
835
|
properties: Record<string, any>;
|
|
835
836
|
}
|
|
836
|
-
declare function searchFeatures(baseUrl: string,
|
|
837
|
-
declare function getFeatureGeometry(baseUrl: string,
|
|
837
|
+
declare function searchFeatures(baseUrl: string, auth: string | Record<string, string> | undefined, params: SearchParams, version?: string): Promise<SearchResultItem[]>;
|
|
838
|
+
declare function getFeatureGeometry(baseUrl: string, auth: string | Record<string, string> | undefined, params: GeometryParams, version?: string): Promise<GeometryFeature>;
|
|
838
839
|
declare function getPeriods(baseUrl: string, apiKey?: string, signal?: AbortSignal, version?: string): Promise<string[]>;
|
|
839
840
|
|
|
840
841
|
interface SelectFeatureOptions {
|
|
@@ -962,6 +963,7 @@ declare class MapSDK implements IMapSDK {
|
|
|
962
963
|
private _landGeojson;
|
|
963
964
|
private _chartApiUrl;
|
|
964
965
|
private _apiVersion;
|
|
966
|
+
private _tileCipher;
|
|
965
967
|
readonly ready: Promise<void>;
|
|
966
968
|
private _resolveReady;
|
|
967
969
|
private _rejectReady;
|
|
@@ -1049,6 +1051,7 @@ declare class MapSDK implements IMapSDK {
|
|
|
1049
1051
|
getPeriod(): string | undefined;
|
|
1050
1052
|
generateCurrentPeriod(): Promise<string>;
|
|
1051
1053
|
search(params: SearchParams): Promise<SearchResultItem[]>;
|
|
1054
|
+
private _apiAuth;
|
|
1052
1055
|
getGeometry(params: GeometryParams): Promise<GeometryFeature>;
|
|
1053
1056
|
getPeriods(signal?: AbortSignal): Promise<string[]>;
|
|
1054
1057
|
showGraticule(): void;
|
package/dist/nav-sdk.esm.js
CHANGED
|
@@ -4284,8 +4284,10 @@ class GraticuleManager {
|
|
|
4284
4284
|
}
|
|
4285
4285
|
}
|
|
4286
4286
|
|
|
4287
|
-
function authHeaders(
|
|
4288
|
-
|
|
4287
|
+
function authHeaders(auth) {
|
|
4288
|
+
if (!auth)
|
|
4289
|
+
return {};
|
|
4290
|
+
return typeof auth === "string" ? { "X-Api-Key": auth } : auth;
|
|
4289
4291
|
}
|
|
4290
4292
|
function apiPrefix$1(baseUrl, version) {
|
|
4291
4293
|
const base = baseUrl.replace(/\/$/, "");
|
|
@@ -4299,14 +4301,15 @@ async function toJSON(res) {
|
|
|
4299
4301
|
}
|
|
4300
4302
|
catch {
|
|
4301
4303
|
}
|
|
4304
|
+
const detailMsg = detail.trim();
|
|
4302
4305
|
const msg = res.status === 403
|
|
4303
|
-
?
|
|
4304
|
-
: `请求失败(${res.status})${
|
|
4306
|
+
? `接口鉴权失败(403):${detailMsg || "请检查 licenseKey / apiKey 是否正确"}`
|
|
4307
|
+
: `请求失败(${res.status})${detailMsg ? ": " + detailMsg : ""}`;
|
|
4305
4308
|
throw new Error(msg);
|
|
4306
4309
|
}
|
|
4307
4310
|
return res.json();
|
|
4308
4311
|
}
|
|
4309
|
-
async function searchFeatures(baseUrl,
|
|
4312
|
+
async function searchFeatures(baseUrl, auth, params, version) {
|
|
4310
4313
|
const { q, type, period, limit, signal } = params;
|
|
4311
4314
|
if (!q || !q.trim()) {
|
|
4312
4315
|
throw new Error("search: q 参数必填");
|
|
@@ -4320,13 +4323,13 @@ async function searchFeatures(baseUrl, apiKey, params, version) {
|
|
|
4320
4323
|
qs.set("limit", String(limit));
|
|
4321
4324
|
const res = await fetch(`${apiPrefix$1(baseUrl, version)}/search?${qs.toString()}`, {
|
|
4322
4325
|
method: "GET",
|
|
4323
|
-
headers: authHeaders(
|
|
4326
|
+
headers: authHeaders(auth),
|
|
4324
4327
|
...(signal ? { signal } : {}),
|
|
4325
4328
|
});
|
|
4326
4329
|
const data = await toJSON(res);
|
|
4327
4330
|
return data.results ?? [];
|
|
4328
4331
|
}
|
|
4329
|
-
async function getFeatureGeometry(baseUrl,
|
|
4332
|
+
async function getFeatureGeometry(baseUrl, auth, params, version) {
|
|
4330
4333
|
const { type, id, period, signal } = params;
|
|
4331
4334
|
if (!type || !id) {
|
|
4332
4335
|
throw new Error("getGeometry: type 和 id 参数必填");
|
|
@@ -4336,7 +4339,7 @@ async function getFeatureGeometry(baseUrl, apiKey, params, version) {
|
|
|
4336
4339
|
qs.set("period", period);
|
|
4337
4340
|
const res = await fetch(`${apiPrefix$1(baseUrl, version)}/geometry?${qs.toString()}`, {
|
|
4338
4341
|
method: "GET",
|
|
4339
|
-
headers: authHeaders(
|
|
4342
|
+
headers: authHeaders(auth),
|
|
4340
4343
|
...(signal ? { signal } : {}),
|
|
4341
4344
|
});
|
|
4342
4345
|
return toJSON(res);
|
|
@@ -7446,13 +7449,15 @@ function getAviationBaseStyle(opts) {
|
|
|
7446
7449
|
}
|
|
7447
7450
|
};
|
|
7448
7451
|
}
|
|
7449
|
-
function navdataTilesUrl(apiUrl, period, version) {
|
|
7450
|
-
|
|
7452
|
+
function navdataTilesUrl(apiUrl, period, version, encrypted) {
|
|
7453
|
+
const seg = encrypted ? "tiles/e" : "tiles";
|
|
7454
|
+
const url = `${apiPrefix(apiUrl, version)}/${seg}/${period}/{z}/{x}/{y}.pbf`;
|
|
7455
|
+
return encrypted ? `kunyu://${url}` : url;
|
|
7451
7456
|
}
|
|
7452
|
-
function getNavdataSource(apiUrl, period, version) {
|
|
7457
|
+
function getNavdataSource(apiUrl, period, version, encrypted) {
|
|
7453
7458
|
return {
|
|
7454
7459
|
type: "vector",
|
|
7455
|
-
tiles: [navdataTilesUrl(apiUrl, period, version)],
|
|
7460
|
+
tiles: [navdataTilesUrl(apiUrl, period, version, encrypted)],
|
|
7456
7461
|
minzoom: 0.5,
|
|
7457
7462
|
maxzoom: 18,
|
|
7458
7463
|
};
|
|
@@ -7591,6 +7596,101 @@ async function fetchGzJson(url, headers = {}) {
|
|
|
7591
7596
|
return new Response(stream).json();
|
|
7592
7597
|
}
|
|
7593
7598
|
|
|
7599
|
+
const MAGIC = "KYT1";
|
|
7600
|
+
const IV_LEN = 12;
|
|
7601
|
+
const HEADER_LEN = 6;
|
|
7602
|
+
const FLAG_GZIP = 0x01;
|
|
7603
|
+
function b64ToBytes(b64) {
|
|
7604
|
+
const bin = atob(b64);
|
|
7605
|
+
const out = new Uint8Array(bin.length);
|
|
7606
|
+
for (let i = 0; i < bin.length; i++)
|
|
7607
|
+
out[i] = bin.charCodeAt(i);
|
|
7608
|
+
return out;
|
|
7609
|
+
}
|
|
7610
|
+
async function gunzip(buf) {
|
|
7611
|
+
const ds = new globalThis.DecompressionStream("gzip");
|
|
7612
|
+
const stream = new Blob([buf]).stream().pipeThrough(ds);
|
|
7613
|
+
return await new Response(stream).arrayBuffer();
|
|
7614
|
+
}
|
|
7615
|
+
class TileCipher {
|
|
7616
|
+
constructor(apiUrl, version, licenseKey) {
|
|
7617
|
+
this.periodKeys = new Map();
|
|
7618
|
+
const dot = licenseKey.indexOf(".");
|
|
7619
|
+
if (dot <= 0) {
|
|
7620
|
+
throw new Error("[MapSDK] 无效的 licenseKey,应为 \"customerId.base64Key\"");
|
|
7621
|
+
}
|
|
7622
|
+
this.cid = licenseKey.slice(0, dot);
|
|
7623
|
+
const raw = b64ToBytes(licenseKey.slice(dot + 1));
|
|
7624
|
+
this.customerKeyRaw = raw;
|
|
7625
|
+
this.customerKey = crypto.subtle.importKey("raw", raw, { name: "AES-GCM" }, false, ["decrypt"]);
|
|
7626
|
+
this.wrapBase = apiPrefix(apiUrl, version);
|
|
7627
|
+
}
|
|
7628
|
+
async apiAuthHeaders() {
|
|
7629
|
+
const key = await this.authKey();
|
|
7630
|
+
const ts = Math.floor(Date.now() / 1000);
|
|
7631
|
+
const sigBuf = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(`${this.cid}|${ts}`));
|
|
7632
|
+
const sig = Array.from(new Uint8Array(sigBuf))
|
|
7633
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
7634
|
+
.join("");
|
|
7635
|
+
return { "X-Cid": this.cid, "X-Ts": String(ts), "X-Sig": sig };
|
|
7636
|
+
}
|
|
7637
|
+
authKey() {
|
|
7638
|
+
if (!this.authKeyPromise) {
|
|
7639
|
+
this.authKeyPromise = (async () => {
|
|
7640
|
+
const ck = await crypto.subtle.importKey("raw", this.customerKeyRaw, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
7641
|
+
const derived = await crypto.subtle.sign("HMAC", ck, new TextEncoder().encode("kunyu-api-auth-v1"));
|
|
7642
|
+
return crypto.subtle.importKey("raw", derived, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
7643
|
+
})();
|
|
7644
|
+
}
|
|
7645
|
+
return this.authKeyPromise;
|
|
7646
|
+
}
|
|
7647
|
+
periodKey(period) {
|
|
7648
|
+
let p = this.periodKeys.get(period);
|
|
7649
|
+
if (!p) {
|
|
7650
|
+
p = this.fetchPeriodKey(period).catch((e) => {
|
|
7651
|
+
this.periodKeys.delete(period);
|
|
7652
|
+
throw e;
|
|
7653
|
+
});
|
|
7654
|
+
this.periodKeys.set(period, p);
|
|
7655
|
+
}
|
|
7656
|
+
return p;
|
|
7657
|
+
}
|
|
7658
|
+
async fetchPeriodKey(period) {
|
|
7659
|
+
const url = `${this.wrapBase}/tilewrap?cid=${encodeURIComponent(this.cid)}&period=${encodeURIComponent(period)}`;
|
|
7660
|
+
const resp = await fetch(url);
|
|
7661
|
+
if (!resp.ok) {
|
|
7662
|
+
throw new Error(`[MapSDK] 取瓦片密钥失败 (HTTP ${resp.status})`);
|
|
7663
|
+
}
|
|
7664
|
+
const { wrapped } = (await resp.json());
|
|
7665
|
+
const blob = b64ToBytes(wrapped);
|
|
7666
|
+
const iv = blob.slice(0, IV_LEN);
|
|
7667
|
+
const ct = blob.slice(IV_LEN);
|
|
7668
|
+
const ck = await this.customerKey;
|
|
7669
|
+
const rawPeriodKey = await crypto.subtle.decrypt({ name: "AES-GCM", iv: iv }, ck, ct);
|
|
7670
|
+
return crypto.subtle.importKey("raw", rawPeriodKey, { name: "AES-GCM" }, false, ["decrypt"]);
|
|
7671
|
+
}
|
|
7672
|
+
async decrypt(realUrl, envelope) {
|
|
7673
|
+
const m = realUrl.match(/\/tiles\/e\/([^/]+)\//);
|
|
7674
|
+
const period = m?.[1];
|
|
7675
|
+
if (!period)
|
|
7676
|
+
throw new Error("[MapSDK] 无法从 URL 解析期号: " + realUrl);
|
|
7677
|
+
const bytes = new Uint8Array(envelope);
|
|
7678
|
+
const magic = new TextDecoder().decode(bytes.subarray(0, 4));
|
|
7679
|
+
if (bytes.length < HEADER_LEN + IV_LEN || magic !== MAGIC) {
|
|
7680
|
+
throw new Error("[MapSDK] 瓦片信封无效 (magic)");
|
|
7681
|
+
}
|
|
7682
|
+
const flags = bytes[5] ?? 0;
|
|
7683
|
+
const aad = bytes.slice(0, HEADER_LEN);
|
|
7684
|
+
const iv = bytes.slice(HEADER_LEN, HEADER_LEN + IV_LEN);
|
|
7685
|
+
const ct = bytes.slice(HEADER_LEN + IV_LEN);
|
|
7686
|
+
const key = await this.periodKey(period);
|
|
7687
|
+
let plain = await crypto.subtle.decrypt({ name: "AES-GCM", iv: iv, additionalData: aad }, key, ct);
|
|
7688
|
+
if (flags & FLAG_GZIP)
|
|
7689
|
+
plain = await gunzip(plain);
|
|
7690
|
+
return plain;
|
|
7691
|
+
}
|
|
7692
|
+
}
|
|
7693
|
+
|
|
7594
7694
|
// ICAO aviation chart layer styles — token-driven multi-theme.
|
|
7595
7695
|
//
|
|
7596
7696
|
// 单一 buildLayers(T):图层结构只写一份(以 light 为准);凡随主题变化的值
|
|
@@ -7878,7 +7978,7 @@ function buildLayers(themeId = 'light') {
|
|
|
7878
7978
|
["case", ["all", ["has", "TXT_DESIG_HIGH"], ["!=", ["get", "TXT_DESIG_HIGH"], ""]], ["get", "TXT_DESIG_HIGH"], ["all", ["has", "TXT_DESIG_FORWARD"], ["!=", ["get", "TXT_DESIG_FORWARD"], ""]], ["get", "TXT_DESIG_FORWARD"], ["all", ["has", "TXT_DESIG_BACKWARD"], ["!=", ["get", "TXT_DESIG_BACKWARD"], ""]], ["get", "TXT_DESIG_BACKWARD"], "-"], { "font-scale": 0.95, "text-color": T.alDist }
|
|
7879
7979
|
]
|
|
7880
7980
|
],
|
|
7881
|
-
"text-size": ["interpolate", ["linear"], ["zoom"], 6, 9, 10, 10],
|
|
7981
|
+
"text-size": ["interpolate", ["linear"], ["zoom"], 6.5, 9, 10, 10],
|
|
7882
7982
|
"icon-text-fit-padding": [0, 3, 0, 3],
|
|
7883
7983
|
},
|
|
7884
7984
|
paint: {
|
|
@@ -7903,15 +8003,23 @@ function buildLayers(themeId = 'light') {
|
|
|
7903
8003
|
paint: { 'text-color': T.segment, ...T.radialHalo },
|
|
7904
8004
|
},
|
|
7905
8005
|
{
|
|
7906
|
-
id: 'airport', type: 'symbol', source: sourceId, minzoom:
|
|
7907
|
-
|
|
8006
|
+
id: 'airport', type: 'symbol', source: sourceId, minzoom: 2, 'source-layer': 'airport',
|
|
8007
|
+
// 4级前就显示大型机场+中型,5级后全部显示
|
|
8008
|
+
filter:
|
|
8009
|
+
['case',
|
|
8010
|
+
['<=', ['zoom'], 3], ['<=', ['get', 'level'], 2], // ≤4 只显 大型+中型
|
|
8011
|
+
true // >4 全部
|
|
8012
|
+
],
|
|
7908
8013
|
layout: {
|
|
7909
|
-
"icon-image": ["case", ["==", ["get", "CODE_TYPE_MIL_OPS"], "MIL"], "airport-mil", ["==", ["get", "CODE_TYPE_MIL_OPS"], "MILEXT"], "airport-milext", "airport-civ"],
|
|
8014
|
+
"icon-image": ["case", ["==", ["get", "CODE_TYPE_MIL_OPS"], "MIL"], "airport-mil", ["==", ["get", "CODE_TYPE_MIL_OPS"], "MILEXT"], "airport-milext", "airport-civ"],
|
|
8015
|
+
"icon-size": ["interpolate", ["linear"], ["zoom"], 4, 0.5, 10, 0.7],
|
|
8016
|
+
"symbol-z-order": "viewport-y",
|
|
8017
|
+
"text-field": ["get", "codeId"],
|
|
7910
8018
|
"text-letter-spacing": 0.05,
|
|
7911
8019
|
'text-field': ['get', 'CODE_ID'],
|
|
7912
8020
|
"text-anchor": "bottom",
|
|
7913
8021
|
"text-justify": "center",
|
|
7914
|
-
"text-size": ["interpolate", ["linear"], ["zoom"], 4, 0, 5, 10, 9,
|
|
8022
|
+
"text-size": ["interpolate", ["linear"], ["zoom"], 4, 0, 5, 10, 9, 11],
|
|
7915
8023
|
"text-offset": [
|
|
7916
8024
|
"interpolate", ["linear"], ["zoom"],
|
|
7917
8025
|
5, ["literal", [0, -0.8]],
|
|
@@ -7923,7 +8031,7 @@ function buildLayers(themeId = 'light') {
|
|
|
7923
8031
|
"text-allow-overlap": true,
|
|
7924
8032
|
"text-ignore-placement": true,
|
|
7925
8033
|
"visibility": "none",
|
|
7926
|
-
"icon-size": ["interpolate", ["linear"], ["zoom"], 5, 0.
|
|
8034
|
+
"icon-size": ["interpolate", ["linear"], ["zoom"], 5, 0.7, 9, 1.2, 12, 1.3]
|
|
7927
8035
|
},
|
|
7928
8036
|
paint: {
|
|
7929
8037
|
'icon-color': ['case', ['has', 'has_amm'], '#4B2D6E', T.airport],
|
|
@@ -7939,37 +8047,37 @@ function buildLayers(themeId = 'light') {
|
|
|
7939
8047
|
// keeps the strip aligned to the ground as the map rotates. The `runway-strip`
|
|
7940
8048
|
// sprite is supplied by the host sprite sheet.
|
|
7941
8049
|
{
|
|
7942
|
-
id: 'airport-runway', type: 'symbol', source: sourceId, minzoom:
|
|
7943
|
-
filter: ['all', ['has', 'RWY_BRG1'], ['case', ['
|
|
8050
|
+
id: 'airport-runway', type: 'symbol', source: sourceId, minzoom: 2, 'source-layer': 'airport',
|
|
8051
|
+
filter: ['all', ['has', 'RWY_BRG1'], ['case', ['<=', ['zoom'], 3], ['<=', ['get', 'level'], 2], true]],
|
|
7944
8052
|
layout: {
|
|
7945
8053
|
'icon-image': 'runway:runway-strip',
|
|
7946
8054
|
'icon-rotate': ['get', 'RWY_BRG1'],
|
|
7947
8055
|
'icon-rotation-alignment': 'map',
|
|
7948
|
-
'icon-size': ['interpolate', ['linear'], ['zoom'], 5, 0.
|
|
8056
|
+
'icon-size': ['interpolate', ['linear'], ['zoom'], 5, 0.5, 9, 0.7, 12, 0.75],
|
|
7949
8057
|
'icon-allow-overlap': true,
|
|
7950
8058
|
'icon-ignore-placement': true,
|
|
7951
8059
|
'visibility': 'none',
|
|
7952
8060
|
},
|
|
7953
8061
|
paint: {
|
|
7954
8062
|
"icon-color": T.airport,
|
|
7955
|
-
"icon-opacity": ["interpolate", ["linear"], ["zoom"], 2, 0.
|
|
8063
|
+
"icon-opacity": ["interpolate", ["linear"], ["zoom"], 2, 0.65, 3, 0.85, 5, 0.9, 9, 1, 11, 0.2],
|
|
7956
8064
|
},
|
|
7957
8065
|
},
|
|
7958
8066
|
{
|
|
7959
|
-
id: 'airport-runway-cross', type: 'symbol', source: sourceId, minzoom:
|
|
7960
|
-
filter: ['all', ['has', 'RWY_BRG2'], ['case', ['
|
|
8067
|
+
id: 'airport-runway-cross', type: 'symbol', source: sourceId, minzoom: 2, 'source-layer': 'airport',
|
|
8068
|
+
filter: ['all', ['has', 'RWY_BRG2'], ['case', ['<=', ['zoom'], 3], ['<=', ['get', 'level'], 2], true]],
|
|
7961
8069
|
layout: {
|
|
7962
8070
|
'icon-image': 'runway:runway-strip',
|
|
7963
8071
|
'icon-rotate': ['get', 'RWY_BRG2'],
|
|
7964
8072
|
'icon-rotation-alignment': 'map',
|
|
7965
|
-
'icon-size': ['interpolate', ['linear'], ['zoom'], 5, 0.
|
|
8073
|
+
'icon-size': ['interpolate', ['linear'], ['zoom'], 5, 0.5, 9, 0.7, 12, 0.75],
|
|
7966
8074
|
'icon-allow-overlap': true,
|
|
7967
8075
|
'icon-ignore-placement': true,
|
|
7968
8076
|
'visibility': 'none',
|
|
7969
8077
|
},
|
|
7970
8078
|
paint: {
|
|
7971
8079
|
"icon-color": T.airport,
|
|
7972
|
-
"icon-opacity": ["interpolate", ["linear"], ["zoom"], 2, 0.
|
|
8080
|
+
"icon-opacity": ["interpolate", ["linear"], ["zoom"], 2, 0.65, 3, 0.85, 5, 0.9, 9, 1, 11, 0.2],
|
|
7973
8081
|
},
|
|
7974
8082
|
},
|
|
7975
8083
|
{
|
|
@@ -8051,11 +8159,11 @@ function buildLayers(themeId = 'light') {
|
|
|
8051
8159
|
'text-color': T.waypoint,
|
|
8052
8160
|
"icon-halo-color": "rgba(0,0,0,0)",
|
|
8053
8161
|
"icon-halo-width": 0,
|
|
8054
|
-
"icon-opacity": ["interpolate", ["linear"], ["zoom"], 6, 0.5, 12, 1, 15, 0.2],
|
|
8162
|
+
"icon-opacity": ["interpolate", ["linear"], ["zoom"], 6.5, 0.5, 12, 1, 15, 0.2],
|
|
8055
8163
|
"text-halo-color": T.halo,
|
|
8056
8164
|
"text-halo-width": 1,
|
|
8057
8165
|
"text-halo-blur": 0,
|
|
8058
|
-
"text-opacity": ["interpolate", ["linear"], ["zoom"], 6, 1, 12, 0.9, 15, 0.15],
|
|
8166
|
+
"text-opacity": ["interpolate", ["linear"], ["zoom"], 6.49, 0, 6.5, 1, 12, 0.9, 15, 0.15],
|
|
8059
8167
|
},
|
|
8060
8168
|
},
|
|
8061
8169
|
{
|
|
@@ -8185,6 +8293,26 @@ class MapSDK {
|
|
|
8185
8293
|
this._baseUrl = options.staticUrl || "https://aips.siniswift.com";
|
|
8186
8294
|
this._chartApiUrl = (options.apiUrl || DEFAULT_CHART_API_URL).replace(/\/$/, "");
|
|
8187
8295
|
this._apiVersion = options.apiVersion || undefined;
|
|
8296
|
+
if (options.licenseKey) {
|
|
8297
|
+
try {
|
|
8298
|
+
this._tileCipher = new TileCipher(this._chartApiUrl, this._apiVersion, options.licenseKey);
|
|
8299
|
+
const cipher = this._tileCipher;
|
|
8300
|
+
_mlGlExports.addProtocol("kunyu", async (params) => {
|
|
8301
|
+
const realUrl = String(params.url).replace(/^kunyu:\/\//, "");
|
|
8302
|
+
const resp = await fetch(realUrl, { signal: params.signal });
|
|
8303
|
+
if (!resp.ok)
|
|
8304
|
+
throw new Error(`tile ${resp.status}`);
|
|
8305
|
+
const buf = await resp.arrayBuffer();
|
|
8306
|
+
if (buf.byteLength === 0)
|
|
8307
|
+
return { data: null };
|
|
8308
|
+
const data = await cipher.decrypt(realUrl, buf);
|
|
8309
|
+
return { data };
|
|
8310
|
+
});
|
|
8311
|
+
}
|
|
8312
|
+
catch (e) {
|
|
8313
|
+
this._tileCipher = undefined;
|
|
8314
|
+
}
|
|
8315
|
+
}
|
|
8188
8316
|
const themeId = this._resolveThemeId(options.theme);
|
|
8189
8317
|
const themeConfig = CHART_THEMES[themeId] ?? CHART_THEMES.light;
|
|
8190
8318
|
const style = options.style ??
|
|
@@ -8339,7 +8467,7 @@ class MapSDK {
|
|
|
8339
8467
|
return;
|
|
8340
8468
|
}
|
|
8341
8469
|
if (!this.map.getSource("navdata")) {
|
|
8342
|
-
this.map.addSource("navdata", getNavdataSource(this._chartApiUrl, period, this._apiVersion));
|
|
8470
|
+
this.map.addSource("navdata", getNavdataSource(this._chartApiUrl, period, this._apiVersion, !!this._tileCipher));
|
|
8343
8471
|
}
|
|
8344
8472
|
const themeId = this._resolveThemeId(this.initialOptions.theme);
|
|
8345
8473
|
for (const layer of buildLayers(themeId)) {
|
|
@@ -8682,7 +8810,7 @@ class MapSDK {
|
|
|
8682
8810
|
this.globalConfig.setPeriod(period);
|
|
8683
8811
|
const navdata = this.map?.getSource("navdata");
|
|
8684
8812
|
if (navdata?.setTiles) {
|
|
8685
|
-
navdata.setTiles([navdataTilesUrl(this._chartApiUrl, period, this._apiVersion)]);
|
|
8813
|
+
navdata.setTiles([navdataTilesUrl(this._chartApiUrl, period, this._apiVersion, !!this._tileCipher)]);
|
|
8686
8814
|
}
|
|
8687
8815
|
if (from !== undefined && from !== period) {
|
|
8688
8816
|
this.map?.fire("periodchange", { from, to: period });
|
|
@@ -8694,18 +8822,23 @@ class MapSDK {
|
|
|
8694
8822
|
async generateCurrentPeriod() {
|
|
8695
8823
|
return await this.globalConfig.generateCurrentPeriod();
|
|
8696
8824
|
}
|
|
8697
|
-
search(params) {
|
|
8698
|
-
const
|
|
8825
|
+
async search(params) {
|
|
8826
|
+
const auth = await this._apiAuth();
|
|
8699
8827
|
const period = params.period ?? this.getPeriod();
|
|
8700
|
-
return searchFeatures(this._chartApiUrl,
|
|
8828
|
+
return searchFeatures(this._chartApiUrl, auth, {
|
|
8701
8829
|
...params,
|
|
8702
8830
|
...(period ? { period } : {}),
|
|
8703
8831
|
}, this._apiVersion);
|
|
8704
8832
|
}
|
|
8705
|
-
|
|
8706
|
-
|
|
8833
|
+
async _apiAuth() {
|
|
8834
|
+
if (this._tileCipher)
|
|
8835
|
+
return this._tileCipher.apiAuthHeaders();
|
|
8836
|
+
return this.globalConfig.getConfig().apiKey;
|
|
8837
|
+
}
|
|
8838
|
+
async getGeometry(params) {
|
|
8839
|
+
const auth = await this._apiAuth();
|
|
8707
8840
|
const period = params.period ?? this.getPeriod();
|
|
8708
|
-
return getFeatureGeometry(this._chartApiUrl,
|
|
8841
|
+
return getFeatureGeometry(this._chartApiUrl, auth, {
|
|
8709
8842
|
...params,
|
|
8710
8843
|
...(period ? { period } : {}),
|
|
8711
8844
|
}, this._apiVersion);
|