@sswroom/sswr 1.5.1 → 1.5.3
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 +37 -0
- package/cesium.d.ts +9 -2
- package/cesium.js +263 -44
- package/data.d.ts +6 -0
- package/data.js +216 -204
- package/geometry.d.ts +5 -0
- package/geometry.js +62 -50
- package/hkoapi.js +10 -10
- package/kml.d.ts +4 -1
- package/kml.js +53 -24
- package/leaflet.js +154 -34
- package/map.js +22 -22
- package/math.js +127 -127
- package/net.d.ts +2 -0
- package/net.js +76 -0
- package/olayer2.d.ts +11 -0
- package/olayer2.js +328 -76
- package/osm.js +21 -22
- package/package.json +1 -1
- package/parser.js +342 -95
- package/text.d.ts +127 -1
- package/text.js +1142 -21
- package/web.d.ts +9 -0
- package/web.js +222 -58
package/olayer2.js
CHANGED
|
@@ -1,17 +1,222 @@
|
|
|
1
|
+
import * as data from "./data.js";
|
|
1
2
|
import * as geometry from "./geometry.js";
|
|
2
3
|
import * as kml from "./kml.js";
|
|
3
4
|
import * as map from "./map.js";
|
|
4
5
|
import * as math from "./math.js";
|
|
6
|
+
import * as osm from "./osm.js";
|
|
7
|
+
import * as text from "./text.js";
|
|
5
8
|
import * as web from "./web.js";
|
|
6
9
|
|
|
10
|
+
export function toPointArray(numArr, options)
|
|
11
|
+
{
|
|
12
|
+
let ret = [];
|
|
13
|
+
let i;
|
|
14
|
+
for (i in numArr)
|
|
15
|
+
{
|
|
16
|
+
let pos = new OpenLayers.LonLat(numArr[i][0], numArr[i][1]).transform(options.objProjection, options.mapProjection);
|
|
17
|
+
ret.push(new OpenLayers.Geometry.Point(pos.lon, pos.lat));
|
|
18
|
+
}
|
|
19
|
+
return ret;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function createFromKMLFeature(feature, options)
|
|
23
|
+
{
|
|
24
|
+
options = data.mergeOptions(options, {noPopup: false});
|
|
25
|
+
if (feature instanceof kml.Container)
|
|
26
|
+
{
|
|
27
|
+
let i;
|
|
28
|
+
let layers = [];
|
|
29
|
+
let layer;
|
|
30
|
+
for (i in feature.features)
|
|
31
|
+
{
|
|
32
|
+
layer = await createFromKMLFeature(feature.features[i], options);
|
|
33
|
+
if (layer instanceof OpenLayers.Marker)
|
|
34
|
+
{
|
|
35
|
+
layers.push(layer);
|
|
36
|
+
}
|
|
37
|
+
else if (layer instanceof OpenLayers.Feature.Vector)
|
|
38
|
+
{
|
|
39
|
+
layers.push(layer);
|
|
40
|
+
}
|
|
41
|
+
else if (layer != null)
|
|
42
|
+
{
|
|
43
|
+
let j;
|
|
44
|
+
for (j in layer)
|
|
45
|
+
{
|
|
46
|
+
layers.push(layer[j]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return layers;
|
|
51
|
+
}
|
|
52
|
+
else if (feature instanceof kml.Placemark)
|
|
53
|
+
{
|
|
54
|
+
let opt = {objProjection: options.objProjection, mapProjection: options.mapProjection};
|
|
55
|
+
if (feature.name)
|
|
56
|
+
opt.name = feature.name;
|
|
57
|
+
if (feature.style)
|
|
58
|
+
{
|
|
59
|
+
let style = feature.style;
|
|
60
|
+
if (style instanceof kml.StyleMap)
|
|
61
|
+
{
|
|
62
|
+
style = style.normalStyle;
|
|
63
|
+
}
|
|
64
|
+
if (style instanceof kml.Style)
|
|
65
|
+
{
|
|
66
|
+
if (style.iconStyle)
|
|
67
|
+
{
|
|
68
|
+
let s = style.iconStyle;
|
|
69
|
+
if (s.iconUrl)
|
|
70
|
+
{
|
|
71
|
+
opt.iconUrl = s.iconUrl;
|
|
72
|
+
}
|
|
73
|
+
if (s.hotSpotX && s.hotSpotY)
|
|
74
|
+
{
|
|
75
|
+
opt.iconOffset = new OpenLayers.Pixel(-s.hotSpotX, -s.hotSpotY);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (style.lineStyle)
|
|
79
|
+
{
|
|
80
|
+
let ls = style.lineStyle;
|
|
81
|
+
if (ls.color)
|
|
82
|
+
opt.strokeColor = kml.toCSSColor(ls.color);
|
|
83
|
+
if (ls.width)
|
|
84
|
+
opt.strokeWidth = ls.width;
|
|
85
|
+
opt.stroke = true;
|
|
86
|
+
}
|
|
87
|
+
else
|
|
88
|
+
{
|
|
89
|
+
opt.stroke = false;
|
|
90
|
+
}
|
|
91
|
+
if (style.polyStyle)
|
|
92
|
+
{
|
|
93
|
+
let ps = style.polyStyle;
|
|
94
|
+
if (ps.color)
|
|
95
|
+
opt.fillColor = kml.toCSSColor(ps.color);
|
|
96
|
+
opt.fill = true;
|
|
97
|
+
}
|
|
98
|
+
else
|
|
99
|
+
{
|
|
100
|
+
opt.fill = false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
let layer = await createFromGeometry(feature.vec, opt);
|
|
105
|
+
if (layer instanceof OpenLayers.Geometry)
|
|
106
|
+
{
|
|
107
|
+
return new OpenLayers.Feature.Vector(layer, {name: feature.name, description: feature.description}, opt);
|
|
108
|
+
}
|
|
109
|
+
else if (layer instanceof OpenLayers.Marker)
|
|
110
|
+
{
|
|
111
|
+
if (!options.noPopup && (feature.name || feature.description))
|
|
112
|
+
{
|
|
113
|
+
let content;
|
|
114
|
+
if (feature.name && feature.description)
|
|
115
|
+
{
|
|
116
|
+
content = "<b>"+text.toHTMLText(feature.name)+"</b><br/>"+feature.description;
|
|
117
|
+
}
|
|
118
|
+
else if (feature.name)
|
|
119
|
+
{
|
|
120
|
+
content = "<b>"+text.toHTMLText(feature.name)+"</b>";
|
|
121
|
+
}
|
|
122
|
+
else
|
|
123
|
+
{
|
|
124
|
+
content = feature.description;
|
|
125
|
+
}
|
|
126
|
+
layer.events.register('click', layer, function(evt) {
|
|
127
|
+
let popup = new OpenLayers.Popup.FramedCloud("Popup",
|
|
128
|
+
layer.lonlat,
|
|
129
|
+
null,
|
|
130
|
+
content,
|
|
131
|
+
null,
|
|
132
|
+
null);
|
|
133
|
+
options.map.addPopup(popup, true);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return layer;
|
|
137
|
+
}
|
|
138
|
+
return layer;
|
|
139
|
+
}
|
|
140
|
+
else
|
|
141
|
+
{
|
|
142
|
+
console.log("Unknown KML feature type", feature);
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export async function createFromGeometry(geom, options)
|
|
148
|
+
{
|
|
149
|
+
if (options == null)
|
|
150
|
+
{
|
|
151
|
+
console.log("createFromGeometry does not have options");
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
if (geom instanceof geometry.Point)
|
|
155
|
+
{
|
|
156
|
+
let icon;
|
|
157
|
+
if (options.iconUrl && options.iconOffset)
|
|
158
|
+
{
|
|
159
|
+
let size = await web.getImageInfo(options.iconUrl);
|
|
160
|
+
if (size == null)
|
|
161
|
+
{
|
|
162
|
+
console.log("Error in getting image info from url", options.iconUrl);
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
icon = new OpenLayers.Icon(options.iconUrl, new OpenLayers.Size(size.width, size.height), options.iconOffset);
|
|
166
|
+
return new OpenLayers.Marker(new OpenLayers.LonLat(geom.coordinates[0], geom.coordinates[1]).transform(options.objProjection, options.mapProjection), icon);
|
|
167
|
+
}
|
|
168
|
+
else
|
|
169
|
+
{
|
|
170
|
+
let lonLat = new OpenLayers.LonLat(geom.coordinates[0], geom.coordinates[1]).transform(options.objProjection, options.mapProjection);
|
|
171
|
+
return new OpenLayers.Geometry.Point(lonLat.lon, lonLat.lat);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
else if (geom instanceof geometry.LinearRing)
|
|
175
|
+
{
|
|
176
|
+
return new OpenLayers.Geometry.LinearRing(toPointArray(geom.coordinates, options));
|
|
177
|
+
}
|
|
178
|
+
else if (geom instanceof geometry.LineString)
|
|
179
|
+
{
|
|
180
|
+
return new OpenLayers.Geometry.LineString(toPointArray(geom.coordinates, options));
|
|
181
|
+
}
|
|
182
|
+
else if (geom instanceof geometry.Polygon)
|
|
183
|
+
{
|
|
184
|
+
let lrList = [];
|
|
185
|
+
let i;
|
|
186
|
+
for (i in geom.geometries)
|
|
187
|
+
{
|
|
188
|
+
lrList.push(await createFromGeometry(geom.geometries[i], options));
|
|
189
|
+
}
|
|
190
|
+
return new OpenLayers.Geometry.Polygon(lrList);
|
|
191
|
+
}
|
|
192
|
+
else if (geom instanceof geometry.MultiPolygon)
|
|
193
|
+
{
|
|
194
|
+
let pgList = [];
|
|
195
|
+
let i;
|
|
196
|
+
for (i in geom.geometries)
|
|
197
|
+
{
|
|
198
|
+
pgList.push(await createFromGeometry(geom.geometries[i], options));
|
|
199
|
+
}
|
|
200
|
+
return new OpenLayers.Geometry.MultiPolygon(pgList);
|
|
201
|
+
}
|
|
202
|
+
else
|
|
203
|
+
{
|
|
204
|
+
console.log("Unknown geometry type", geom);
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
7
209
|
export class Olayer2Map extends map.MapControl
|
|
8
210
|
{
|
|
9
211
|
constructor(mapId)
|
|
10
212
|
{
|
|
11
213
|
super();
|
|
12
214
|
this.inited = false;
|
|
215
|
+
this.initX = 114.2;
|
|
216
|
+
this.initY = 22.4;
|
|
217
|
+
this.initLev = 12;
|
|
13
218
|
this.mapId = mapId;
|
|
14
|
-
|
|
219
|
+
let dom = document.getElementById(mapId);
|
|
15
220
|
dom.style.minWidth = '1px';
|
|
16
221
|
dom.style.minHeight = '1px';
|
|
17
222
|
this.mapProjection = new OpenLayers.Projection("EPSG:4326");
|
|
@@ -65,7 +270,7 @@ export class Olayer2Map extends map.MapControl
|
|
|
65
270
|
{
|
|
66
271
|
if (layer.type == map.WebMapType.OSMTile)
|
|
67
272
|
{
|
|
68
|
-
return new OpenLayers.Layer.OSM(layer.name, [layer.url]);
|
|
273
|
+
return new OpenLayers.Layer.OSM(layer.name, [layer.url.replace("{x}", "${x}").replace("{y}", "${y}").replace("{z}", "${z}")]);
|
|
69
274
|
}
|
|
70
275
|
else if (layer.type == map.WebMapType.ArcGIS)
|
|
71
276
|
{
|
|
@@ -80,33 +285,72 @@ export class Olayer2Map extends map.MapControl
|
|
|
80
285
|
|
|
81
286
|
createMarkerLayer(name, options)
|
|
82
287
|
{
|
|
83
|
-
|
|
288
|
+
let layer = new OpenLayers.Layer.Markers(name);
|
|
84
289
|
return layer;
|
|
85
290
|
}
|
|
86
291
|
|
|
87
292
|
createGeometryLayer(name, options)
|
|
88
293
|
{
|
|
89
|
-
|
|
294
|
+
let layer = new OpenLayers.Layer.Vector(name);
|
|
90
295
|
return layer;
|
|
91
296
|
}
|
|
92
297
|
|
|
93
298
|
addLayer(layer)
|
|
94
299
|
{
|
|
95
|
-
|
|
96
|
-
|
|
300
|
+
if (layer instanceof OpenLayers.Layer)
|
|
301
|
+
{
|
|
302
|
+
this.map.addLayer(layer);
|
|
303
|
+
if (!this.inited)
|
|
304
|
+
{
|
|
305
|
+
this.inited = true;
|
|
306
|
+
this.map.setCenter(
|
|
307
|
+
new OpenLayers.LonLat(this.initX, this.initY).transform(
|
|
308
|
+
this.mapProjection,
|
|
309
|
+
this.map.getProjectionObject()
|
|
310
|
+
), this.initLev);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
else if (data.isArray(layer))
|
|
314
|
+
{
|
|
315
|
+
let vectorLayer;
|
|
316
|
+
let markerLayer;
|
|
317
|
+
let vectors = [];
|
|
318
|
+
let i;
|
|
319
|
+
for (i in layer)
|
|
320
|
+
{
|
|
321
|
+
if (layer[i] instanceof OpenLayers.Marker)
|
|
322
|
+
{
|
|
323
|
+
if (markerLayer == null)
|
|
324
|
+
markerLayer = new OpenLayers.Layer.Markers("Markers");
|
|
325
|
+
markerLayer.addMarker(layer[i]);
|
|
326
|
+
}
|
|
327
|
+
else if (layer[i] instanceof OpenLayers.Feature.Vector)
|
|
328
|
+
{
|
|
329
|
+
vectors.push(layer[i]);
|
|
330
|
+
}
|
|
331
|
+
else
|
|
332
|
+
{
|
|
333
|
+
console.log("Unknown type on layer array");
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (vectors.length > 0)
|
|
337
|
+
{
|
|
338
|
+
vectorLayer = new OpenLayers.Layer.Vector("Vectors");
|
|
339
|
+
vectorLayer.addFeatures(vectors);
|
|
340
|
+
this.map.addLayer(vectorLayer);
|
|
341
|
+
}
|
|
342
|
+
if (markerLayer)
|
|
343
|
+
this.map.addLayer(markerLayer);
|
|
344
|
+
}
|
|
345
|
+
else
|
|
97
346
|
{
|
|
98
|
-
|
|
99
|
-
this.map.setCenter(
|
|
100
|
-
new OpenLayers.LonLat(114.2, 22.4).transform(
|
|
101
|
-
this.mapProjection,
|
|
102
|
-
this.map.getProjectionObject()
|
|
103
|
-
), 12);
|
|
347
|
+
console.log("Unknown layer type", layer);
|
|
104
348
|
}
|
|
105
349
|
}
|
|
106
350
|
|
|
107
351
|
addKMLFeature(feature)
|
|
108
352
|
{
|
|
109
|
-
|
|
353
|
+
createFromKMLFeature(feature, {map: this.map, objProjection: this.mapProjection, mapProjection: this.map.getProjectionObject()}).then((layer)=>{this.addLayer(layer);});
|
|
110
354
|
}
|
|
111
355
|
|
|
112
356
|
uninit()
|
|
@@ -136,25 +380,33 @@ export class Olayer2Map extends map.MapControl
|
|
|
136
380
|
|
|
137
381
|
panZoomScale(pos, scale)
|
|
138
382
|
{
|
|
139
|
-
this.
|
|
140
|
-
|
|
383
|
+
if (this.inited)
|
|
384
|
+
{
|
|
385
|
+
this.map.zoomToScale(scale, false);
|
|
386
|
+
this.map.setCenter(new OpenLayers.LonLat(pos.x, pos.y).transform(this.mapProjection, this.map.getProjectionObject()), this.map.getZoom(), false, false);
|
|
387
|
+
}
|
|
388
|
+
else
|
|
389
|
+
{
|
|
390
|
+
this.initX = pos.x;
|
|
391
|
+
this.initY = pos.y;
|
|
392
|
+
this.initLev = osm.scale2Level(scale);
|
|
393
|
+
}
|
|
141
394
|
}
|
|
142
395
|
|
|
143
396
|
zoomToExtent(extent)
|
|
144
397
|
{
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
398
|
+
let pos = extent.getCenter();
|
|
399
|
+
let currZoom = this.map.getZoom();
|
|
400
|
+
let tl = this.map2ScnPos(new math.Coord2D(extent.min.x, extent.max.y));
|
|
401
|
+
let br = this.map2ScnPos(new math.Coord2D(extent.max.x, extent.min.y));
|
|
402
|
+
let scnSize = this.map.getSize();
|
|
403
|
+
let ratioX = (br.x - tl.x) / scnSize.w;
|
|
404
|
+
let ratioY = (br.y - tl.y) / scnSize.h;
|
|
152
405
|
if (ratioY > ratioX)
|
|
153
406
|
{
|
|
154
407
|
ratioX = ratioY;
|
|
155
408
|
}
|
|
156
|
-
|
|
157
|
-
var maxZoom = this.map.getNumZoomLevels() - 1;
|
|
409
|
+
let maxZoom = this.map.getNumZoomLevels() - 1;
|
|
158
410
|
currZoom += Math.floor(-Math.log(ratioX) / Math.log(2));
|
|
159
411
|
if (currZoom < 0)
|
|
160
412
|
currZoom = 0;
|
|
@@ -180,21 +432,21 @@ export class Olayer2Map extends map.MapControl
|
|
|
180
432
|
|
|
181
433
|
map2ScnPos(mapPos)
|
|
182
434
|
{
|
|
183
|
-
|
|
435
|
+
let scnPx = this.map.getViewPortPxFromLonLat(new OpenLayers.LonLat(mapPos.x, mapPos.y).transform(this.mapProjection, this.map.getProjectionObject()));
|
|
184
436
|
return new math.Coord2D(scnPx.x, scnPx.y);
|
|
185
437
|
}
|
|
186
438
|
|
|
187
439
|
scn2MapPos(scnPos)
|
|
188
440
|
{
|
|
189
|
-
|
|
441
|
+
let lonLat = this.map.getLonLatFromViewPortPx(new OpenLayers.Pixel(scnPos.x, scnPos.y)).transform(this.map.getProjectionObject(), this.mapProjection);
|
|
190
442
|
return new math.Coord2D(lonLat.lon, lonLat.lat);
|
|
191
443
|
}
|
|
192
444
|
|
|
193
445
|
createMarker(mapPos, imgURL, imgWidth, imgHeight, options)
|
|
194
446
|
{
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
447
|
+
let size = new OpenLayers.Size(imgWidth, imgHeight);
|
|
448
|
+
let offset = new OpenLayers.Pixel(-(size.w / 2), -(size.h / 2));
|
|
449
|
+
let icon = new OpenLayers.Icon(imgURL, size, offset);
|
|
198
450
|
if (options && options.zIndex)
|
|
199
451
|
{
|
|
200
452
|
icon.imageDiv.style.zIndex = options.zIndex;
|
|
@@ -220,7 +472,7 @@ export class Olayer2Map extends map.MapControl
|
|
|
220
472
|
|
|
221
473
|
markerIsOver(marker, scnPos)
|
|
222
474
|
{
|
|
223
|
-
|
|
475
|
+
let icon = marker.icon;
|
|
224
476
|
//alert("x="+x+", y="+y+", px.x="+icon.px.x+", px.y="+icon.px.y+", offset.x="+icon.offset.x+", offset.y="+icon.offset.y+", size.w="+icon.size.w+", size.h="+icon.size.h+", debug="+(icon.px.x + icon.px.offset.x + icon.size.w));
|
|
225
477
|
if ((scnPos.x < icon.px.x + icon.offset.x) || (scnPos.y < icon.px.y + icon.offset.y))
|
|
226
478
|
return false;
|
|
@@ -231,7 +483,7 @@ export class Olayer2Map extends map.MapControl
|
|
|
231
483
|
|
|
232
484
|
createGeometry(geom, options)
|
|
233
485
|
{
|
|
234
|
-
|
|
486
|
+
let opt = {};
|
|
235
487
|
if (options.lineColor)
|
|
236
488
|
{
|
|
237
489
|
opt.strokeColor = options.lineColor;
|
|
@@ -258,38 +510,38 @@ export class Olayer2Map extends map.MapControl
|
|
|
258
510
|
}
|
|
259
511
|
else if (geom instanceof geometry.LinearRing)
|
|
260
512
|
{
|
|
261
|
-
|
|
262
|
-
|
|
513
|
+
let i;
|
|
514
|
+
let points = [];
|
|
263
515
|
for (i in geom.coordinates)
|
|
264
516
|
{
|
|
265
|
-
|
|
517
|
+
let pos = new OpenLayers.LonLat(geom.coordinates[i][0], geom.coordinates[i][1]).transform(this.mapProjection, this.map.getProjectionObject());
|
|
266
518
|
points.push(new OpenLayers.Geometry.Point(pos.lon, pos.lat));
|
|
267
519
|
}
|
|
268
520
|
return new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LinearRing(points), null, opt);
|
|
269
521
|
}
|
|
270
522
|
else if (geom instanceof geometry.LineString)
|
|
271
523
|
{
|
|
272
|
-
|
|
273
|
-
|
|
524
|
+
let i;
|
|
525
|
+
let points = [];
|
|
274
526
|
for (i in geom.coordinates)
|
|
275
527
|
{
|
|
276
|
-
|
|
528
|
+
let pos = new OpenLayers.LonLat(geom.coordinates[i][0], geom.coordinates[i][1]).transform(this.mapProjection, this.map.getProjectionObject());
|
|
277
529
|
points.push(new OpenLayers.Geometry.Point(pos.lon, pos.lat));
|
|
278
530
|
}
|
|
279
531
|
return new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LineString(points), null, opt);
|
|
280
532
|
}
|
|
281
533
|
else if (geom instanceof geometry.Polygon)
|
|
282
534
|
{
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
535
|
+
let i;
|
|
536
|
+
let j;
|
|
537
|
+
let lrArr = [];
|
|
286
538
|
for (i in geom.geometries)
|
|
287
539
|
{
|
|
288
|
-
|
|
289
|
-
|
|
540
|
+
let points = [];
|
|
541
|
+
let lr = geom.geometries[i];
|
|
290
542
|
for (j in lr.coordinates)
|
|
291
543
|
{
|
|
292
|
-
|
|
544
|
+
let pos = new OpenLayers.LonLat(lr.coordinates[j][0], lr.coordinates[j][1]).transform(this.mapProjection, this.map.getProjectionObject());
|
|
293
545
|
points.push(new OpenLayers.Geometry.Point(pos.lon, pos.lat));
|
|
294
546
|
}
|
|
295
547
|
lrArr.push(new OpenLayers.Geometry.LineString(points));
|
|
@@ -298,21 +550,21 @@ export class Olayer2Map extends map.MapControl
|
|
|
298
550
|
}
|
|
299
551
|
else if (geom instanceof geometry.MultiPolygon)
|
|
300
552
|
{
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
553
|
+
let i;
|
|
554
|
+
let j;
|
|
555
|
+
let k;
|
|
556
|
+
let pgArr = [];
|
|
305
557
|
for (i in geom.geometries)
|
|
306
558
|
{
|
|
307
|
-
|
|
308
|
-
|
|
559
|
+
let lrArr = [];
|
|
560
|
+
let pg = geom.geometries[i];
|
|
309
561
|
for (j in pg.geometries)
|
|
310
562
|
{
|
|
311
|
-
|
|
312
|
-
|
|
563
|
+
let lr = pg.geometries[j];
|
|
564
|
+
let points = [];
|
|
313
565
|
for (k in lr.coordinates)
|
|
314
566
|
{
|
|
315
|
-
|
|
567
|
+
let pos = new OpenLayers.LonLat(lr.coordinates[k][0], lr.coordinates[k][1]).transform(this.mapProjection, this.map.getProjectionObject());
|
|
316
568
|
points.push(new OpenLayers.Geometry.Point(pos.lon, pos.lat));
|
|
317
569
|
}
|
|
318
570
|
lrArr.push(new OpenLayers.Geometry.LineString(points));
|
|
@@ -341,7 +593,7 @@ export class Olayer2Map extends map.MapControl
|
|
|
341
593
|
|
|
342
594
|
toKMLFeature(layer, doc)
|
|
343
595
|
{
|
|
344
|
-
|
|
596
|
+
let feature;
|
|
345
597
|
if (doc == null || !(doc instanceof kml.Document))
|
|
346
598
|
{
|
|
347
599
|
doc = new kml.Document();
|
|
@@ -355,9 +607,9 @@ export class Olayer2Map extends map.MapControl
|
|
|
355
607
|
}
|
|
356
608
|
if (layer instanceof OpenLayers.Layer.Markers)
|
|
357
609
|
{
|
|
358
|
-
|
|
610
|
+
let featureGroup = new kml.Folder();
|
|
359
611
|
featureGroup.setName(layer.name || "Markers");
|
|
360
|
-
|
|
612
|
+
let i;
|
|
361
613
|
for (i in layer.markers)
|
|
362
614
|
{
|
|
363
615
|
feature = this.toKMLFeature(layer.markers[i], doc);
|
|
@@ -368,17 +620,17 @@ export class Olayer2Map extends map.MapControl
|
|
|
368
620
|
}
|
|
369
621
|
else if (layer instanceof OpenLayers.Marker)
|
|
370
622
|
{
|
|
371
|
-
|
|
623
|
+
let pos = layer.lonlat.transform(this.map.getProjectionObject(), this.mapProjection);
|
|
372
624
|
feature = new kml.Placemark(new geometry.Point(4326, [pos.lon, pos.lat]));
|
|
373
625
|
feature.setName("Marker");
|
|
374
|
-
|
|
626
|
+
let icon = layer.icon;
|
|
375
627
|
if (icon)
|
|
376
628
|
{
|
|
377
|
-
|
|
629
|
+
let iconStyle = new kml.IconStyle();
|
|
378
630
|
if (icon.url.startsWith("/"))
|
|
379
631
|
{
|
|
380
|
-
|
|
381
|
-
|
|
632
|
+
let durl = document.location.href;
|
|
633
|
+
let i = durl.indexOf("://");
|
|
382
634
|
i = durl.indexOf("/", i + 3);
|
|
383
635
|
if (i >= 0)
|
|
384
636
|
{
|
|
@@ -401,9 +653,9 @@ export class Olayer2Map extends map.MapControl
|
|
|
401
653
|
}
|
|
402
654
|
else if (layer instanceof OpenLayers.Layer.Vector)
|
|
403
655
|
{
|
|
404
|
-
|
|
656
|
+
let featureGroup = new kml.Folder();
|
|
405
657
|
featureGroup.setName(layer.name || "Vector");
|
|
406
|
-
|
|
658
|
+
let i;
|
|
407
659
|
for (i in layer.features)
|
|
408
660
|
{
|
|
409
661
|
feature = this.toKMLFeature(layer.features[i], doc);
|
|
@@ -414,13 +666,13 @@ export class Olayer2Map extends map.MapControl
|
|
|
414
666
|
}
|
|
415
667
|
else if (layer instanceof OpenLayers.Feature.Vector)
|
|
416
668
|
{
|
|
417
|
-
|
|
418
|
-
|
|
669
|
+
let lineStyle = null;
|
|
670
|
+
let polyStyle = null;
|
|
419
671
|
if (layer.style)
|
|
420
672
|
{
|
|
421
673
|
if (layer.style.stroke)
|
|
422
674
|
{
|
|
423
|
-
|
|
675
|
+
let c = web.parseCSSColor(layer.style.strokeColor);
|
|
424
676
|
lineStyle = new kml.LineStyle();
|
|
425
677
|
lineStyle.fromARGB(c.a, c.r, c.g, c.b);
|
|
426
678
|
if (layer.style.strokeWidth)
|
|
@@ -428,22 +680,22 @@ export class Olayer2Map extends map.MapControl
|
|
|
428
680
|
}
|
|
429
681
|
if (layer.style.fill)
|
|
430
682
|
{
|
|
431
|
-
|
|
683
|
+
let c = web.parseCSSColor(layer.style.fillColor);
|
|
432
684
|
if (layer.style.fillOpacity)
|
|
433
685
|
c.a = c.a * layer.style.fillOpacity;
|
|
434
686
|
polyStyle = new kml.PolyStyle();
|
|
435
687
|
polyStyle.fromARGB(c.a, c.r, c.g, c.b);
|
|
436
688
|
}
|
|
437
689
|
}
|
|
438
|
-
|
|
439
|
-
|
|
690
|
+
let vec;
|
|
691
|
+
let geom = layer.geometry;
|
|
440
692
|
if (geom instanceof OpenLayers.Geometry.LinearRing)
|
|
441
693
|
{
|
|
442
|
-
|
|
443
|
-
|
|
694
|
+
let pts = [];
|
|
695
|
+
let i;
|
|
444
696
|
for (i in geom.components)
|
|
445
697
|
{
|
|
446
|
-
|
|
698
|
+
let pt = new OpenLayers.LonLat(geom.components[i].x, geom.components[i].y).transform(this.map.getProjectionObject(), this.mapProjection);
|
|
447
699
|
pts.push([pt.lon, pt.lat]);
|
|
448
700
|
}
|
|
449
701
|
vec = new geometry.LinearRing(4326, pts);
|
|
@@ -452,7 +704,7 @@ export class Olayer2Map extends map.MapControl
|
|
|
452
704
|
{
|
|
453
705
|
throw new Error("Unsupported type of geometry");
|
|
454
706
|
}
|
|
455
|
-
|
|
707
|
+
let placemark = new kml.Placemark(vec);
|
|
456
708
|
placemark.setStyle(doc.getOrNewStyle(null, null, lineStyle, polyStyle, null, null));
|
|
457
709
|
return placemark;
|
|
458
710
|
}
|
|
@@ -467,7 +719,7 @@ export class Olayer2Map extends map.MapControl
|
|
|
467
719
|
{
|
|
468
720
|
if (this.lclickFunc)
|
|
469
721
|
{
|
|
470
|
-
|
|
722
|
+
let lonlat = this.map.getLonLatFromViewPortPx(e.xy).transform(this.map.getProjectionObject(), this.mapProjection);
|
|
471
723
|
this.lclickFunc(lonlat.lat, lonlat.lon, e.xy.x, e.xy.y);
|
|
472
724
|
}
|
|
473
725
|
}
|
|
@@ -478,7 +730,7 @@ export class Olayer2Map extends map.MapControl
|
|
|
478
730
|
return;
|
|
479
731
|
if (this.posFunc)
|
|
480
732
|
{
|
|
481
|
-
|
|
733
|
+
let cent = this.map.getCenter().transform(this.map.getProjectionObject(), this.mapProjection);
|
|
482
734
|
this.posFunc(new math.Coord2D(cent.lon, cent.lat));
|
|
483
735
|
}
|
|
484
736
|
}
|
|
@@ -489,8 +741,8 @@ export class Olayer2Map extends map.MapControl
|
|
|
489
741
|
return;
|
|
490
742
|
if (this.moveFunc)
|
|
491
743
|
{
|
|
492
|
-
|
|
493
|
-
|
|
744
|
+
let pos = this.map.events.getMousePosition(event);
|
|
745
|
+
let cent = this.map.getLonLatFromViewPortPx(pos).transform(this.map.getProjectionObject(), this.mapProjection);
|
|
494
746
|
this.moveFunc(new math.Coord2D(cent.lon, cent.lat));
|
|
495
747
|
}
|
|
496
748
|
}
|
package/osm.js
CHANGED
|
@@ -15,21 +15,21 @@ export function pixelX2Lon(x, level, tileSize)
|
|
|
15
15
|
|
|
16
16
|
export function pixelY2Lat(y, level, tileSize)
|
|
17
17
|
{
|
|
18
|
-
|
|
18
|
+
let n = Math.PI - 2.0 * Math.PI * y / tileSize / (1 << level);
|
|
19
19
|
return 180.0 / Math.PI * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function tileUrls(osmUrl, minCoord, maxCoord, minLev, maxLev)
|
|
23
23
|
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
let tileSize = 256;
|
|
25
|
+
let ret = new Array();
|
|
26
|
+
let minX;
|
|
27
|
+
let minY;
|
|
28
|
+
let maxX;
|
|
29
|
+
let maxY;
|
|
30
|
+
let i;
|
|
31
|
+
let j;
|
|
32
|
+
let url;
|
|
33
33
|
while (minLev <= maxLev)
|
|
34
34
|
{
|
|
35
35
|
minX = Math.floor(lon2PixelX(minCoord.x, minLev, tileSize) / tileSize);
|
|
@@ -57,23 +57,22 @@ export function removeTileUrls(urls, osmUrl, minLev, maxLev, areaList)
|
|
|
57
57
|
{
|
|
58
58
|
if (areaList == null || areaList.length == 0)
|
|
59
59
|
return;
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
let urlMap = {};
|
|
61
|
+
let i;
|
|
62
62
|
for (i in urls)
|
|
63
63
|
{
|
|
64
64
|
urlMap[urls[i]] = true;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
var url;
|
|
67
|
+
let tileSize = 256;
|
|
68
|
+
let minX;
|
|
69
|
+
let minY;
|
|
70
|
+
let maxX;
|
|
71
|
+
let maxY;
|
|
72
|
+
let j;
|
|
73
|
+
let k;
|
|
74
|
+
let rect;
|
|
75
|
+
let url;
|
|
77
76
|
while (minLev <= maxLev)
|
|
78
77
|
{
|
|
79
78
|
for (k in areaList)
|