cmap-core 0.0.3 → 0.0.4

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.
@@ -16,7 +16,6 @@ import { SourceSpecification } from 'mapbox-gl';
16
16
  export declare class AisShip extends BaseShip<IAisShipOptions> {
17
17
  readonly SOURCE: string;
18
18
  readonly NAME: string;
19
- tooltip: Tooltip | null;
20
19
  constructor(map: Map_2, options: IAisShipOptions);
21
20
  onAdd(): void;
22
21
  onRemove(): void;
@@ -60,6 +59,7 @@ export declare abstract class BaseShip<T extends IBaseShipOptions> extends Modul
60
59
  options: T;
61
60
  readonly SOURCE: string;
62
61
  readonly NAME: string;
62
+ tooltip: Tooltip | null;
63
63
  visible: boolean;
64
64
  protected constructor(map: Map_2, options: T);
65
65
  destroy(): void;
@@ -92,6 +92,11 @@ export declare abstract class BaseShip<T extends IBaseShipOptions> extends Modul
92
92
  getName(): string;
93
93
  }
94
94
 
95
+ declare interface BaseShipConstructor<T extends IBaseShipOptions = any> {
96
+ new (map: Map_2, options: T): BaseShip<T>;
97
+ readonly NAME: string;
98
+ }
99
+
95
100
  declare class Cache_2 {
96
101
  _options: CacheOptions;
97
102
  cacheKey: string;
@@ -353,6 +358,10 @@ declare interface Image_2 {
353
358
  image: ImageBitmap | HTMLImageElement | ImageData;
354
359
  }
355
360
 
361
+ declare interface IShipOptions {
362
+ plugins?: BaseShipConstructor[];
363
+ }
364
+
356
365
  declare interface ITooltipOptions {
357
366
  id: string | number;
358
367
  visible?: boolean;
@@ -467,21 +476,24 @@ declare interface Shape {
467
476
  }
468
477
 
469
478
  export declare class Ship extends Module {
470
- ships: AisShip[];
479
+ options: IShipOptions;
480
+ ships: BaseShip<any>[];
471
481
  event: ResidentEvent;
482
+ private pluginRegistry;
472
483
  private collision;
473
- constructor(map: Map_2);
484
+ constructor(map: Map_2, options: IShipOptions);
474
485
  onAdd(): void;
475
486
  onRemove(): void;
476
487
  get tooltips(): Tooltip[];
488
+ private registerPlugins;
477
489
  private createCollisions;
478
490
  private collisionTooltip;
479
- add(data: IAisShipOptions): AisShip;
480
- load(list: IAisShipOptions[]): AisShip[];
491
+ add(data: IAisShipOptions): BaseShip<any> | undefined;
492
+ load(list: IAisShipOptions[]): BaseShip<any>[];
481
493
  remove(id: IAisShipOptions['id']): void;
482
494
  removeAll(): void;
483
495
  render(): void;
484
- get(id: IAisShipOptions['id']): AisShip | undefined;
496
+ get(id: string | number): BaseShip<any> | undefined;
485
497
  select(id: IAisShipOptions['id']): void;
486
498
  unselect(id: IAisShipOptions['id']): void;
487
499
  }
package/dist/index.es.js CHANGED
@@ -13936,7 +13936,7 @@ ${JSON.stringify(a, null, 2)}
13936
13936
  if (Ai) {
13937
13937
  const jr = oi.layout.get("icon-rotate").evaluate(Yi, {}, Vr), Un = Mg(Ai, jr, ns, br, tr.iconScaleFactor), Ns = cr ? Mg(cr, jr, ns, br, tr.iconScaleFactor) : void 0;
13938
13938
  ll = bm(Ti, jo, Pt, Bi, Wi, Xi, Ai, Er, jr, null, Fu);
13939
- const Go = (function(lo, nS, E1, sS, A1, M1, oS, GE, iy) {
13939
+ const Go = (function(lo, nS, E1, sS, A1, M1, oS, jE, iy) {
13940
13940
  const P1 = lo.layers[0], C1 = P1.appearances;
13941
13941
  let Nu = nS.length;
13942
13942
  if (E1 && (Nu = Math.max(Nu, E1.length)), C1.length === 0) return Nu;
@@ -37673,7 +37673,7 @@ const OE = {
37673
37673
  }
37674
37674
  ]
37675
37675
  };
37676
- class $E extends my {
37676
+ class GE extends my {
37677
37677
  map;
37678
37678
  options;
37679
37679
  cache = /* @__PURE__ */ new Set();
@@ -37818,12 +37818,131 @@ class FE extends ju {
37818
37818
  return this.ships.find((q) => String(q.id) === String(L));
37819
37819
  }
37820
37820
  }
37821
- var qm = { exports: {} }, kE = qm.exports, J1;
37822
- function BE() {
37821
+ class $E extends Ym {
37822
+ options;
37823
+ ships = [];
37824
+ event;
37825
+ pluginRegistry = /* @__PURE__ */ new Map();
37826
+ collision;
37827
+ constructor(L, q) {
37828
+ super(L), this.options = q, this.collision = new wS(this.context.map), this.event = new FE(L), this.registerPlugins(q.plugins);
37829
+ }
37830
+ onAdd() {
37831
+ }
37832
+ onRemove() {
37833
+ }
37834
+ get tooltips() {
37835
+ return this.ships.flatMap((L) => L.tooltip ?? []);
37836
+ }
37837
+ registerPlugins(L = []) {
37838
+ L.forEach((q) => {
37839
+ q.NAME ? this.pluginRegistry.set(q.NAME, q) : console.warn("Ship Plugin missing static NAME property:", q);
37840
+ });
37841
+ }
37842
+ createCollisions() {
37843
+ return this.tooltips.map((L) => ({
37844
+ ...L.getAllBbox(),
37845
+ id: L.id
37846
+ }));
37847
+ }
37848
+ collisionTooltip() {
37849
+ this.collision.load(this.createCollisions()).forEach((L) => {
37850
+ const q = this.tooltips.find((ae) => ae.id === L.id);
37851
+ q && (L.visible ? q.setAnchor(L.dir) : q.hide());
37852
+ });
37853
+ }
37854
+ add(L) {
37855
+ const q = this.pluginRegistry.get(L.type);
37856
+ if (!q) {
37857
+ console.warn(`No plugin registered for ship type: "${L.type}"`);
37858
+ return;
37859
+ }
37860
+ const ae = new q(this.context.map, L);
37861
+ return this.ships.push(ae), this.event.add(ae), ae;
37862
+ }
37863
+ load(L) {
37864
+ this.removeAll();
37865
+ const q = [];
37866
+ return L.forEach((ae) => {
37867
+ const Me = this.add(ae);
37868
+ Me && q.push(Me);
37869
+ }), this.render(), this.collisionTooltip(), q;
37870
+ }
37871
+ remove(L) {
37872
+ this.event.remove(L);
37873
+ const q = this.ships.findIndex((ae) => ae.id === L);
37874
+ q !== -1 && (this.ships[q].remove(), this.ships.splice(q, 1));
37875
+ }
37876
+ removeAll() {
37877
+ this.collision.clear(), this.ships.forEach((L) => {
37878
+ L.remove();
37879
+ }), this.ships = [];
37880
+ }
37881
+ render() {
37882
+ this.ships.forEach((L) => {
37883
+ L.render();
37884
+ });
37885
+ }
37886
+ get(L) {
37887
+ return this.ships.find((q) => q.id === L);
37888
+ }
37889
+ select(L) {
37890
+ const q = this.get(L);
37891
+ q && q.select();
37892
+ }
37893
+ unselect(L) {
37894
+ const q = this.get(L);
37895
+ q && q.unselect();
37896
+ }
37897
+ }
37898
+ class kE extends Ym {
37899
+ options;
37900
+ SOURCE = "mapbox-gl-ship-source";
37901
+ NAME = "Base";
37902
+ tooltip = null;
37903
+ visible = !0;
37904
+ constructor(L, q) {
37905
+ super(L), this.options = q;
37906
+ }
37907
+ destroy() {
37908
+ throw new Error("Method not implemented.");
37909
+ }
37910
+ get isFocus() {
37911
+ const L = this.getState();
37912
+ return L ? !!L.focus : !1;
37913
+ }
37914
+ setState(L) {
37915
+ this.context.map.setFeatureState(
37916
+ {
37917
+ source: this.SOURCE,
37918
+ id: this.id
37919
+ },
37920
+ L
37921
+ );
37922
+ }
37923
+ getState() {
37924
+ return this.context.map.getFeatureState({
37925
+ source: this.SOURCE,
37926
+ id: this.id
37927
+ });
37928
+ }
37929
+ isSelf(L) {
37930
+ if (L.features && L.features.length > 0) {
37931
+ const q = L.features[0];
37932
+ return String(q.id) === this.id;
37933
+ } else
37934
+ return !1;
37935
+ }
37936
+ getName() {
37937
+ return this.NAME;
37938
+ }
37939
+ }
37940
+ var qm = { exports: {} }, BE = qm.exports, J1;
37941
+ function NE() {
37823
37942
  return J1 || (J1 = 1, (function(G, L) {
37824
37943
  (function(q, ae) {
37825
37944
  G.exports = ae();
37826
- })(kE, (function() {
37945
+ })(BE, (function() {
37827
37946
  var q = 1e3, ae = 6e4, Me = 36e5, Be = "millisecond", Qe = "second", o = "minute", st = "hour", We = "day", ht = "week", gt = "month", Xt = "quarter", Jt = "year", ai = "date", Vt = "Invalid Date", Ct = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, Ji = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, gi = { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), ordinal: function(ci) {
37828
37947
  var Et = ["th", "st", "nd", "rd"], dt = ci % 100;
37829
37948
  return "[" + ci + (Et[(dt - 20) % 10] || Et[dt] || Et[0]) + "]";
@@ -38096,53 +38215,11 @@ function BE() {
38096
38215
  }));
38097
38216
  })(qm)), qm.exports;
38098
38217
  }
38099
- var NE = BE();
38100
- const VE = /* @__PURE__ */ rb(NE);
38101
- class UE extends Ym {
38102
- options;
38103
- SOURCE = "mapbox-gl-ship-source";
38104
- NAME = "Base";
38105
- visible = !0;
38106
- constructor(L, q) {
38107
- super(L), this.options = q;
38108
- }
38109
- destroy() {
38110
- throw new Error("Method not implemented.");
38111
- }
38112
- get isFocus() {
38113
- const L = this.getState();
38114
- return L ? !!L.focus : !1;
38115
- }
38116
- setState(L) {
38117
- this.context.map.setFeatureState(
38118
- {
38119
- source: this.SOURCE,
38120
- id: this.id
38121
- },
38122
- L
38123
- );
38124
- }
38125
- getState() {
38126
- return this.context.map.getFeatureState({
38127
- source: this.SOURCE,
38128
- id: this.id
38129
- });
38130
- }
38131
- isSelf(L) {
38132
- if (L.features && L.features.length > 0) {
38133
- const q = L.features[0];
38134
- return String(q.id) === this.id;
38135
- } else
38136
- return !1;
38137
- }
38138
- getName() {
38139
- return this.NAME;
38140
- }
38141
- }
38142
- class jE extends UE {
38218
+ var VE = NE();
38219
+ const UE = /* @__PURE__ */ rb(VE);
38220
+ class qE extends kE {
38143
38221
  SOURCE = pf;
38144
38222
  NAME = _a;
38145
- tooltip = null;
38146
38223
  constructor(L, q) {
38147
38224
  super(L, q), this.options.tooltip && (this.setTooltip(
38148
38225
  new ME(this.context.map, {
@@ -38176,7 +38253,7 @@ class jE extends UE {
38176
38253
  return this.options.id;
38177
38254
  }
38178
38255
  get updateStatus() {
38179
- const L = Date.now() - VE(Number(this.options.time)).valueOf();
38256
+ const L = Date.now() - UE(Number(this.options.time)).valueOf();
38180
38257
  return L <= 18e5 ? ul.ONLINE : L > 18e5 && L <= 72e5 ? ul.DELAY : (L > 72e5, ul.OFFLINE);
38181
38258
  }
38182
38259
  getIconName() {
@@ -38340,81 +38417,17 @@ class jE extends UE {
38340
38417
  return L;
38341
38418
  }
38342
38419
  }
38343
- class qE extends Ym {
38344
- // options: IShipOptions
38345
- ships = [];
38346
- event;
38347
- collision;
38348
- constructor(L) {
38349
- super(L), this.collision = new wS(this.context.map), this.event = new FE(L);
38350
- }
38351
- onAdd() {
38352
- }
38353
- onRemove() {
38354
- }
38355
- get tooltips() {
38356
- return this.ships.flatMap((L) => L.tooltip ?? []);
38357
- }
38358
- // private get plugins(): IShipOptions['plugins'] {
38359
- // return this.options.plugins
38360
- // }
38361
- createCollisions() {
38362
- return this.tooltips.map((L) => ({
38363
- ...L.getAllBbox(),
38364
- id: L.id
38365
- }));
38366
- }
38367
- collisionTooltip() {
38368
- this.collision.load(this.createCollisions()).forEach((L) => {
38369
- const q = this.tooltips.find((ae) => ae.id === L.id);
38370
- q && (L.visible ? q.setAnchor(L.dir) : q.hide());
38371
- });
38372
- }
38373
- add(L) {
38374
- const q = new jE(this.context.map, L);
38375
- return this.ships.push(q), this.event.add(q), q;
38376
- }
38377
- load(L) {
38378
- return this.removeAll(), this.ships = L.map((q) => this.add(q)), this.render(), this.collisionTooltip(), this.ships;
38379
- }
38380
- remove(L) {
38381
- this.event.remove(L);
38382
- const q = this.ships.findIndex((ae) => ae.id === L);
38383
- q !== -1 && (this.ships[q].remove(), this.ships.splice(q, 1));
38384
- }
38385
- removeAll() {
38386
- this.collision.clear(), this.ships.forEach((L) => {
38387
- L.remove();
38388
- }), this.ships = [];
38389
- }
38390
- render() {
38391
- this.ships.forEach((L) => {
38392
- L.render();
38393
- });
38394
- }
38395
- get(L) {
38396
- return this.ships.find((q) => q.id === L);
38397
- }
38398
- select(L) {
38399
- const q = this.get(L);
38400
- q && q.select();
38401
- }
38402
- unselect(L) {
38403
- const q = this.get(L);
38404
- q && q.unselect();
38405
- }
38406
- }
38407
38420
  export {
38408
- jE as AisShip,
38409
- UE as BaseShip,
38410
- $E as CMap,
38421
+ qE as AisShip,
38422
+ kE as BaseShip,
38423
+ GE as CMap,
38411
38424
  fS as Cache,
38412
38425
  wS as Collision,
38413
38426
  bS as CollisionItem,
38414
38427
  wE as Context,
38415
38428
  df as IconManager,
38416
38429
  Ym as Module,
38417
- qE as Ship,
38430
+ $E as Ship,
38418
38431
  ME as Tooltip
38419
38432
  };
38420
38433
  //# sourceMappingURL=index.es.js.map