@sswroom/sswr 1.5.3 → 1.5.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.
package/Changelog CHANGED
@@ -1,3 +1,10 @@
1
+ 1.5.4
2
+ -Added geometry.Vector2D.getBounds
3
+ -Added kml.Feature.getBounds
4
+ -Added leaflet.toLatLngBounds
5
+ -Added math.RectArea.unionInPlace
6
+ -Added math.RectArea.unionPointInPlace
7
+
1
8
  1.5.3
2
9
  -Fixed parser file type handling
3
10
 
package/cesium.js CHANGED
@@ -462,8 +462,21 @@ export class CesiumMap extends map.MapControl
462
462
  {
463
463
  this.viewer.camera.flyTo({destination: Cesium.Cartesian3.fromDegrees(pos.x, pos.y, scale), duration:0});
464
464
  }
465
- /* zoomToExtent(extent: math.RectArea): void;
466
- handleMouseLClick(clickFunc: (mapPos: math.Coord2D, scnPos: math.Coord2D)=>void): void;
465
+
466
+ zoomToExtent(extent)
467
+ {
468
+ const zoomRatio = 500000000;
469
+ let center = extent.getCenter();
470
+ let xScale = (extent.max.x - extent.min.x) / this.viewer.canvas.width * zoomRatio;
471
+ let yScale = (extent.max.y - extent.min.y) / this.viewer.canvas.height * zoomRatio;
472
+ if (yScale > xScale)
473
+ {
474
+ xScale = yScale;
475
+ }
476
+ this.viewer.camera.flyTo({destination: Cesium.Cartesian3.fromDegrees(center.x, center.y, xScale), duration:0});
477
+ }
478
+
479
+ /* handleMouseLClick(clickFunc: (mapPos: math.Coord2D, scnPos: math.Coord2D)=>void): void;
467
480
  handleMouseMove(moveFunc: (mapPos: math.Coord2D)=>void): void;
468
481
  handlePosChange(posFunc: (mapPos: math.Coord2D)=>void): void;
469
482
  map2ScnPos(mapPos: math.Coord2D): math.Coord2D;
package/geometry.d.ts CHANGED
@@ -40,6 +40,7 @@ export class Vector2D {
40
40
  type: VectorType;
41
41
  constructor(srid: number);
42
42
  insideOrTouch(coord: math.Coord2D): boolean;
43
+ getBounds(): math.RectArea;
43
44
  };
44
45
 
45
46
  export class Point extends Vector2D
@@ -47,6 +48,7 @@ export class Point extends Vector2D
47
48
  coordinates: number[];
48
49
  constructor(srid: number, coordinates: number[] | math.Coord2D | math.Vector3);
49
50
  insideOrTouch(coord: math.Coord2D): boolean;
51
+ getBounds(): math.RectArea;
50
52
  }
51
53
 
52
54
 
@@ -56,6 +58,7 @@ export class LineString extends Vector2D
56
58
  constructor(srid: number, coordinates: number[][]);
57
59
  calBoundaryPoint(coord: math.Coord2D): BoundaryPointResult;
58
60
  insideOrTouch(coord: math.Coord2D): boolean;
61
+ getBounds(): math.RectArea;
59
62
  }
60
63
 
61
64
  export class LinearRing extends LineString
@@ -76,6 +79,7 @@ export class MultiGeometry<VecType> extends Vector2D
76
79
  constructor(srid: number);
77
80
  calBoundaryPoint(coord: math.Coord2D): BoundaryPointResult;
78
81
  insideOrTouch(coord: math.Coord2D): boolean;
82
+ getBounds(): math.RectArea;
79
83
  }
80
84
 
81
85
  export class Polygon extends MultiGeometry<LinearRing>
package/geometry.js CHANGED
@@ -52,6 +52,11 @@ export class Point extends Vector2D
52
52
  {
53
53
  return this.coordinates[0] == coord.x && this.coordinates[1] == coord.y;
54
54
  }
55
+
56
+ getBounds()
57
+ {
58
+ return new math.RectArea(this.coordinates[0], this.coordinates[1], this.coordinates[0], this.coordinates[1]);
59
+ }
55
60
  }
56
61
 
57
62
  export class LineString extends Vector2D
@@ -226,6 +231,17 @@ export class LineString extends Vector2D
226
231
  }
227
232
  return false;
228
233
  }
234
+
235
+ getBounds()
236
+ {
237
+ let bounds = new math.RectArea(this.coordinates[0][0], this.coordinates[0][1], this.coordinates[0][0], this.coordinates[0][1]);
238
+ let i;
239
+ for (i in this.coordinates)
240
+ {
241
+ bounds.unionPointInPlace(this.coordinates[i][0], this.coordinates[i][1]);
242
+ }
243
+ return bounds;
244
+ }
229
245
  }
230
246
 
231
247
  export class LinearRing extends LineString
@@ -364,6 +380,29 @@ export class MultiGeometry extends Vector2D
364
380
  }
365
381
  return false;
366
382
  }
383
+
384
+ getBounds()
385
+ {
386
+ if (this.geometries.length == 0)
387
+ {
388
+ return null;
389
+ }
390
+ let bounds;
391
+ let thisBounds;
392
+ let i;
393
+ for (i in this.geometries)
394
+ {
395
+ thisBounds = this.geometries[i].getBounds();
396
+ if (thisBounds)
397
+ {
398
+ if (bounds)
399
+ bounds.unionInPlace(thisBounds);
400
+ else
401
+ bounds = thisBounds;
402
+ }
403
+ }
404
+ return bounds;
405
+ }
367
406
  }
368
407
 
369
408
  export class Polygon extends MultiGeometry
package/kml.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as data from "./data";
2
2
  import * as geometry from "./geometry";
3
+ import * as math from "./math";
3
4
  import * as web from "./web";
4
5
 
5
6
  export enum AltitudeMode
@@ -235,6 +236,7 @@ export class Feature extends Element
235
236
  setDescription(description: string): void;
236
237
  setLookAt(lookAt: LookAt): void;
237
238
  setStyle(style: StyleSelector): void;
239
+ getBounds(): math.RectArea | null;
238
240
 
239
241
  appendInnerXML(strs: string[], level: number): void;
240
242
  }
@@ -252,6 +254,7 @@ export class Container extends Feature
252
254
  addStyleMap(styleMap: StyleMap): void;
253
255
  getOrNewStyle(iconStyle: IconStyle, labelStyle: LabelStyle, lineStyle: LineStyle, polyStyle: PolyStyle, balloonStyle: BalloonStyle, listStyle: ListStyle): Style;
254
256
  getStyleById(id: string): Style | StyleMap | null;
257
+ getBounds(): math.RectArea | null;
255
258
  getUsedNS(ns: object): void;
256
259
  appendOuterXML(strs: string[], level: number): void;
257
260
  }
@@ -270,6 +273,7 @@ export class NetworkLink extends Feature
270
273
  {
271
274
  constructor();
272
275
 
276
+ getBounds(): math.RectArea | null;
273
277
  getUsedNS(ns: object): void;
274
278
  appendOuterXML(strs: string[], level: number): void;
275
279
  }
@@ -280,6 +284,7 @@ export class Placemark extends Feature
280
284
  constructor(vec: geometry.Vector2D);
281
285
 
282
286
  appendGeometry(strs: string[], level: number, vec: geometry.Vector2D, subGeom?: boolean): void;
287
+ getBounds(): math.RectArea | null;
283
288
  getUsedNS(ns: object): void;
284
289
  appendOuterXML(strs: string[], level: number): void;
285
290
  }
package/kml.js CHANGED
@@ -790,6 +790,29 @@ export class Container extends Feature
790
790
  return null;
791
791
  }
792
792
 
793
+ getBounds()
794
+ {
795
+ let bounds = null;
796
+ let thisBounds;
797
+ let i;
798
+ for (i in this.features)
799
+ {
800
+ thisBounds = this.features[i].getBounds();
801
+ if (thisBounds)
802
+ {
803
+ if (bounds)
804
+ {
805
+ bounds = bounds.unionInPlace(thisBounds);
806
+ }
807
+ else
808
+ {
809
+ bounds = thisBounds;
810
+ }
811
+ }
812
+ }
813
+ return bounds;
814
+ }
815
+
793
816
  getUsedNS(ns)
794
817
  {
795
818
  if (this.styleList)
@@ -977,6 +1000,15 @@ export class Placemark extends Feature
977
1000
  }
978
1001
  }
979
1002
 
1003
+ getBounds()
1004
+ {
1005
+ if (this.vec)
1006
+ {
1007
+ return this.vec.getBounds();
1008
+ }
1009
+ return null;
1010
+ }
1011
+
980
1012
  getUsedNS(ns)
981
1013
  {
982
1014
  }
package/leaflet.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as L from "./node_modules/leaflet/src/Leaflet";
2
2
  import * as geometry from "./geometry";
3
3
  import * as kml from "./kml";
4
- import { Coord2D, RectArea } from "./math";
4
+ import * as math from "./math";
5
5
  import * as map from "./map";
6
6
 
7
7
  declare class GeometryOptions
@@ -15,9 +15,11 @@ declare class KMLFeatureOptions
15
15
  noPopup: boolean;
16
16
  }
17
17
 
18
- export function fromLatLon(latLon: L.LatLng): Coord2D;
19
- export function fromLatLng(latLng: L.LatLng): Coord2D;
20
- export function fromLatLngBounds(b: L.LatLngBounds): RectArea;
18
+ export function fromLatLon(latLon: L.LatLng): math.Coord2D;
19
+ export function fromLatLng(latLng: L.LatLng): math.Coord2D;
20
+ export function fromLatLngBounds(b: L.LatLngBounds): math.RectArea;
21
+ export function toLatLngBounds(rect: math.RectArea): L.LatLngBounds;
22
+
21
23
  export function createLayer(layer: map.LayerInfo, options: object): L.Layer;
22
24
  export function createFromKMLFeature(feature: kml.Feature, options: KMLFeatureOptions): L.Layer;
23
25
  export function createFromGeometry(geom: geometry.Vector2D, options: GeometryOptions): L.Layer;
package/leaflet.js CHANGED
@@ -22,6 +22,11 @@ export function fromLatLngBounds(b)
22
22
  return new math.RectArea(b.getWest(), b.getSouth(), b.getEast(), b.getNorth());
23
23
  }
24
24
 
25
+ export function toLatLngBounds(rect)
26
+ {
27
+ return L.latLngBounds(L.latLng(rect.min.y, rect.min.x), L.latLng(rect.max.y, rect.max.x));
28
+ }
29
+
25
30
  export function createLayer(layer, options)
26
31
  {
27
32
  let lyrOpts;
@@ -488,7 +493,10 @@ export class LeafletMap extends map.MapControl
488
493
  this.mapObj.setView(L.latLng(pos.y, pos.x), osm.scale2Level(scale));
489
494
  }
490
495
 
491
- //zoomToExtent(extent: math.RectArea): void;
496
+ zoomToExtent(extent)
497
+ {
498
+ this.mapObj.fitBounds(toLatLngBounds(extent));
499
+ }
492
500
 
493
501
  /* handleMouseLClick(clickFunc: (mapPos: math.Coord2D, scnPos: math.Coord2D)=>void): void;
494
502
  handleMouseMove(moveFunc: (mapPos: math.Coord2D)=>void): void;
package/math.d.ts CHANGED
@@ -34,6 +34,8 @@ export class RectArea
34
34
  getWidth(): number;
35
35
  getHeight(): number;
36
36
  getArea(): number;
37
+ unionInPlace(rect: RectArea): RectArea;
38
+ unionPointInPlace(x: number, y: number): RectArea;
37
39
  };
38
40
 
39
41
  export class Vector3 extends Coord2D
package/math.js CHANGED
@@ -149,6 +149,32 @@ export class RectArea
149
149
  {
150
150
  return this.getWidth() * this.getHeight();
151
151
  }
152
+
153
+ unionInPlace(rect)
154
+ {
155
+ if (this.min.x > rect.min.x)
156
+ this.min.x = rect.min.x;
157
+ if (this.min.y > rect.min.y)
158
+ this.min.y = rect.min.y;
159
+ if (this.max.x < rect.max.x)
160
+ this.max.x = rect.max.x;
161
+ if (this.max.y < rect.max.y)
162
+ this.max.y = rect.max.y;
163
+ return this;
164
+ }
165
+
166
+ unionPointInPlace(x, y)
167
+ {
168
+ if (this.min.x > x)
169
+ this.min.x = x;
170
+ if (this.min.y > y)
171
+ this.min.y = y;
172
+ if (this.max.x < x)
173
+ this.max.x = x;
174
+ if (this.max.y < y)
175
+ this.max.y = y;
176
+ return this;
177
+ }
152
178
  };
153
179
 
154
180
  export class Vector3 extends Coord2D
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sswroom/sswr",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "description": "Libraries made by sswroom",
5
5
  "main": "sswr.js",
6
6
  "scripts": {