aviation-chart 0.3.3 → 0.3.5

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 CHANGED
@@ -8,6 +8,7 @@ import { Geoman } from '@geoman-io/maplibre-geoman-free';
8
8
  interface GlobalConfig {
9
9
  apiKey?: string;
10
10
  baseUrl?: string;
11
+ apiUrl?: string;
11
12
  version?: string;
12
13
  period?: string;
13
14
  chartConfig?: {
@@ -437,7 +438,9 @@ interface IMapSDK {
437
438
  destroy(): void;
438
439
  use(plugin: IPlugin): void;
439
440
  getPlugin<T extends IPlugin>(name: string): T | undefined;
440
- setPeriod(period: string): void;
441
+ setPeriod(period: string, options?: {
442
+ validate?: boolean;
443
+ }): void;
441
444
  getPeriod(): string | undefined;
442
445
  generateCurrentPeriod(): Promise<string>;
443
446
  showGraticule(): void;
@@ -799,6 +802,39 @@ declare class RasterManager {
799
802
  removeRasterLayer(layerId: string, sourceId: string): void;
800
803
  }
801
804
 
805
+ type FeatureType = "airport" | "waypoint" | "vor" | "ndb" | "airspace" | "restricted" | "controlled" | "airway";
806
+ interface SearchParams {
807
+ q: string;
808
+ type?: FeatureType;
809
+ period?: string;
810
+ limit?: number;
811
+ signal?: AbortSignal;
812
+ }
813
+ interface SearchResultItem {
814
+ type: FeatureType;
815
+ id: string;
816
+ code: string;
817
+ name?: string;
818
+ name_chn?: string;
819
+ }
820
+ interface GeometryParams {
821
+ type: FeatureType;
822
+ id: string;
823
+ period?: string;
824
+ signal?: AbortSignal;
825
+ }
826
+ interface GeometryFeature {
827
+ type: "Feature";
828
+ geometry: {
829
+ type: "Point" | "LineString" | "Polygon" | "MultiPolygon" | "MultiLineString" | "MultiPoint";
830
+ coordinates: any;
831
+ };
832
+ properties: Record<string, any>;
833
+ }
834
+ declare function searchFeatures(baseUrl: string, apiKey: string | undefined, params: SearchParams): Promise<SearchResultItem[]>;
835
+ declare function getFeatureGeometry(baseUrl: string, apiKey: string | undefined, params: GeometryParams): Promise<GeometryFeature>;
836
+ declare function getPeriods(baseUrl: string, apiKey?: string, signal?: AbortSignal): Promise<string[]>;
837
+
802
838
  interface SelectFeatureOptions {
803
839
  isHighlight: boolean;
804
840
  highlightColor: string;
@@ -1002,9 +1038,15 @@ declare class MapSDK implements IMapSDK {
1002
1038
  lazyLoadingEnabled: boolean;
1003
1039
  };
1004
1040
  getErrorStats(): void;
1005
- setPeriod(period: string): void;
1041
+ setPeriod(period: string, options?: {
1042
+ validate?: boolean;
1043
+ }): void;
1044
+ private _applyPeriod;
1006
1045
  getPeriod(): string | undefined;
1007
1046
  generateCurrentPeriod(): Promise<string>;
1047
+ search(params: SearchParams): Promise<SearchResultItem[]>;
1048
+ getGeometry(params: GeometryParams): Promise<GeometryFeature>;
1049
+ getPeriods(signal?: AbortSignal): Promise<string[]>;
1008
1050
  showGraticule(): void;
1009
1051
  hideGraticule(): void;
1010
1052
  toggleGraticule(): void;
@@ -3544,4 +3586,4 @@ declare function buildLayersDark(): ({
3544
3586
  maxzoom?: never;
3545
3587
  })[];
3546
3588
 
3547
- export { API, MapSDK as AviationChart, BuiltInLayer, CHART_THEMES, Circle, CircleOptions, ClusteringConfig, DEFAULT_LAYER_VISIBILITY, DrawPlugin, EnhancedMarker, EnhancedPolygon, ErrorHandler, ErrorManager, EventListener, GROUP_ALIASES, GeoJSONCollection, GeoJSONFeature, GeoJSONManager, GlobalConfigManager, HookCallback, HookContext, HookRegistry, IGeoJSONManager, ILayerManager, IMapSDK, IPlugin, LAYER_GROUPS, LAYER_LABELS, LODConfig, LayerConfig, LayerManager, LineType, MapEvent, MapSDK, MapSDKOptions, MarkerOptions, MeasurePlugin, NOTAM, PerformanceManager, PluginManager, PolygonOptions, Polyline, PolylineOptions, SDKError, StrokeLineType, StyleConfig, TYPEMAP, Text, TextOptions, WindFrame, WindManager, WindOptions, MapSDK as default, globalConfig };
3589
+ export { API, MapSDK as AviationChart, BuiltInLayer, CHART_THEMES, Circle, CircleOptions, ClusteringConfig, DEFAULT_LAYER_VISIBILITY, DrawPlugin, EnhancedMarker, EnhancedPolygon, ErrorHandler, ErrorManager, EventListener, FeatureType, GROUP_ALIASES, GeoJSONCollection, GeoJSONFeature, GeoJSONManager, GeometryFeature, GeometryParams, GlobalConfigManager, HookCallback, HookContext, HookRegistry, IGeoJSONManager, ILayerManager, IMapSDK, IPlugin, LAYER_GROUPS, LAYER_LABELS, LODConfig, LayerConfig, LayerManager, LineType, MapEvent, MapSDK, MapSDKOptions, MarkerOptions, MeasurePlugin, NOTAM, PerformanceManager, PluginManager, PolygonOptions, Polyline, PolylineOptions, SDKError, SearchParams, SearchResultItem, StrokeLineType, StyleConfig, TYPEMAP, Text, TextOptions, WindFrame, WindManager, WindOptions, MapSDK as default, getFeatureGeometry, getPeriods, globalConfig, searchFeatures };
@@ -3259,12 +3259,6 @@ class ClickManager {
3259
3259
  }
3260
3260
  }
3261
3261
 
3262
- let _api = null;
3263
- function getApi() {
3264
- if (!_api)
3265
- _api = new API();
3266
- return _api;
3267
- }
3268
3262
  class GlobalConfigManager {
3269
3263
  constructor() {
3270
3264
  this.config = {};
@@ -3463,11 +3457,20 @@ class GlobalConfigManager {
3463
3457
  return this.config.period;
3464
3458
  }
3465
3459
  async generateCurrentPeriod() {
3466
- const response = await getApi().getPeriodData();
3467
- const { data } = await response.json();
3468
- const period = data.filter((item) => item.valIscurrent == "1")[0]
3469
- .txtPeriodName;
3470
- return period;
3460
+ const base = (this.config.apiUrl || "https://aips.siniswift.com").replace(/\/$/, "");
3461
+ const headers = this.config.apiKey
3462
+ ? { "X-Api-Key": this.config.apiKey }
3463
+ : {};
3464
+ const response = await fetch(`${base}/api/periods`, { headers });
3465
+ if (!response.ok) {
3466
+ throw new Error(`获取期数失败(${response.status})`);
3467
+ }
3468
+ const { periods } = (await response.json());
3469
+ const current = periods?.[0];
3470
+ if (!current) {
3471
+ throw new Error("后端未返回任何期数");
3472
+ }
3473
+ return current;
3471
3474
  }
3472
3475
  setMapReinitCallback(callback) {
3473
3476
  this.mapReinitCallback = callback;
@@ -4278,6 +4281,69 @@ class GraticuleManager {
4278
4281
  }
4279
4282
  }
4280
4283
 
4284
+ function authHeaders(apiKey) {
4285
+ return apiKey ? { "X-Api-Key": apiKey } : {};
4286
+ }
4287
+ async function toJSON(res) {
4288
+ if (!res.ok) {
4289
+ let detail = "";
4290
+ try {
4291
+ detail = await res.text();
4292
+ }
4293
+ catch {
4294
+ }
4295
+ const msg = res.status === 403
4296
+ ? "搜索接口鉴权失败(403):请检查初始化传入的 apiKey 是否正确"
4297
+ : `请求失败(${res.status})${detail ? ": " + detail.trim() : ""}`;
4298
+ throw new Error(msg);
4299
+ }
4300
+ return res.json();
4301
+ }
4302
+ async function searchFeatures(baseUrl, apiKey, params) {
4303
+ const { q, type, period, limit, signal } = params;
4304
+ if (!q || !q.trim()) {
4305
+ throw new Error("search: q 参数必填");
4306
+ }
4307
+ const qs = new URLSearchParams({ q: q.trim() });
4308
+ if (type)
4309
+ qs.set("type", type);
4310
+ if (period)
4311
+ qs.set("period", period);
4312
+ if (limit != null)
4313
+ qs.set("limit", String(limit));
4314
+ const res = await fetch(`${baseUrl}/api/search?${qs.toString()}`, {
4315
+ method: "GET",
4316
+ headers: authHeaders(apiKey),
4317
+ ...(signal ? { signal } : {}),
4318
+ });
4319
+ const data = await toJSON(res);
4320
+ return data.results ?? [];
4321
+ }
4322
+ async function getFeatureGeometry(baseUrl, apiKey, params) {
4323
+ const { type, id, period, signal } = params;
4324
+ if (!type || !id) {
4325
+ throw new Error("getGeometry: type 和 id 参数必填");
4326
+ }
4327
+ const qs = new URLSearchParams({ type, id });
4328
+ if (period)
4329
+ qs.set("period", period);
4330
+ const res = await fetch(`${baseUrl}/api/geometry?${qs.toString()}`, {
4331
+ method: "GET",
4332
+ headers: authHeaders(apiKey),
4333
+ ...(signal ? { signal } : {}),
4334
+ });
4335
+ return toJSON(res);
4336
+ }
4337
+ async function getPeriods(baseUrl, apiKey, signal) {
4338
+ const res = await fetch(`${baseUrl}/api/periods`, {
4339
+ method: "GET",
4340
+ headers: authHeaders(apiKey),
4341
+ ...(signal ? { signal } : {}),
4342
+ });
4343
+ const data = await toJSON(res);
4344
+ return data.periods ?? [];
4345
+ }
4346
+
4281
4347
  function identity(x) {
4282
4348
  return x;
4283
4349
  }
@@ -6541,12 +6607,32 @@ class MapSDK {
6541
6607
  }
6542
6608
  getErrorStats() {
6543
6609
  }
6544
- setPeriod(period) {
6610
+ setPeriod(period, options) {
6611
+ if (options?.validate) {
6612
+ this.getPeriods()
6613
+ .then((all) => {
6614
+ if (!all.includes(period)) {
6615
+ const err = new Error(`期数 ${period} 不存在,可用期数:${all.join(", ")}`);
6616
+ this.map?.fire("error", { error: err });
6617
+ return;
6618
+ }
6619
+ this._applyPeriod(period);
6620
+ })
6621
+ .catch((e) => (void 0));
6622
+ return;
6623
+ }
6624
+ this._applyPeriod(period);
6625
+ }
6626
+ _applyPeriod(period) {
6627
+ const from = this.getPeriod();
6545
6628
  this.globalConfig.setPeriod(period);
6546
6629
  const navdata = this.map?.getSource("navdata");
6547
6630
  if (navdata?.setTiles) {
6548
6631
  navdata.setTiles([navdataTilesUrl(this._chartApiUrl, period)]);
6549
6632
  }
6633
+ if (from !== undefined && from !== period) {
6634
+ this.map?.fire("periodchange", { from, to: period });
6635
+ }
6550
6636
  }
6551
6637
  getPeriod() {
6552
6638
  return this.globalConfig.getPeriod();
@@ -6554,6 +6640,26 @@ class MapSDK {
6554
6640
  async generateCurrentPeriod() {
6555
6641
  return await this.globalConfig.generateCurrentPeriod();
6556
6642
  }
6643
+ search(params) {
6644
+ const apiKey = this.globalConfig.getConfig().apiKey;
6645
+ const period = params.period ?? this.getPeriod();
6646
+ return searchFeatures(this._chartApiUrl, apiKey, {
6647
+ ...params,
6648
+ ...(period ? { period } : {}),
6649
+ });
6650
+ }
6651
+ getGeometry(params) {
6652
+ const apiKey = this.globalConfig.getConfig().apiKey;
6653
+ const period = params.period ?? this.getPeriod();
6654
+ return getFeatureGeometry(this._chartApiUrl, apiKey, {
6655
+ ...params,
6656
+ ...(period ? { period } : {}),
6657
+ });
6658
+ }
6659
+ getPeriods(signal) {
6660
+ const apiKey = this.globalConfig.getConfig().apiKey;
6661
+ return getPeriods(this._chartApiUrl, apiKey, signal);
6662
+ }
6557
6663
  showGraticule() {
6558
6664
  this.graticule?.show();
6559
6665
  }
@@ -6635,6 +6741,7 @@ class MapSDK {
6635
6741
  config.apiKey = options.apiKey;
6636
6742
  if (options.baseUrl)
6637
6743
  config.baseUrl = options.baseUrl;
6744
+ config.apiUrl = this._chartApiUrl;
6638
6745
  if (options.period)
6639
6746
  config.period = options.period;
6640
6747
  globalConfig.setConfig(config);
@@ -28287,4 +28394,4 @@ var LngLat = _mlGlExports.LngLat;
28287
28394
  var LngLatBounds = _mlGlExports.LngLatBounds;
28288
28395
  var Marker = _mlGlExports.Marker;
28289
28396
  var Popup = _mlGlExports.Popup;
28290
- export { API, MapSDK as AviationChart, CHART_THEMES, Circle, DEFAULT_LAYER_VISIBILITY, DrawPlugin, EnhancedMarker, EnhancedPolygon, ErrorManager, GROUP_ALIASES, GeoJSONManager, LAYER_GROUPS, LAYER_LABELS, LayerManager, LngLat, LngLatBounds, _mlGl as MapEngine, MapSDK, Marker, MeasurePlugin, NOTAM, PerformanceManager, PluginManager, Polyline, Popup, TYPEMAP, Text$1 as Text, WindManager, MapSDK as default, globalConfig };
28397
+ export { API, MapSDK as AviationChart, CHART_THEMES, Circle, DEFAULT_LAYER_VISIBILITY, DrawPlugin, EnhancedMarker, EnhancedPolygon, ErrorManager, GROUP_ALIASES, GeoJSONManager, LAYER_GROUPS, LAYER_LABELS, LayerManager, LngLat, LngLatBounds, _mlGl as MapEngine, MapSDK, Marker, MeasurePlugin, NOTAM, PerformanceManager, PluginManager, Polyline, Popup, TYPEMAP, Text$1 as Text, WindManager, MapSDK as default, getFeatureGeometry, getPeriods, globalConfig, searchFeatures };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aviation-chart",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "KunYu aviation map SDK",
5
5
  "main": "dist/nav-sdk.esm.js",
6
6
  "module": "dist/nav-sdk.esm.js",