@sswroom/sswr 1.6.10 → 1.6.12

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/olayer2.js CHANGED
@@ -6,6 +6,7 @@ import * as math from "./math.js";
6
6
  import * as osm from "./osm.js";
7
7
  import * as text from "./text.js";
8
8
  import * as web from "./web.js";
9
+ import OpenLayers from "./dummy/olayer2.js";
9
10
 
10
11
  export function toPointArray(numArr, options)
11
12
  {
@@ -55,6 +56,7 @@ export async function createFromKML(feature, options)
55
56
  }
56
57
  else if (feature instanceof kml.Placemark)
57
58
  {
59
+ /** @type {{objProjection?: OpenLayers.Projection, mapProjection?: OpenLayers.Projection, name?: string, iconUrl?: string, iconOffset?: OpenLayers.Pixel, strokeColor?: string, strokeWidth?: number, stroke?: boolean, fillColor?: string, fill?: boolean}} */
58
60
  let opt = {objProjection: options.objProjection, mapProjection: options.mapProjection};
59
61
  if (feature.name)
60
62
  opt.name = feature.name;
@@ -148,6 +150,11 @@ export async function createFromKML(feature, options)
148
150
  }
149
151
  }
150
152
 
153
+ /**
154
+ * @param {geometry.Vector2D} geom
155
+ * @param {{ objProjection?: OpenLayers.Projection; mapProjection?: OpenLayers.Projection; iconUrl?: string; iconOffset?: OpenLayers.Pixel; } | null} options
156
+ * @returns {Promise<OpenLayers.Geometry|OpenLayers.Marker|null>}
157
+ */
151
158
  export async function createFromGeometry(geom, options)
152
159
  {
153
160
  if (options == null)
@@ -158,6 +165,11 @@ export async function createFromGeometry(geom, options)
158
165
  if (geom instanceof geometry.Point)
159
166
  {
160
167
  let icon;
168
+ let lonLat = new OpenLayers.LonLat(geom.coordinates[0], geom.coordinates[1]);
169
+ if (options.objProjection && options.mapProjection)
170
+ {
171
+ lonLat = lonLat.transform(options.objProjection, options.mapProjection);
172
+ }
161
173
  if (options.iconUrl && options.iconOffset)
162
174
  {
163
175
  let size = await web.getImageInfo(options.iconUrl);
@@ -167,11 +179,10 @@ export async function createFromGeometry(geom, options)
167
179
  return null;
168
180
  }
169
181
  icon = new OpenLayers.Icon(options.iconUrl, new OpenLayers.Size(size.width, size.height), options.iconOffset);
170
- return new OpenLayers.Marker(new OpenLayers.LonLat(geom.coordinates[0], geom.coordinates[1]).transform(options.objProjection, options.mapProjection), icon);
182
+ return new OpenLayers.Marker(lonLat, icon);
171
183
  }
172
184
  else
173
185
  {
174
- let lonLat = new OpenLayers.LonLat(geom.coordinates[0], geom.coordinates[1]).transform(options.objProjection, options.mapProjection);
175
186
  return new OpenLayers.Geometry.Point(lonLat.lon, lonLat.lat);
176
187
  }
177
188
  }
@@ -189,7 +200,9 @@ export async function createFromGeometry(geom, options)
189
200
  let i;
190
201
  for (i in geom.geometries)
191
202
  {
192
- lrList.push(await createFromGeometry(geom.geometries[i], options));
203
+ let lr = await createFromGeometry(geom.geometries[i], options);
204
+ if (lr instanceof OpenLayers.Geometry.LinearRing)
205
+ lrList.push(lr);
193
206
  }
194
207
  return new OpenLayers.Geometry.Polygon(lrList);
195
208
  }
@@ -199,7 +212,9 @@ export async function createFromGeometry(geom, options)
199
212
  let i;
200
213
  for (i in geom.geometries)
201
214
  {
202
- pgList.push(await createFromGeometry(geom.geometries[i], options));
215
+ let pg = await createFromGeometry(geom.geometries[i], options);
216
+ if (pg instanceof OpenLayers.Geometry.Polygon)
217
+ pgList.push(pg);
203
218
  }
204
219
  return new OpenLayers.Geometry.MultiPolygon(pgList);
205
220
  }
@@ -221,8 +236,11 @@ export class Olayer2Map extends map.MapControl
221
236
  this.initLev = 12;
222
237
  this.mapId = mapId;
223
238
  let dom = document.getElementById(mapId);
224
- dom.style.minWidth = '1px';
225
- dom.style.minHeight = '1px';
239
+ if (dom)
240
+ {
241
+ dom.style.minWidth = '1px';
242
+ dom.style.minHeight = '1px';
243
+ }
226
244
  this.mapProjection = new OpenLayers.Projection("EPSG:4326");
227
245
  this.map = new OpenLayers.Map(this.mapId, {
228
246
  eventListeners: {
@@ -270,6 +288,10 @@ export class Olayer2Map extends map.MapControl
270
288
  this.currMarkerPopupObj = null;
271
289
  }
272
290
 
291
+ /**
292
+ * @param {map.LayerInfo} layer
293
+ * @param {object} options
294
+ */
273
295
  createLayer(layer, options)
274
296
  {
275
297
  if (layer.type == map.WebMapType.OSMTile)
@@ -548,7 +570,7 @@ export class Olayer2Map extends map.MapControl
548
570
  let pos = new OpenLayers.LonLat(lr.coordinates[j][0], lr.coordinates[j][1]).transform(this.mapProjection, this.map.getProjectionObject());
549
571
  points.push(new OpenLayers.Geometry.Point(pos.lon, pos.lat));
550
572
  }
551
- lrArr.push(new OpenLayers.Geometry.LineString(points));
573
+ lrArr.push(new OpenLayers.Geometry.LinearRing(points));
552
574
  }
553
575
  return new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Polygon(lrArr), null, opt);
554
576
  }
@@ -571,7 +593,7 @@ export class Olayer2Map extends map.MapControl
571
593
  let pos = new OpenLayers.LonLat(lr.coordinates[k][0], lr.coordinates[k][1]).transform(this.mapProjection, this.map.getProjectionObject());
572
594
  points.push(new OpenLayers.Geometry.Point(pos.lon, pos.lat));
573
595
  }
574
- lrArr.push(new OpenLayers.Geometry.LineString(points));
596
+ lrArr.push(new OpenLayers.Geometry.LinearRing(points));
575
597
  }
576
598
  pgArr.push(new OpenLayers.Geometry.Polygon(lrArr));
577
599
  }
@@ -674,7 +696,7 @@ export class Olayer2Map extends map.MapControl
674
696
  let polyStyle = null;
675
697
  if (layer.style)
676
698
  {
677
- if (layer.style.stroke)
699
+ if (layer.style.stroke && layer.style.strokeColor)
678
700
  {
679
701
  let c = web.parseCSSColor(layer.style.strokeColor);
680
702
  lineStyle = new kml.LineStyle();
@@ -682,7 +704,7 @@ export class Olayer2Map extends map.MapControl
682
704
  if (layer.style.strokeWidth)
683
705
  lineStyle.setWidth(layer.style.strokeWidth)
684
706
  }
685
- if (layer.style.fill)
707
+ if (layer.style.fill && layer.style.fillColor)
686
708
  {
687
709
  let c = web.parseCSSColor(layer.style.fillColor);
688
710
  if (layer.style.fillOpacity)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sswroom/sswr",
3
- "version": "1.6.10",
3
+ "version": "1.6.12",
4
4
  "description": "Libraries made by sswroom",
5
5
  "main": "sswr.js",
6
6
  "scripts": {
package/text.d.ts CHANGED
@@ -35,6 +35,8 @@ export function charIsUpperCase(s: string, index: number): boolean;
35
35
  export function charIsLowerCase(s: string, index: number): boolean;
36
36
  export function replaceAll(s: string, replaceFrom: string, replaceTo: string): string;
37
37
  export function getEncList(): TextBinEnc[];
38
+ export function b64Enc(s: string, cs?: Base64Charset): string;
39
+ export function b64Dec(b64Str: string): string;
38
40
 
39
41
  export class TextBinEnc
40
42
  {
package/text.js CHANGED
@@ -577,6 +577,29 @@ export function getEncList()
577
577
  return ret;
578
578
  }
579
579
 
580
+ /**
581
+ * @param {string} s
582
+ * @param {number|undefined} cs
583
+ * @returns {string}
584
+ */
585
+ export function b64Enc(s, cs)
586
+ {
587
+ let b64 = new Base64Enc(cs, false);
588
+ let enc = new TextEncoder();
589
+ return b64.encodeBin(enc.encode(s));
590
+ }
591
+
592
+ /**
593
+ * @param {string} b64Str
594
+ * @returns {string}
595
+ */
596
+ export function b64Dec(b64Str)
597
+ {
598
+ let b64 = new Base64Enc();
599
+ let dec = new TextDecoder();
600
+ return dec.decode(b64.decodeBin(b64Str));
601
+ }
602
+
580
603
  export class TextBinEnc
581
604
  {
582
605
  constructor(name)
package/web.d.ts CHANGED
@@ -110,9 +110,11 @@ export function mimeFromExt(ext: string): string;
110
110
  export function getImageInfo(url: string): Promise<ImageInfo|null>;
111
111
  export function propertiesToHTML(prop: object, nameMap?: object, timeFormat?: string): string;
112
112
  export function getCacheSize(name: string): Promise<number>;
113
- export function getInputOrSelectElement(id: string): HTMLInputElement|HTMLSelectElement;
114
113
  export function getInputElement(id: string): HTMLInputElement;
115
114
  export function getSelectElement(id: string): HTMLSelectElement;
115
+ export function getButtonElement(id: string): HTMLButtonElement;
116
+ export function getDivElement(id: string): HTMLDivElement;
117
+ export function getSpanElement(id: string): HTMLSpanElement;
116
118
  export function getBrowserInfo(): Promise<BrowserInfo>;
117
119
  export function parseUserAgent(userAgent: string): BrowserInfo;
118
120
 
package/web.js CHANGED
@@ -149,7 +149,14 @@ export function buildTable(o)
149
149
  ret.push("<tr>");
150
150
  for (name in o[0])
151
151
  {
152
- ret.push("<td>"+text.toHTMLText(""+obj[name])+"</td>");
152
+ if (typeof obj[name] == "object")
153
+ {
154
+ ret.push("<td>"+text.toHTMLText(JSON.stringify(obj[name]))+"</td>");
155
+ }
156
+ else
157
+ {
158
+ ret.push("<td>"+text.toHTMLText(""+obj[name])+"</td>");
159
+ }
153
160
  }
154
161
  ret.push("</tr>");
155
162
  i++;
@@ -161,7 +168,14 @@ export function buildTable(o)
161
168
  {
162
169
  ret.push("<tr>");
163
170
  ret.push("<td>"+text.toHTMLText(name)+"</td>");
164
- ret.push("<td>"+text.toHTMLText(""+o[name])+"</td>");
171
+ if (typeof o[name] == "object")
172
+ {
173
+ ret.push("<td>"+text.toHTMLText(JSON.stringify(o[name]))+"</td>");
174
+ }
175
+ else
176
+ {
177
+ ret.push("<td>"+text.toHTMLText(""+o[name])+"</td>");
178
+ }
165
179
  ret.push("</tr>");
166
180
  }
167
181
  }
@@ -924,46 +938,72 @@ export async function getCacheSize(name)
924
938
 
925
939
  /**
926
940
  * @param {string} id
927
- * @returns {HTMLInputElement|HTMLSelectElement}
941
+ * @returns {HTMLInputElement}
928
942
  */
929
- export function getInputOrSelectElement(id)
943
+ export function getInputElement(id)
930
944
  {
931
945
  let ele = document.getElementById(id);
932
946
  if (ele == null)
933
947
  throw new Error("Element with id \""+id+"\" not found");
934
948
  if (ele instanceof HTMLInputElement)
935
949
  return ele;
950
+ throw new Error("Element with id \""+id+"\" is not an input");
951
+ }
952
+
953
+ /**
954
+ * @param {string} id
955
+ * @returns {HTMLSelectElement}
956
+ */
957
+ export function getSelectElement(id)
958
+ {
959
+ let ele = document.getElementById(id);
960
+ if (ele == null)
961
+ throw new Error("Element with id \""+id+"\" not found");
936
962
  if (ele instanceof HTMLSelectElement)
937
963
  return ele;
938
- throw new Error("Element with id \""+id+"\" is not an input");
964
+ throw new Error("Element with id \""+id+"\" is not a select");
939
965
  }
940
966
 
941
967
  /**
942
968
  * @param {string} id
943
- * @returns {HTMLInputElement}
969
+ * @returns {HTMLButtonElement}
944
970
  */
945
- export function getInputElement(id)
971
+ export function getButtonElement(id)
946
972
  {
947
973
  let ele = document.getElementById(id);
948
974
  if (ele == null)
949
975
  throw new Error("Element with id \""+id+"\" not found");
950
- if (ele instanceof HTMLInputElement)
976
+ if (ele instanceof HTMLButtonElement)
951
977
  return ele;
952
- throw new Error("Element with id \""+id+"\" is not an input");
978
+ throw new Error("Element with id \""+id+"\" is not a button");
953
979
  }
954
980
 
955
981
  /**
956
982
  * @param {string} id
957
- * @returns {HTMLSelectElement}
983
+ * @returns {HTMLDivElement}
958
984
  */
959
- export function getSelectElement(id)
985
+ export function getDivElement(id)
960
986
  {
961
987
  let ele = document.getElementById(id);
962
988
  if (ele == null)
963
989
  throw new Error("Element with id \""+id+"\" not found");
964
- if (ele instanceof HTMLSelectElement)
990
+ if (ele instanceof HTMLDivElement)
965
991
  return ele;
966
- throw new Error("Element with id \""+id+"\" is not a select");
992
+ throw new Error("Element with id \""+id+"\" is not a div");
993
+ }
994
+
995
+ /**
996
+ * @param {string} id
997
+ * @returns {HTMLSpanElement}
998
+ */
999
+ export function getSpanElement(id)
1000
+ {
1001
+ let ele = document.getElementById(id);
1002
+ if (ele == null)
1003
+ throw new Error("Element with id \""+id+"\" not found");
1004
+ if (ele instanceof HTMLSpanElement)
1005
+ return ele;
1006
+ throw new Error("Element with id \""+id+"\" is not a span");
967
1007
  }
968
1008
 
969
1009
  /**