@sswroom/sswr 1.4.0 → 1.5.0

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/kml.js CHANGED
@@ -29,6 +29,12 @@ export const ItemIconMode = {
29
29
  Fetching2: "fetching2"
30
30
  };
31
31
 
32
+ export const HotSpotUnit = {
33
+ Fraction: "fraction",
34
+ Pixels: "pixels",
35
+ InsetPixels: "insetPixels"
36
+ }
37
+
32
38
  export class Element
33
39
  {
34
40
  }
@@ -62,6 +68,10 @@ export class LookAt extends Element
62
68
  this.altitudeMode = altitudeMode;
63
69
  }
64
70
 
71
+ getUsedNS(ns)
72
+ {
73
+ }
74
+
65
75
  appendOuterXML(strs, level)
66
76
  {
67
77
  strs.push("\t".repeat(level)+"<LookAt>");
@@ -117,6 +127,14 @@ export class ColorStyle extends Element
117
127
  this.fromARGB(c.a, c.r, c.g, c.b);
118
128
  }
119
129
 
130
+ setColor(color)
131
+ {
132
+ if (typeof color == "string" && color.length == 8)
133
+ {
134
+ this.color = color;
135
+ }
136
+ }
137
+
120
138
  sameColor(c)
121
139
  {
122
140
  if (this.randomColor != c.randomColor)
@@ -157,21 +175,27 @@ export class IconStyle extends ColorStyle
157
175
  this.iconUrl = iconUrl;
158
176
  }
159
177
 
160
- setHotSpotX(hotSpotX)
178
+ setHotSpotX(hotSpotX, hsUnit)
161
179
  {
162
180
  this.hotSpotX = hotSpotX;
181
+ this.hotSpotUnitX = hsUnit || HotSpotUnit.Fraction;
163
182
  }
164
183
 
165
- setHotSpotY(hotSpotY)
184
+ setHotSpotY(hotSpotY, hsUnit)
166
185
  {
167
186
  this.hotSpotY = hotSpotY;
187
+ this.hotSpotUnitY = hsUnit || HotSpotUnit.Fraction;
188
+ }
189
+
190
+ getUsedNS(ns)
191
+ {
168
192
  }
169
193
 
170
194
  appendOuterXML(strs, level)
171
195
  {
172
196
  strs.push("\t".repeat(level)+"<IconStyle>");
173
197
  this.appendInnerXML(strs, level + 1);
174
- if (this.scale)
198
+ if (this.scale != null)
175
199
  strs.push("\t".repeat(level + 1)+"<scale>"+this.scale+"</scale>");
176
200
  if (this.heading != null)
177
201
  strs.push("\t".repeat(level + 1)+"<heading>"+this.heading+"</heading>");
@@ -182,7 +206,7 @@ export class IconStyle extends ColorStyle
182
206
  strs.push("\t".repeat(level + 1)+"</Icon>");
183
207
  }
184
208
  if (this.hotSpotX != null && this.hotSpotY != null)
185
- strs.push("\t".repeat(level + 1)+"<hotSpot x="+text.toAttrText(""+this.hotSpotX)+" y="+text.toAttrText(""+this.hotSpotY)+" xunits=\"fraction\" yunits=\"fraction\"/>");
209
+ strs.push("\t".repeat(level + 1)+"<hotSpot x="+text.toAttrText(""+this.hotSpotX)+" y="+text.toAttrText(""+this.hotSpotY)+" xunits=\""+this.hotSpotUnitX+"\" yunits=\""+this.hotSpotUnitY+"\"/>");
186
210
  strs.push("\t".repeat(level)+"</IconStyle>");
187
211
  }
188
212
 
@@ -202,6 +226,10 @@ export class IconStyle extends ColorStyle
202
226
  return false;
203
227
  if (this.hotSpotY != o.hotSpotY)
204
228
  return false;
229
+ if (this.hotSpotUnitX != o.hotSpotUnitX)
230
+ return false;
231
+ if (this.hotSpotUnitY != o.hotSpotUnitY)
232
+ return false;
205
233
  return true;
206
234
  }
207
235
  }
@@ -213,10 +241,21 @@ export class LabelStyle extends ColorStyle
213
241
  super();
214
242
  }
215
243
 
244
+ setScale(scale)
245
+ {
246
+ this.scale = scale;
247
+ }
248
+
249
+ getUsedNS(ns)
250
+ {
251
+ }
252
+
216
253
  appendOuterXML(strs, level)
217
254
  {
218
255
  strs.push("\t".repeat(level)+"<LabelStyle>");
219
256
  this.appendInnerXML(strs, level + 1);
257
+ if (this.scale != null)
258
+ strs.push("\t".repeat(level + 1)+"<scale>"+this.scale+"</scale>");
220
259
  strs.push("\t".repeat(level)+"</LabelStyle>");
221
260
  }
222
261
 
@@ -226,6 +265,8 @@ export class LabelStyle extends ColorStyle
226
265
  return false;
227
266
  if (!this.sameColor(o))
228
267
  return false;
268
+ if (this.scale != o.scale)
269
+ return false;
229
270
  return true;
230
271
  }
231
272
  };
@@ -242,12 +283,25 @@ export class LineStyle extends ColorStyle
242
283
  this.width = width;
243
284
  }
244
285
 
286
+ setLabelVisibility(labelVisibility)
287
+ {
288
+ this.labelVisibility = labelVisibility;
289
+ }
290
+
291
+ getUsedNS(ns)
292
+ {
293
+ if (this.labelVisibility != null)
294
+ ns.gx = "http://www.google.com/kml/ext/2.2";
295
+ }
296
+
245
297
  appendOuterXML(strs, level)
246
298
  {
247
299
  strs.push("\t".repeat(level)+"<LineStyle>");
248
300
  this.appendInnerXML(strs, level + 1);
249
301
  if (this.width)
250
302
  strs.push("\t".repeat(level + 1)+"<width>"+this.width+"</width>");
303
+ if (this.labelVisibility != null)
304
+ strs.push("\t".repeat(level + 1)+"<gx:labelVisibility>"+(this.labelVisibility?"1":"0")+"</gx:labelVisibility>");
251
305
  strs.push("\t".repeat(level)+"</LineStyle>");
252
306
  }
253
307
 
@@ -261,7 +315,7 @@ export class LineStyle extends ColorStyle
261
315
  return false;
262
316
  return true;
263
317
  }
264
- };
318
+ }
265
319
 
266
320
  export class PolyStyle extends ColorStyle
267
321
  {
@@ -270,6 +324,10 @@ export class PolyStyle extends ColorStyle
270
324
  super();
271
325
  }
272
326
 
327
+ getUsedNS(ns)
328
+ {
329
+ }
330
+
273
331
  appendOuterXML(strs, level)
274
332
  {
275
333
  strs.push("\t".repeat(level)+"<PolyStyle>");
@@ -294,6 +352,10 @@ export class BalloonStyle extends Element
294
352
  super();
295
353
  }
296
354
 
355
+ getUsedNS(ns)
356
+ {
357
+ }
358
+
297
359
  appendOuterXML(strs, level)
298
360
  {
299
361
  strs.push("\t".repeat(level)+"<BalloonStyle>");
@@ -332,6 +394,10 @@ export class ListStyle extends Element
332
394
  super();
333
395
  }
334
396
 
397
+ getUsedNS(ns)
398
+ {
399
+ }
400
+
335
401
  appendOuterXML(strs, level)
336
402
  {
337
403
  strs.push("\t".repeat(level)+"<ListStyle>");
@@ -355,13 +421,21 @@ export class ListStyle extends Element
355
421
  }
356
422
  };
357
423
 
358
- export class Style extends Element
424
+ export class StyleSelector extends Element
359
425
  {
360
426
  constructor(id)
361
427
  {
362
428
  super();
363
429
  this.id = id;
364
430
  }
431
+ }
432
+
433
+ export class Style extends StyleSelector
434
+ {
435
+ constructor(id)
436
+ {
437
+ super(id);
438
+ }
365
439
 
366
440
  setIconStyle(style)
367
441
  {
@@ -494,6 +568,16 @@ export class Style extends Element
494
568
  return true;
495
569
  }
496
570
 
571
+ getUsedNS(ns)
572
+ {
573
+ if (this.iconStyle) this.iconStyle.getUsedNS(ns);
574
+ if (this.labelStyle) this.labelStyle.getUsedNS(ns);
575
+ if (this.lineStyle) this.lineStyle.getUsedNS(ns);
576
+ if (this.polyStyle) this.polyStyle.getUsedNS(ns);
577
+ if (this.balloonStyle) this.balloonStyle.getUsedNS(ns);
578
+ if (this.listStyle) this.listStyle.getUsedNS(ns);
579
+ }
580
+
497
581
  appendOuterXML(strs, level)
498
582
  {
499
583
  strs.push("\t".repeat(level)+"<Style id="+text.toAttrText(this.id)+">");
@@ -507,6 +591,34 @@ export class Style extends Element
507
591
  }
508
592
  };
509
593
 
594
+ export class StyleMap extends StyleSelector
595
+ {
596
+ constructor(id, normalStyle, highlightStyle)
597
+ {
598
+ super(id);
599
+ this.normalStyle = normalStyle;
600
+ this.highlightStyle = highlightStyle;
601
+ }
602
+
603
+ getUsedNS(ns)
604
+ {
605
+ }
606
+
607
+ appendOuterXML(strs, level)
608
+ {
609
+ strs.push("\t".repeat(level)+"<StyleMap id="+text.toAttrText(this.id)+">");
610
+ strs.push("\t".repeat(level + 1)+"<Pair>");
611
+ strs.push("\t".repeat(level + 2)+"<key>normal</key>");
612
+ strs.push("\t".repeat(level + 2)+"<styleUrl>#"+text.toXMLText(this.normalStyle.id)+"</styleUrl>");
613
+ strs.push("\t".repeat(level + 1)+"</Pair>");
614
+ strs.push("\t".repeat(level + 1)+"<Pair>");
615
+ strs.push("\t".repeat(level + 2)+"<key>highlight</key>");
616
+ strs.push("\t".repeat(level + 2)+"<styleUrl>#"+text.toXMLText(this.highlightStyle.id)+"</styleUrl>");
617
+ strs.push("\t".repeat(level + 1)+"</Pair>");
618
+ strs.push("\t".repeat(level)+"</Style>");
619
+ }
620
+ }
621
+
510
622
  export class Feature extends Element
511
623
  {
512
624
  constructor()
@@ -604,24 +716,32 @@ export class Container extends Feature
604
716
  super();
605
717
  this.eleName = eleName;
606
718
  this.features = [];
719
+ this.styleList = null;
607
720
  }
608
721
 
609
722
  addFeature(feature)
610
723
  {
611
724
  this.features.push(feature);
612
725
  }
613
- }
614
726
 
615
- export class Document extends Container
616
- {
617
- constructor()
727
+ addStyle(style)
618
728
  {
619
- super("Document");
620
- this.styleList = [];
729
+ if (this.styleList == null)
730
+ this.styleList = [];
731
+ this.styleList.push(style);
732
+ }
733
+
734
+ addStyleMap(styleMap)
735
+ {
736
+ if (this.styleMapList == null)
737
+ this.styleMapList = [];
738
+ this.styleMapList.push(styleMap);
621
739
  }
622
740
 
623
741
  getOrNewStyle(iconStyle, labelStyle, lineStyle, polyStyle, balloonStyle, listStyle)
624
742
  {
743
+ if (this.styleList == null)
744
+ this.styleList = [];
625
745
  var i;
626
746
  for (i in this.styleList)
627
747
  {
@@ -639,14 +759,58 @@ export class Document extends Container
639
759
  return style;
640
760
  }
641
761
 
762
+ getStyleById(id)
763
+ {
764
+ var i;
765
+ if (this.styleList)
766
+ {
767
+ for (i in this.styleList)
768
+ {
769
+ if (this.styleList[i].id == id)
770
+ return this.styleList[i];
771
+ }
772
+ }
773
+ if (this.styleMapList)
774
+ {
775
+ for (i in this.styleMapList)
776
+ {
777
+ if (this.styleMapList[i].id == id)
778
+ return this.styleMapList[i];
779
+ }
780
+ }
781
+ return null;
782
+ }
783
+
784
+ getUsedNS(ns)
785
+ {
786
+ if (this.styleList)
787
+ {
788
+ var i;
789
+ for (i in this.styleList)
790
+ {
791
+ this.styleList[i].getUsedNS(ns);
792
+ }
793
+ }
794
+ }
795
+
642
796
  appendOuterXML(strs, level)
643
797
  {
644
798
  var i;
645
799
  strs.push("\t".repeat(level)+"<"+this.eleName+">");
646
800
  this.appendInnerXML(strs, level + 1);
647
- for (i in this.styleList)
801
+ if (this.styleList)
802
+ {
803
+ for (i in this.styleList)
804
+ {
805
+ this.styleList[i].appendOuterXML(strs, level + 1);
806
+ }
807
+ }
808
+ if (this.styleMapList)
648
809
  {
649
- this.styleList[i].appendOuterXML(strs, level + 1);
810
+ for (i in this.styleMapList)
811
+ {
812
+ this.styleMapList[i].appendOuterXML(strs, level + 1);
813
+ }
650
814
  }
651
815
  for (i in this.features)
652
816
  {
@@ -656,23 +820,19 @@ export class Document extends Container
656
820
  }
657
821
  }
658
822
 
659
- export class Folder extends Container
823
+ export class Document extends Container
660
824
  {
661
825
  constructor()
662
826
  {
663
- super("Folder");
827
+ super("Document");
664
828
  }
829
+ }
665
830
 
666
- appendOuterXML(strs, level)
831
+ export class Folder extends Container
832
+ {
833
+ constructor()
667
834
  {
668
- strs.push("\t".repeat(level)+"<"+this.eleName+">");
669
- this.appendInnerXML(strs, level + 1);
670
- var i;
671
- for (i in this.features)
672
- {
673
- this.features[i].appendOuterXML(strs, level + 1);
674
- }
675
- strs.push("\t".repeat(level)+"</"+this.eleName+">");
835
+ super("Folder");
676
836
  }
677
837
  }
678
838
 
@@ -808,6 +968,10 @@ export class Placemark extends Feature
808
968
  }
809
969
  }
810
970
 
971
+ getUsedNS(ns)
972
+ {
973
+ }
974
+
811
975
  appendOuterXML(strs, level)
812
976
  {
813
977
  strs.push("\t".repeat(level)+"<Placemark>");
@@ -824,8 +988,22 @@ export function toString(item)
824
988
  {
825
989
  var strs = [];
826
990
  strs.push("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
991
+ var namespaces = {};
992
+ item.getUsedNS(namespaces);
827
993
  strs.push("<kml xmlns=\"http://www.opengis.net/kml/2.2\">");
828
994
  item.appendOuterXML(strs, 1);
829
995
  strs.push("</kml>");
830
996
  return strs.join("\r\n");
831
997
  }
998
+
999
+ export function toCSSColor(color)
1000
+ {
1001
+ if (color.length != 8)
1002
+ return null;
1003
+
1004
+ var a = Number.parseInt(color.substring(0, 2), 16);
1005
+ var b = Number.parseInt(color.substring(2, 4), 16);
1006
+ var g = Number.parseInt(color.substring(4, 6), 16);
1007
+ var r = Number.parseInt(color.substring(6, 8), 16);
1008
+ return "rgba("+r+", "+g+", "+b+", "+(a / 255.0)+")";
1009
+ }
package/leaflet.d.ts CHANGED
@@ -1,12 +1,59 @@
1
1
  import * as L from "./node_modules/leaflet/src/Leaflet";
2
+ import * as geometry from "./geometry";
2
3
  import * as kml from "./kml";
3
4
  import { Coord2D, RectArea } from "./math";
4
- import { LayerInfo } from "./map";
5
+ import * as map from "./map";
6
+
7
+ declare class GeometryOptions
8
+ {
9
+ name: string;
10
+ icon: object;
11
+ }
12
+
13
+ declare class KMLFeatureOptions
14
+ {
15
+ noPopup: boolean;
16
+ }
5
17
 
6
18
  export function fromLatLon(latLon: L.LatLng): Coord2D;
7
19
  export function fromLatLng(latLng: L.LatLng): Coord2D;
8
20
  export function fromLatLngBounds(b: L.LatLngBounds): RectArea;
9
- export function createLayer(layer: LayerInfo, options: object): L.Layer;
21
+ export function createLayer(layer: map.LayerInfo, options: object): L.Layer;
22
+ export function createFromKMLFeature(feature: kml.Feature, options: KMLFeatureOptions): L.Layer;
23
+ export function createFromGeometry(geom: geometry.Vector2D, options: GeometryOptions): L.Layer;
10
24
  export function createKMLLookAt(map: L.Map): kml.LookAt;
11
25
  export function toKMLFeature(layer: L.Layer, doc?: kml.Document): kml.Feature | null;
12
- export function toKMLString(layer: L.Layer): string | null;
26
+ export function toKMLString(layer: L.Layer): string | null;
27
+
28
+ export class LeafletMap extends map.MapControl
29
+ {
30
+ constructor(divId: string);
31
+ createLayer(layer: map.LayerInfo, options?: LayerOptions): any;
32
+ createMarkerLayer(name: string, options?: LayerOptions): any;
33
+ createGeometryLayer(name: string, options?: LayerOptions): any;
34
+ addLayer(layer: any): void;
35
+ addKMLFeature(feature: kml.Feature): void;
36
+ uninit(): void;
37
+ zoomIn(): void;
38
+ zoomOut(): void;
39
+ zoomScale(scale: number): void;
40
+ panTo(pos: math.Coord2D): void;
41
+ panZoomScale(pos: math.Coord2D, scale: number): void;
42
+ zoomToExtent(extent: math.RectArea): void;
43
+ handleMouseLClick(clickFunc: (mapPos: math.Coord2D, scnPos: math.Coord2D)=>void): void;
44
+ handleMouseMove(moveFunc: (mapPos: math.Coord2D)=>void): void;
45
+ handlePosChange(posFunc: (mapPos: math.Coord2D)=>void): void;
46
+ map2ScnPos(mapPos: math.Coord2D): math.Coord2D;
47
+ scn2MapPos(scnPos: math.Coord2D): math.Coord2D;
48
+
49
+ createMarker(mapPos: math.Coord2D, imgURL: string, imgWidth: number, imgHeight: number, options?: MarkerOptions): any;
50
+ layerAddMarker(markerLayer: any, marker: any): void;
51
+ layerRemoveMarker(markerLayer: any, marker: any): void;
52
+ layerClearMarkers(markerLayer: any): void;
53
+ markerIsOver(marker: any, scnPos: math.Coord2D): boolean;
54
+
55
+ createGeometry(geom: geometry.Vector2D, options: GeometryOptions): any;
56
+ layerAddGeometry(geometryLayer: any, geom: any): void;
57
+ layerRemoveGeometry(geometryLayer: any, geom: any): void;
58
+ layerClearGeometries(geometryLayer: any): void;
59
+ }