@sswroom/sswr 1.5.0 → 1.5.2

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,40 @@
1
+ 1.5.2
2
+ -Support leaflet icon without adding to map
3
+ -Added web.mimeFromExt
4
+ -Added cesium.createFromKMLFeature
5
+ -Added web.getImageInfo
6
+ -Enhance KML parsing
7
+ -Added olayer2.createFromKMLFeature
8
+ -Added olayer2.createFromGeometry
9
+ -Added olayer2.toPointArray
10
+ -Added geometry.GeometryCollection
11
+ -geometry.MultiPolygon support dynamic adding
12
+ -kml.PolyStyle support outline
13
+ -cesium support Polygon/MultiPolygon
14
+ -Added text.toHex8, toHex16, toHex32
15
+ -Added text.getEncList
16
+ -Added text.TextBinEnc
17
+ -Added text.UTF8TextBinEnc
18
+ -Added text.UTF8LCaseTextBinEnc
19
+ -Added text.UTF8UCaseTextBinEnc
20
+ -Added text.HexTextBinEnc
21
+ -Added text.Base64Enc
22
+ -Added text.UTF16LETextBinEnc
23
+ -Added text.UTF16BETextBinEnc
24
+ -Added text.CPPByteArrBinEnc
25
+ -Added text.CPPTextBinEnc
26
+ -Added text.QuotedPrintableEnc
27
+ -Added text.ASN1OIDBinEnc
28
+ -Added text.URIEncoding
29
+ -Added text.FormEncoding
30
+ -Added text.ASCII85Enc
31
+ -Added data.readUInt/readMUInt
32
+ -Added net.oidText2PDU
33
+ -Added net.oidToString
34
+
35
+ 1.5.1
36
+ -Fixed AngleUnit problem
37
+
1
38
  1.5.0
2
39
  -Change unit.AngleUnit and unit.DistanceUnit to unit.Angle.Unit and unit.Distance.Unit
3
40
  -Added unit.Acceleration
package/cesium.d.ts CHANGED
@@ -1,16 +1,23 @@
1
1
  import { Cartesian3, Ellipsoid, Viewer } from "cesium";
2
- import { Polygon } from "./geometry";
2
+ import * as geometry from "./geometry";
3
3
  import * as kml from "./kml";
4
4
  import * as map from "./map";
5
5
  import { Coord2D } from "./math";
6
6
 
7
+ declare class KMLFeatureOptions
8
+ {
9
+ noPopup: boolean;
10
+ }
11
+
7
12
  export function screenToLatLon(viewer: Viewer, x: number, y: number, ellipsoid: Ellipsoid) : Coord2D;
8
13
  export function fromCXYZArray(arr: any[]): Cartesian3[];
9
14
  export function toCartesian3Arr(coords: number[][]) : Cartesian3[];
10
15
  export function newObjFromGeoJSON(geoJSON: object) : object;
11
16
  export function addGeoJSON(viewer: Viewer, geoJSON: object, color: any, extSize: number): void;
12
17
  export function fromCartesian3Array(viewer: Viewer, arr: Cartesian3[]): object[];
13
- export function fromPolygonGraphics(viewer: Viewer, pg: any): Polygon;
18
+ export function fromPolygonGraphics(viewer: Viewer, pg: any): geometry.Polygon;
19
+ export function createFromKMLFeature(feature: kml.Feature, options: KMLFeatureOptions): any;
20
+ export function createFromGeometry(geom: geometry.Vector2D, options: GeometryOptions)
14
21
 
15
22
  export class CesiumMap extends map.MapControl
16
23
  {
package/cesium.js CHANGED
@@ -1,29 +1,31 @@
1
+ import * as data from "./data.js";
2
+ import * as kml from "./kml.js";
1
3
  import * as map from "./map.js";
2
- import { Coord2D } from "./math.js";
3
- import { Polygon } from "./geometry.js";
4
+ import * as math from "./math.js";
5
+ import * as geometry from "./geometry.js";
4
6
 
5
7
  export function screenToLatLon(viewer, x, y, ellipsoid)
6
8
  {
7
- var pos = new Cesium.Cartesian2(x, y);
9
+ let pos = new Cesium.Cartesian2(x, y);
8
10
  if (ellipsoid == null)
9
11
  ellipsoid = viewer.scene.globe.ellipsoid;
10
- var cartesian = viewer.camera.pickEllipsoid(pos, ellipsoid);
12
+ let cartesian = viewer.camera.pickEllipsoid(pos, ellipsoid);
11
13
  if (cartesian)
12
14
  {
13
- var cartographic = ellipsoid.cartesianToCartographic(cartesian);
14
- return new Coord2D(cartographic.longitude * 180 / Math.PI, cartographic.latitude * 180 / Math.PI);
15
+ let cartographic = ellipsoid.cartesianToCartographic(cartesian);
16
+ return new math.Coord2D(cartographic.longitude * 180 / Math.PI, cartographic.latitude * 180 / Math.PI);
15
17
  }
16
18
  else
17
19
  {
18
- return new Coord2D(0, 0);
20
+ return new math.Coord2D(0, 0);
19
21
  }
20
22
  }
21
23
 
22
24
  export function fromCXYZArray(arr)
23
25
  {
24
- var ret = new Array();
25
- var i = 0;
26
- var j = arr.length;
26
+ let ret = new Array();
27
+ let i = 0;
28
+ let j = arr.length;
27
29
  while (i < j)
28
30
  {
29
31
  ret.push(Cesium.Cartesian3.fromArray(arr[i]));
@@ -34,9 +36,9 @@ export function fromCXYZArray(arr)
34
36
 
35
37
  export function toCartesian3Arr(coords)
36
38
  {
37
- var arr = new Array();
38
- var i = 0;
39
- var j = coords.length;
39
+ let arr = new Array();
40
+ let i = 0;
41
+ let j = coords.length;
40
42
  if (coords[0].length == 3)
41
43
  {
42
44
  while (i < j)
@@ -58,11 +60,11 @@ export function toCartesian3Arr(coords)
58
60
 
59
61
  export function newObjFromGeoJSON(geoJSON)
60
62
  {
61
- var o = new Object();
63
+ let o = new Object();
62
64
  o.id = geoJSON.id;
63
65
  o.name = geoJSON.id;
64
- var n;
65
- var props = new Array();
66
+ let n;
67
+ let props = new Array();
66
68
  for (n in geoJSON.properties)
67
69
  {
68
70
  props.push(text.toHTMLText(n)+": "+text.toHTMLText(geoJSON.properties[n]));
@@ -73,11 +75,11 @@ export function newObjFromGeoJSON(geoJSON)
73
75
 
74
76
  export function addGeoJSON(viewer, geoJSON, color, extSize)
75
77
  {
76
- var oColor = color.darken(0.5, new Cesium.Color());
78
+ let oColor = color.darken(0.5, new Cesium.Color());
77
79
  if (geoJSON.type == "FeatureCollection")
78
80
  {
79
- var i = 0;
80
- var j = geoJSON.features.length;
81
+ let i = 0;
82
+ let j = geoJSON.features.length;
81
83
  while (i < j)
82
84
  {
83
85
  addGeoJSON(viewer, geoJSON.features[i], color, extSize);
@@ -86,14 +88,14 @@ export function addGeoJSON(viewer, geoJSON, color, extSize)
86
88
  }
87
89
  else if (geoJSON.type == "Feature")
88
90
  {
89
- var o;
91
+ let o;
90
92
  if (geoJSON.geometry != null)
91
93
  {
92
94
  if (geoJSON.geometry.type == "Polygon")
93
95
  {
94
- var coordinates = geoJSON.geometry.coordinates;
95
- var i = 0;
96
- var j = coordinates.length;
96
+ let coordinates = geoJSON.geometry.coordinates;
97
+ let i = 0;
98
+ let j = coordinates.length;
97
99
  while (i < j)
98
100
  {
99
101
  o = newObjFromGeoJSON(geoJSON);
@@ -119,12 +121,12 @@ export function addGeoJSON(viewer, geoJSON, color, extSize)
119
121
 
120
122
  export function fromCartesian3Array(viewer, arr)
121
123
  {
122
- var coordinates = new Array();
123
- var points;
124
- var ellipsoid = viewer.scene.globe.ellipsoid;
125
- var cartoArr = ellipsoid.cartesianArrayToCartographicArray(arr);
126
- var i = 0;
127
- var j = cartoArr.length;
124
+ let coordinates = new Array();
125
+ let points;
126
+ let ellipsoid = viewer.scene.globe.ellipsoid;
127
+ let cartoArr = ellipsoid.cartesianArrayToCartographicArray(arr);
128
+ let i = 0;
129
+ let j = cartoArr.length;
128
130
  while (i < j)
129
131
  {
130
132
  points = new Array();
@@ -139,17 +141,213 @@ export function fromCartesian3Array(viewer, arr)
139
141
 
140
142
  export function fromPolygonGraphics(viewer, pg)
141
143
  {
142
- var coordinates = new Array();
143
- var hierarchy = pg.hierarchy.getValue();
144
+ let coordinates = new Array();
145
+ let hierarchy = pg.hierarchy.getValue();
144
146
  coordinates.push(fromCartesian3Array(viewer, hierarchy.positions));
145
- var i = 0;
146
- var j =hierarchy.holes.length;
147
+ let i = 0;
148
+ let j =hierarchy.holes.length;
147
149
  while (i < j)
148
150
  {
149
151
  coordinates.push(fromCartesian3Array(viewer, hierarchy.holes[i].positions));
150
152
  i++;
151
153
  }
152
- return new Polygon(4326, coordinates);
154
+ return new geometry.Polygon(4326, coordinates);
155
+ }
156
+
157
+ export function createFromKMLFeature(feature, options)
158
+ {
159
+ options = data.mergeOptions(options, {noPopup: false});
160
+ if (feature instanceof kml.Container)
161
+ {
162
+ let i;
163
+ let layers = [];
164
+ let layer;
165
+ for (i in feature.features)
166
+ {
167
+ layer = createFromKMLFeature(feature.features[i], options);
168
+ if (layer instanceof Cesium.Entity)
169
+ {
170
+ layers.push(layer);
171
+ }
172
+ else if (layer != null)
173
+ {
174
+ let j;
175
+ for (j in layer)
176
+ {
177
+ layers.push(layer[j]);
178
+ }
179
+ }
180
+ }
181
+ return layers;
182
+ }
183
+ else if (feature instanceof kml.Placemark)
184
+ {
185
+ let opt = {};
186
+ if (feature.name)
187
+ opt.name = feature.name;
188
+ if (feature.style)
189
+ {
190
+ let style = feature.style;
191
+ if (style instanceof kml.StyleMap)
192
+ {
193
+ style = style.normalStyle;
194
+ }
195
+ if (style instanceof kml.Style)
196
+ {
197
+ if (style.iconStyle)
198
+ {
199
+ let s = style.iconStyle;
200
+ if (s.iconUrl)
201
+ {
202
+ opt.iconUrl = s.iconUrl;
203
+ }
204
+ if (s.hotSpotX && s.hotSpotY)
205
+ {
206
+ if (s.hotSpotX == 0)
207
+ opt.horizontalOrigin = Cesium.HorizontalOrigin.LEFT;
208
+ else if (s.hotSpotUnitX == kml.HotSpotUnit.Fraction && s.hotSpotX == 1)
209
+ opt.horizontalOrigin = Cesium.HorizontalOrigin.RIGHT;
210
+ if (s.hotSpotY == 0)
211
+ opt.verticalOrigin = Cesium.VerticalOrigin.TOP;
212
+ else if (s.hotSpotUnitY == kml.HotSpotUnit.Fraction && s.hotSpotY == 1)
213
+ opt.verticalOrigin = Cesium.VerticalOrigin.BOTTOM;
214
+ else
215
+ {
216
+ if (s.hotSpotX * 2 == s.hotSpotY)
217
+ {
218
+ opt.verticalOrigin = Cesium.VerticalOrigin.CENTER;
219
+ }
220
+ }
221
+ }
222
+ }
223
+ if (style.lineStyle)
224
+ {
225
+ let ls = style.lineStyle;
226
+ if (ls.color)
227
+ opt.lineColor = ls.color;
228
+ if (ls.width)
229
+ opt.lineWidth = ls.width;
230
+ }
231
+ if (style.polyStyle)
232
+ {
233
+ let ps = style.polyStyle;
234
+ if (ps.color)
235
+ opt.fillColor = ps.color;
236
+ }
237
+ }
238
+ }
239
+ let layer = createFromGeometry(feature.vec, opt);
240
+ if (layer)
241
+ {
242
+ if (feature.name)
243
+ layer.name = feature.name;
244
+ if (feature.description)
245
+ layer.description = feature.description;
246
+ }
247
+ return layer;
248
+ }
249
+ else
250
+ {
251
+ console.log("Unknown KML feature type", feature);
252
+ return null;
253
+ }
254
+ }
255
+
256
+ export function createFromGeometry(geom, options)
257
+ {
258
+ if (geom instanceof geometry.Point)
259
+ {
260
+ let opt = {};
261
+ if (options)
262
+ {
263
+ if (options.name)
264
+ opt.title = options.name;
265
+ if (options.iconUrl)
266
+ opt.image = options.iconUrl;
267
+ if (options.horizontalOrigin)
268
+ opt.horizontalOrigin = options.horizontalOrigin;
269
+ if (options.verticalOrigin)
270
+ opt.verticalOrigin = options.verticalOrigin;
271
+ }
272
+ return new Cesium.Entity({
273
+ position: Cesium.Cartesian3.fromDegrees(geom.coordinates[0], geom.coordinates[1]),
274
+ billboard: new Cesium.BillboardGraphics(opt)});
275
+ }
276
+ else if (geom instanceof geometry.LineString)
277
+ {
278
+ let opt = {};
279
+ if (options.lineColor)
280
+ {
281
+ let c = kml.toColor(options.lineColor);
282
+ opt.material = new Cesium.Color(c.r, c.g, c.b, c.a);
283
+ }
284
+ if (options.lineWidth)
285
+ opt.width = options.lineWidth;
286
+ opt.positions = toCartesian3Arr(geom.coordinates);
287
+ return new Cesium.Entity({polyline: new Cesium.PolylineGraphics(opt)});
288
+ }
289
+ else if (geom instanceof geometry.Polygon)
290
+ {
291
+ let opt = {};
292
+ opt.heightReference = Cesium.HeightReference.CLAMP_TO_GROUND;
293
+ opt.height = 0;
294
+ if (options.lineColor)
295
+ {
296
+ let c = kml.toColor(options.lineColor);
297
+ opt.outlineColor = new Cesium.Color(c.r, c.g, c.b, c.a);
298
+ opt.outline = true;
299
+ }
300
+ if (options.lineWidth)
301
+ {
302
+ opt.outlineWidth = options.lineWidth;
303
+ opt.outline = true;
304
+ }
305
+ if (options.fillColor)
306
+ {
307
+ let c = kml.toColor(options.fillColor);
308
+ opt.material = new Cesium.Color(c.r, c.g, c.b, c.a);
309
+ }
310
+ opt.hierarchy = {positions: toCartesian3Arr(geom.geometries[0].coordinates), holes: []};
311
+ let i = 1;
312
+ let j = geom.geometries.length;
313
+ while (i < j)
314
+ {
315
+ opt.hierarchy.holes.push({positions: toCartesian3Arr(geom.geometries[i].coordinates)});
316
+ i++;
317
+ }
318
+ return new Cesium.Entity({polygon: new Cesium.PolygonGraphics(opt)});
319
+ }
320
+ else if (geom instanceof geometry.MultiPolygon)
321
+ {
322
+ if (geom.geometries.length == 1)
323
+ {
324
+ return createFromGeometry(geom.geometries[0], options);
325
+ }
326
+ let opt = {};
327
+ if (options.lineColor)
328
+ {
329
+ let c = kml.toColor(options.lineColor);
330
+ opt.outlineColor = new Cesium.Color(c.r, c.g, c.b, c.a);
331
+ opt.outline = true;
332
+ }
333
+ if (options.lineWidth)
334
+ {
335
+ opt.outlineWidth = options.lineWidth;
336
+ opt.outline = true;
337
+ }
338
+ if (options.fillColor)
339
+ {
340
+ let c = kml.toColor(options.fillColor);
341
+ opt.material = new Cesium.Color(c.r, c.g, c.b, c.a);
342
+ }
343
+ console.log("MultiPolygon not supported", geom);
344
+ return null;
345
+ }
346
+ else
347
+ {
348
+ console.log("Unknown geometry type", geom);
349
+ return null;
350
+ }
153
351
  }
154
352
 
155
353
  /*export function createPolygon(viewer, lats, lons, height)
@@ -162,11 +360,11 @@ export function fromPolygonGraphics(viewer, pg)
162
360
  {
163
361
  height = 0;
164
362
  }
165
- var ellipsoid = viewer.scene.globe.ellipsoid;
166
- var o = new Object();
363
+ let ellipsoid = viewer.scene.globe.ellipsoid;
364
+ let o = new Object();
167
365
  o.positions = new Array();
168
- var i = 0;
169
- var j = lats.length;
366
+ let i = 0;
367
+ let j = lats.length;
170
368
  while (i < j)
171
369
  {
172
370
  o.positions.push(ellipsoid.cartographicToCartesian(new Cesium.Cartographic(lons[i] * Math.PI / 180, lats[i] * Math.PI / 180, height)));
@@ -174,7 +372,7 @@ export function fromPolygonGraphics(viewer, pg)
174
372
  }
175
373
  o.positions.push(ellipsoid.cartographicToCartesian(new Cesium.Cartographic(lons[0] * Math.PI / 180, lats[0] * Math.PI / 180, height)));
176
374
 
177
- var pg = new Cesium.PolygonGraphics(o);
375
+ let pg = new Cesium.PolygonGraphics(o);
178
376
  return pg;
179
377
  }*/
180
378
 
@@ -198,13 +396,13 @@ export class CesiumMap extends map.MapControl
198
396
  {
199
397
  if (layer.type == map.WebMapType.OSMTile)
200
398
  {
201
- var opt = {};
202
- if (options && options.maxZoom)
399
+ let opt = {};
400
+ if (layer.maxZoom)
203
401
  {
204
- opt.maximumLevel = options.maxZoom;
402
+ opt.maximumLevel = layer.maxZoom;
205
403
  }
206
- return new Cesium.ImageryLayer(new Cesium.UrlTemplateImageryProvider({
207
- url: layer.url}, opt));
404
+ opt.url = layer.url;
405
+ return new Cesium.ImageryLayer(new Cesium.UrlTemplateImageryProvider(opt));
208
406
  }
209
407
  }
210
408
 
@@ -216,6 +414,27 @@ export class CesiumMap extends map.MapControl
216
414
  {
217
415
  this.viewer.imageryLayers.add(layer);
218
416
  }
417
+ else if (layer instanceof Cesium.Entity)
418
+ {
419
+ this.viewer.entities.add(layer);
420
+ }
421
+ else if (data.isArray(layer))
422
+ {
423
+ let i;
424
+ for (i in layer)
425
+ {
426
+ this.addLayer(layer[i]);
427
+ }
428
+ }
429
+ else
430
+ {
431
+ console.log("Unknown type to add", layer);
432
+ }
433
+ }
434
+
435
+ addKMLFeature(feature)
436
+ {
437
+ this.addLayer(createFromKMLFeature(feature));
219
438
  }
220
439
 
221
440
  // uninit(): void;
package/data.d.ts CHANGED
@@ -5,6 +5,12 @@ export function arrayBuffer2Base64(buff: any): string;
5
5
  export function compare(a: any, b: any): number;
6
6
  export function sort(arr: object[], compareFunc?: (val1: object, val2: object) => number, firstIndex?: number, lastIndex?: number): void;
7
7
  export function mergeOptions(options: object | null, defOptions: object): object;
8
+ export function readUInt16(arr: Uint8Array, index: number): number;
9
+ export function readMUInt16(arr: Uint8Array, index: number): number;
10
+ export function readUInt24(arr: Uint8Array, index: number): number;
11
+ export function readMUInt24(arr: Uint8Array, index: number): number;
12
+ export function readUInt32(arr: Uint8Array, index: number): number;
13
+ export function readMUInt32(arr: Uint8Array, index: number): number;
8
14
 
9
15
  export class DateValue
10
16
  {