@sswroom/sswr 1.4.1 → 1.5.1

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/leaflet.js CHANGED
@@ -3,6 +3,8 @@ import * as geometry from "./geometry.js";
3
3
  import * as kml from "./kml.js";
4
4
  import * as math from "./math.js";
5
5
  import * as map from "./map.js";
6
+ import * as osm from "./osm.js";
7
+ import * as text from "./text.js";
6
8
  import * as web from "./web.js";
7
9
 
8
10
  export function fromLatLon(latLon)
@@ -51,6 +53,130 @@ export function createLayer(layer, options)
51
53
  return null;
52
54
  }
53
55
 
56
+ export function createFromKMLFeature(feature, options)
57
+ {
58
+ options = data.mergeOptions(options, {noPopup: false});
59
+ if (feature instanceof kml.Container)
60
+ {
61
+ var i;
62
+ var layers = L.featureGroup();
63
+ for (i in feature.features)
64
+ {
65
+ createFromKMLFeature(feature.features[i], options).addTo(layers);
66
+ }
67
+ return layers;
68
+ }
69
+ else if (feature instanceof kml.Placemark)
70
+ {
71
+ var opt = {};
72
+ if (feature.name)
73
+ opt.name = feature.name;
74
+ if (feature.style)
75
+ {
76
+ var style = feature.style;
77
+ if (style instanceof kml.StyleMap)
78
+ {
79
+ style = style.normalStyle;
80
+ }
81
+ if (style instanceof kml.Style)
82
+ {
83
+ if (style.iconStyle)
84
+ {
85
+ var s = style.iconStyle;
86
+ if (s.leafletIcon == null)
87
+ {
88
+ var icon = {};
89
+ if (s.iconUrl)
90
+ {
91
+ icon.iconUrl = s.iconUrl;
92
+ }
93
+ if (s.hotSpotX && s.hotSpotY)
94
+ {
95
+ icon.iconAnchor = [s.hotSpotX, s.hotSpotY];
96
+ }
97
+ s.leafletIcon = L.icon(icon);
98
+ }
99
+ opt.icon = s.leafletIcon;
100
+ }
101
+ if (style.lineStyle)
102
+ {
103
+ var ls = style.lineStyle;
104
+ if (ls.color)
105
+ opt.lineColor = kml.toCSSColor(ls.color);
106
+ if (ls.width)
107
+ opt.lineWidth = ls.width;
108
+ }
109
+ }
110
+ }
111
+ var layer = createFromGeometry(feature.vec, opt);
112
+ if (layer && !options.noPopup)
113
+ {
114
+ if (feature.name && feature.description)
115
+ {
116
+ layer.bindPopup("<b>"+text.toHTMLText(feature.name)+"</b><br/>"+feature.description);
117
+ }
118
+ else if (feature.name)
119
+ {
120
+ layer.bindPopup("<b>"+text.toHTMLText(feature.name)+"</b>");
121
+ }
122
+ else if (feature.description)
123
+ {
124
+ layer.bindPopup(feature.description);
125
+ }
126
+ }
127
+ return layer;
128
+ }
129
+ else
130
+ {
131
+ console.log("Unknown KML feature type", feature);
132
+ return null;
133
+ }
134
+ }
135
+
136
+ export function createFromGeometry(geom, options)
137
+ {
138
+ if (geom instanceof geometry.Point)
139
+ {
140
+ var opt = {};
141
+ if (options)
142
+ {
143
+ if (options.name)
144
+ opt.title = options.name;
145
+ if (options.icon)
146
+ opt.icon = options.icon;
147
+ }
148
+ return L.marker(L.latLng(geom.coordinates[1], geom.coordinates[0]), opt);
149
+ }
150
+ else if (geom instanceof geometry.LineString)
151
+ {
152
+ var opt = {};
153
+ var i;
154
+ var pts = [];
155
+ if (options.lineColor)
156
+ opt.color = options.lineColor;
157
+ if (options.lineWidth)
158
+ opt.weight = options.lineWidth;
159
+ for (i in geom.coordinates)
160
+ {
161
+ var latLng = L.latLng(geom.coordinates[i][1], geom.coordinates[i][0]);
162
+ if (latLng)
163
+ {
164
+ pts.push(latLng);
165
+ }
166
+ else
167
+ {
168
+ console.log("Error in LineString", geom.coordinates[i]);
169
+ }
170
+ }
171
+ return L.polyline(pts, opt);
172
+ }
173
+ else
174
+ {
175
+ console.log("Unknown geometry type", geom);
176
+ return null;
177
+ }
178
+ }
179
+
54
180
  export function createKMLLookAt(map)
55
181
  {
56
182
  var center = map.getCenter();
@@ -119,6 +245,36 @@ export function toKMLFeature(layer, doc)
119
245
  {
120
246
  feature.setDescription(layer._popup._content);
121
247
  }
248
+ if (layer.options && layer.options.icon)
249
+ {
250
+ var opt = layer.options.icon.options;
251
+ if (opt)
252
+ {
253
+ var imgW = layer._icon.naturalWidth || layer._icon.offsetWidth;
254
+ var iconStyle = new kml.IconStyle();
255
+ if (opt.iconSize)
256
+ {
257
+ iconStyle.setScale(opt.iconSize[0] / imgW);
258
+ if (opt.iconAnchor)
259
+ {
260
+ iconStyle.setHotSpotX(opt.iconAnchor[0], kml.HotSpotUnit.Pixels);
261
+ iconStyle.setHotSpotY(opt.iconAnchor[1], kml.HotSpotUnit.InsetPixels);
262
+ }
263
+ }
264
+ if (opt.iconUrl)
265
+ {
266
+ if (opt.iconUrl == "marker-icon.png")
267
+ {
268
+ iconStyle.setIconUrl(web.appendUrl("../../leaflet/dist/images/marker-icon.png", import.meta.url));
269
+ }
270
+ else
271
+ {
272
+ iconStyle.setIconUrl(web.appendUrl(opt.iconUrl, document.location.href));
273
+ }
274
+ }
275
+ feature.setStyle(doc.getOrNewStyle(iconStyle, null, null, null, null, null));
276
+ }
277
+ }
122
278
  return feature;
123
279
  }
124
280
  else if (layer instanceof L.Polyline)
@@ -158,4 +314,76 @@ export function toKMLString(layer)
158
314
  return kml.toString(feature);
159
315
  }
160
316
  return null;
161
- }
317
+ }
318
+
319
+ export class LeafletMap extends map.MapControl
320
+ {
321
+ constructor(divId)
322
+ {
323
+ super();
324
+ this.mapObj = L.map(divId);
325
+ }
326
+
327
+ createLayer(layer, options)
328
+ {
329
+ return createLayer(layer, options);
330
+ }
331
+
332
+ // createMarkerLayer(name: string, options?: LayerOptions): any;
333
+ // createGeometryLayer(name: string, options?: LayerOptions): any;
334
+
335
+ addLayer(layer)
336
+ {
337
+ layer.addTo(this.mapObj);
338
+ }
339
+
340
+ addKMLFeature(feature)
341
+ {
342
+ createFromKMLFeature(feature).addTo(this.mapObj);
343
+ }
344
+
345
+ // uninit(): void;
346
+ zoomIn()
347
+ {
348
+ this.mapObj.zoomIn();
349
+ }
350
+
351
+ zoomOut()
352
+ {
353
+ this.mapObj.zoomOut();
354
+ }
355
+
356
+ zoomScale(scale)
357
+ {
358
+ this.mapObj.setZoom(osm.scale2Level(scale));
359
+ }
360
+
361
+ panTo(pos)
362
+ {
363
+ this.mapObj.setView(L.latLng(pos.y, pos.x));
364
+ }
365
+
366
+ panZoomScale(pos, scale)
367
+ {
368
+ this.mapObj.setView(L.latLng(pos.y, pos.x), osm.scale2Level(scale));
369
+ }
370
+
371
+ //zoomToExtent(extent: math.RectArea): void;
372
+
373
+ /* handleMouseLClick(clickFunc: (mapPos: math.Coord2D, scnPos: math.Coord2D)=>void): void;
374
+ handleMouseMove(moveFunc: (mapPos: math.Coord2D)=>void): void;
375
+ handlePosChange(posFunc: (mapPos: math.Coord2D)=>void): void;
376
+ map2ScnPos(mapPos: math.Coord2D): math.Coord2D;
377
+ scn2MapPos(scnPos: math.Coord2D): math.Coord2D;
378
+
379
+ createMarker(mapPos: math.Coord2D, imgURL: string, imgWidth: number, imgHeight: number, options?: MarkerOptions): any;
380
+ layerAddMarker(markerLayer: any, marker: any): void;
381
+ layerRemoveMarker(markerLayer: any, marker: any): void;
382
+ layerClearMarkers(markerLayer: any): void;
383
+ markerIsOver(marker: any, scnPos: math.Coord2D): boolean;
384
+
385
+ createGeometry(geom: geometry.Vector2D, options: GeometryOptions): any;
386
+ layerAddGeometry(geometryLayer: any, geom: any): void;
387
+ layerRemoveGeometry(geometryLayer: any, geom: any): void;
388
+ layerClearGeometries(geometryLayer: any): void;*/
389
+ }
package/map.d.ts CHANGED
@@ -131,7 +131,8 @@ export class MapControl
131
131
  createLayer(layer: map.LayerInfo, options?: LayerOptions): any;
132
132
  createMarkerLayer(name: string, options?: LayerOptions): any;
133
133
  createGeometryLayer(name: string, options?: LayerOptions): any;
134
- addLayer(layer: any);
134
+ addLayer(layer: any): void;
135
+ addKMLFeature(feature: kml.Feature): void;
135
136
  uninit(): void;
136
137
  zoomIn(): void;
137
138
  zoomOut(): void;
package/map.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as geometry from "./geometry.js";
2
2
  import * as math from "./math.js";
3
3
  import * as web from "./web.js";
4
- import { DistanceUnit } from "./unit.js";
4
+ import * as unit from "./unit.js";
5
5
 
6
6
  export const DataFormat = {
7
7
  Cesium: "cesium",
@@ -35,7 +35,7 @@ export function calcDistance(srid, geom, x, y)
35
35
  {
36
36
  var pt = geom.calBoundaryPoint(new math.Coord2D(x, y));
37
37
  var csys = math.CoordinateSystemManager.srCreateCsys(srid);
38
- return csys.calcSurfaceDistance(x, y, pt.x, pt.y, DistanceUnit.METER);
38
+ return csys.calcSurfaceDistance(x, y, pt.x, pt.y, unit.Distance.Unit.METER);
39
39
  }
40
40
 
41
41
  export function getLayers(svcUrl, onResultFunc)
@@ -134,7 +134,7 @@ export class GeolocationFilter
134
134
  }
135
135
  if (this.minDistMeter)
136
136
  {
137
- if (this.csys.calcSurfaceDistance(pos.coords.longitude, pos.coords.latitude, this.lastPos.longitude, this.lastPos.latitude, DistanceUnit.METER) < this.minDistMeter)
137
+ if (this.csys.calcSurfaceDistance(pos.coords.longitude, pos.coords.latitude, this.lastPos.longitude, this.lastPos.latitude, unit.Distance.Unit.METER) < this.minDistMeter)
138
138
  return false;
139
139
  }
140
140
 
package/math.js CHANGED
@@ -250,9 +250,9 @@ export class EarthEllipsoid
250
250
  var d = Math.acos(cLat1 * Math.cos(rLon1) * cLat2 * Math.cos(rLon2) + cLat1 * Math.sin(rLon1) * cLat2 * Math.sin(rLon2) + Math.sin(rLat1) * Math.sin(rLat2)) * r;
251
251
  if (d > 0 || d < 0)
252
252
  {
253
- if (distUnit != null && distUnit != unit.DistanceUnit.METER)
253
+ if (distUnit != null && distUnit != unit.Distance.Unit.METER)
254
254
  {
255
- d = unit.Distance.convert(unit.DistanceUnit.METER, distUnit, d);
255
+ d = unit.Distance.convert(unit.Distance.Unit.METER, distUnit, d);
256
256
  }
257
257
  }
258
258
  else if (d != 0)
@@ -472,7 +472,7 @@ export class DatumData
472
472
  this.yAngle = yAngle * aratio;
473
473
  this.zAngle = zAngle * aratio;
474
474
  this.scale = scale;
475
- this.aunit = unit.AngleUnit.RADIAN;
475
+ this.aunit = unit.Angle.Unit.RADIAN;
476
476
  }
477
477
  }
478
478
 
@@ -740,9 +740,9 @@ export class ProjectedCoordinateSystem extends CoordinateSystem
740
740
  diffX = diffX * diffX;
741
741
  diffY = diffY * diffY;
742
742
  var d = Math.sqrt(diffX + diffY);
743
- if (distUnit != unit.DistanceUnit.METER)
743
+ if (distUnit != unit.Distance.Unit.METER)
744
744
  {
745
- d = unit.Distance.convert(unit.DistanceUnit.METER, distUnit, d);
745
+ d = unit.Distance.convert(unit.Distance.Unit.METER, distUnit, d);
746
746
  }
747
747
  return d;
748
748
  }
@@ -1014,17 +1014,17 @@ export class CoordinateSystemManager
1014
1014
  switch (srid)
1015
1015
  {
1016
1016
  case 6326:
1017
- return new DatumData(6326, this.srGetSpheroid(7030), "WGS_1984", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, unit.AngleUnit.RADIAN);
1017
+ return new DatumData(6326, this.srGetSpheroid(7030), "WGS_1984", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, unit.Angle.Unit.RADIAN);
1018
1018
  case 6600:
1019
- return new DatumData(6600, this.srGetSpheroid(7012), "Anguilla_1957", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, unit.AngleUnit.RADIAN);
1019
+ return new DatumData(6600, this.srGetSpheroid(7012), "Anguilla_1957", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, unit.Angle.Unit.RADIAN);
1020
1020
  case 6601:
1021
- return new DatumData(6601, this.srGetSpheroid(7012), "Antigua_1943", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, unit.AngleUnit.RADIAN);
1021
+ return new DatumData(6601, this.srGetSpheroid(7012), "Antigua_1943", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, unit.Angle.Unit.RADIAN);
1022
1022
  case 6602:
1023
- return new DatumData(6602, this.srGetSpheroid(7012), "Dominica_1945", 0, 0, 0, 725, 685, 536, 0, 0, 0, 0, unit.AngleUnit.ARCSECOND);
1023
+ return new DatumData(6602, this.srGetSpheroid(7012), "Dominica_1945", 0, 0, 0, 725, 685, 536, 0, 0, 0, 0, unit.Angle.Unit.ARCSECOND);
1024
1024
  case 6603:
1025
- return new DatumData(6603, this.srGetSpheroid(7012), "Grenada_1953", 0, 0, 0, 72, 213.7, 93, 0, 0, 0, 0, unit.AngleUnit.ARCSECOND);
1025
+ return new DatumData(6603, this.srGetSpheroid(7012), "Grenada_1953", 0, 0, 0, 72, 213.7, 93, 0, 0, 0, 0, unit.Angle.Unit.ARCSECOND);
1026
1026
  case 6611:
1027
- return new DatumData(6611, this.srGetSpheroid(7022), "Hong_Kong_1980", 0, 0, 0, -162.619, -276.959, -161.764, 0.067753, -2.24365, -1.15883, -1.09425, unit.AngleUnit.ARCSECOND);
1027
+ return new DatumData(6611, this.srGetSpheroid(7022), "Hong_Kong_1980", 0, 0, 0, -162.619, -276.959, -161.764, 0.067753, -2.24365, -1.15883, -1.09425, unit.Angle.Unit.ARCSECOND);
1028
1028
  }
1029
1029
  return null;
1030
1030
  }
package/olayer2.d.ts CHANGED
@@ -21,7 +21,8 @@ export class Olayer2Map extends map.MapControl
21
21
  createLayer(layer: map.LayerInfo, options?: LayerOptions): any;
22
22
  createMarkerLayer(name: string, options?: LayerOptions): any;
23
23
  createGeometryLayer(name: string, options?: LayerOptions): any;
24
- addLayer(layer: any);
24
+ addLayer(layer: any): void;
25
+ addKMLFeature(feature: kml.Feature): void;
25
26
  uninit(): void;
26
27
  zoomIn(): void;
27
28
  zoomOut(): void;
package/olayer2.js CHANGED
@@ -104,6 +104,11 @@ export class Olayer2Map extends map.MapControl
104
104
  }
105
105
  }
106
106
 
107
+ addKMLFeature(feature)
108
+ {
109
+ ///////////////////////////////
110
+ }
111
+
107
112
  uninit()
108
113
  {
109
114
  this.map.destroy();
package/osm.d.ts CHANGED
@@ -6,3 +6,4 @@ export function pixelX2Lon(x: number, level: number, tileSize: number): number;
6
6
  export function pixelY2Lat(y: number, level: number, tileSize: number): number;
7
7
  export function tileUrls(osmUrl: string, minCoord: math.Coord2D, maxCoord: math.Coord2D, minLev: number, maxLev: number): string[];
8
8
  export function removeTileUrls(urls: string[], osmUrl: string, minLev: number, maxLev: number, areaList: math.RectArea[]): void;
9
+ export function scale2Level(scale: number): number;
package/osm.js CHANGED
@@ -104,3 +104,8 @@ export function removeTileUrls(urls, osmUrl, minLev, maxLev, areaList)
104
104
  urls.push(i);
105
105
  }
106
106
  }
107
+
108
+ export function scale2Level(scale)
109
+ {
110
+ return Math.round(Math.log10(204094080000.0 / scale / 256) / Math.log10(2));
111
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sswroom/sswr",
3
- "version": "1.4.1",
3
+ "version": "1.5.1",
4
4
  "description": "Libraries made by sswroom",
5
5
  "main": "sswr.js",
6
6
  "scripts": {
package/parser.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import * as kml from "./kml";
2
+
3
+ export function parseXML(txt: string): kml.Feature | kml.NetworkLinkControl | null;
4
+ export function parseFile(file: File): Promise<kml.Feature | kml.NetworkLinkControl | null>;