@sswroom/sswr 1.6.10 → 1.6.11

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 * as 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.11",
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)