@hzab/map-combine 0.2.0 → 0.2.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/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -7,7 +7,6 @@ import DragPan from "ol/interaction/DragPan";
|
|
|
7
7
|
import VectorSource from "ol/source/Vector";
|
|
8
8
|
import VectorLayer from "ol/layer/Vector";
|
|
9
9
|
import { fromLonLat } from "ol/proj";
|
|
10
|
-
import * as olProj from "ol/proj";
|
|
11
10
|
import * as olGeom from "ol/geom";
|
|
12
11
|
import * as olSource from "ol/source";
|
|
13
12
|
import * as olStyle from "ol/style";
|
|
@@ -47,6 +46,7 @@ export class OpenlayerMap extends MapCombine {
|
|
|
47
46
|
option: IOpenlayerOption;
|
|
48
47
|
offset: number[];
|
|
49
48
|
fov = 0.9272952180016121;
|
|
49
|
+
isFromLonLat = true;
|
|
50
50
|
get cursor(): string {
|
|
51
51
|
return this.container.style.cursor;
|
|
52
52
|
}
|
|
@@ -121,8 +121,9 @@ export class OpenlayerMap extends MapCombine {
|
|
|
121
121
|
this.cursor = "default";
|
|
122
122
|
|
|
123
123
|
const { center } = this;
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
const proj = this.viewer.getView().getProjection().getCode();
|
|
125
|
+
this.isFromLonLat = (proj === "EPSG:3857" || proj === "EPSG:4326");
|
|
126
|
+
this.offset = this.getFromLonLat(center);
|
|
126
127
|
this.vectors = new VectorSource();
|
|
127
128
|
this.viewer.addLayer(
|
|
128
129
|
new VectorLayer({
|
|
@@ -143,6 +144,11 @@ export class OpenlayerMap extends MapCombine {
|
|
|
143
144
|
bindEvent(this);
|
|
144
145
|
}
|
|
145
146
|
|
|
147
|
+
|
|
148
|
+
getFromLonLat(lonLat) {
|
|
149
|
+
return this.isFromLonLat ? fromLonLat(lonLat) : lonLat;
|
|
150
|
+
}
|
|
151
|
+
|
|
146
152
|
createPoint<K>(option?: Partial<PointOption<K>>): Point<K> {
|
|
147
153
|
const e = new Point(this, option);
|
|
148
154
|
drawPoint(this, e);
|
|
@@ -182,7 +188,7 @@ export class OpenlayerMap extends MapCombine {
|
|
|
182
188
|
// 创建 Feature 数组
|
|
183
189
|
const features = points.map((point) => {
|
|
184
190
|
const [lon, lat] = point;
|
|
185
|
-
const coord =
|
|
191
|
+
const coord = this.getFromLonLat([lon, lat]);
|
|
186
192
|
return new ol.Feature({
|
|
187
193
|
geometry: new olGeom.Point(coord),
|
|
188
194
|
});
|
|
@@ -214,7 +220,7 @@ export class OpenlayerMap extends MapCombine {
|
|
|
214
220
|
return [Projection.lonToX(p[0]) - offset[0], Projection.latToY(p[1]) - offset[1], p[2] ?? 0];
|
|
215
221
|
}
|
|
216
222
|
geographyTcanvas(p: number[]): number[] {
|
|
217
|
-
const pixel = this.viewer.getPixelFromCoordinate(
|
|
223
|
+
const pixel = this.viewer.getPixelFromCoordinate(this.getFromLonLat(p));
|
|
218
224
|
if (pixel) {
|
|
219
225
|
return [pixel[0], pixel[1]];
|
|
220
226
|
} else {
|
|
@@ -9,7 +9,7 @@ import VectorLayer from "ol/layer/Vector";
|
|
|
9
9
|
const RD = 0.017453292519943295
|
|
10
10
|
|
|
11
11
|
export function drawPoint(map: OpenlayerMap, point: Point<unknown>) {
|
|
12
|
-
const { viewer, event } = map
|
|
12
|
+
const { viewer, event, getFromLonLat } = map
|
|
13
13
|
let status = 0
|
|
14
14
|
|
|
15
15
|
const source = new VectorSource();
|
|
@@ -67,7 +67,7 @@ export function drawPoint(map: OpenlayerMap, point: Point<unknown>) {
|
|
|
67
67
|
feature.set('event', _event, true)
|
|
68
68
|
if (point.coordinates) {
|
|
69
69
|
status = 2
|
|
70
|
-
geometry.setCoordinates(
|
|
70
|
+
geometry.setCoordinates(getFromLonLat(point.coordinates))
|
|
71
71
|
layer.setZIndex(point.coordinates[2] ?? 1)
|
|
72
72
|
point.event.trigger('data-loaded')
|
|
73
73
|
source.addFeature(feature)
|
|
@@ -87,7 +87,7 @@ export function drawPoint(map: OpenlayerMap, point: Point<unknown>) {
|
|
|
87
87
|
break;
|
|
88
88
|
case 'coordinates':
|
|
89
89
|
if (point.coordinates) {
|
|
90
|
-
geometry.setCoordinates(
|
|
90
|
+
geometry.setCoordinates(getFromLonLat(point.coordinates))
|
|
91
91
|
layer.setZIndex(point.coordinates[2])
|
|
92
92
|
switch (status) {
|
|
93
93
|
case 0:
|
|
@@ -138,16 +138,16 @@ export function drawPoint(map: OpenlayerMap, point: Point<unknown>) {
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
const onMouseMove = () => {
|
|
141
|
-
const coordinates = [event.geography[0], event.geography[1], point.height]
|
|
141
|
+
const coordinates = [event.geography[0], event.geography[1], point.height];
|
|
142
142
|
switch (status) {
|
|
143
143
|
case 0:
|
|
144
144
|
status = 1
|
|
145
|
-
geometry.setCoordinates(
|
|
145
|
+
geometry.setCoordinates(getFromLonLat(coordinates))
|
|
146
146
|
source.addFeature(feature)
|
|
147
147
|
break;
|
|
148
148
|
case 1:
|
|
149
149
|
case 3:
|
|
150
|
-
geometry.setCoordinates(
|
|
150
|
+
geometry.setCoordinates(getFromLonLat(coordinates))
|
|
151
151
|
break
|
|
152
152
|
}
|
|
153
153
|
}
|
|
@@ -34,7 +34,7 @@ const styleVirtual = new Style({
|
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
export function drawPolygon(map: OpenlayerMap, polygon: Polygon<unknown>) {
|
|
37
|
-
const { event, viewer, vectors } = map
|
|
37
|
+
const { event, viewer, vectors, getFromLonLat } = map
|
|
38
38
|
|
|
39
39
|
const source = new VectorSource();
|
|
40
40
|
|
|
@@ -93,7 +93,7 @@ export function drawPolygon(map: OpenlayerMap, polygon: Polygon<unknown>) {
|
|
|
93
93
|
feature.set('event', _event, true)
|
|
94
94
|
if (polygon.coordinates) {
|
|
95
95
|
status = 2
|
|
96
|
-
geometry.setCoordinates([polygon.coordinates.map(e =>
|
|
96
|
+
geometry.setCoordinates([polygon.coordinates.map(e => getFromLonLat(e))])
|
|
97
97
|
layer.setZIndex(polygon.coordinates[0][2] ?? 1)
|
|
98
98
|
source.addFeature(feature)
|
|
99
99
|
}
|
|
@@ -116,7 +116,7 @@ export function drawPolygon(map: OpenlayerMap, polygon: Polygon<unknown>) {
|
|
|
116
116
|
break;
|
|
117
117
|
case 'coordinates':
|
|
118
118
|
if (polygon.coordinates) {
|
|
119
|
-
geometry.setCoordinates([polygon.coordinates.map(e =>
|
|
119
|
+
geometry.setCoordinates([polygon.coordinates.map(e => getFromLonLat(e))])
|
|
120
120
|
layer.setZIndex(polygon.coordinates[0][2] ?? 1)
|
|
121
121
|
switch (status) {
|
|
122
122
|
case 0:
|
|
@@ -158,11 +158,11 @@ export function drawPolygon(map: OpenlayerMap, polygon: Polygon<unknown>) {
|
|
|
158
158
|
switch (status) {
|
|
159
159
|
case 1:
|
|
160
160
|
cache.pop()
|
|
161
|
-
cache.push(
|
|
161
|
+
cache.push(getFromLonLat(event.geography))
|
|
162
162
|
geometry.setCoordinates([cache])
|
|
163
163
|
break
|
|
164
164
|
case 4:
|
|
165
|
-
activeNode.update(
|
|
165
|
+
activeNode.update(getFromLonLat(event.geography))
|
|
166
166
|
geometry.setCoordinates([editor.getCoordinates()])
|
|
167
167
|
break;
|
|
168
168
|
}
|
|
@@ -172,8 +172,7 @@ export function drawPolygon(map: OpenlayerMap, polygon: Polygon<unknown>) {
|
|
|
172
172
|
switch (status) {
|
|
173
173
|
case 0:
|
|
174
174
|
status = 1
|
|
175
|
-
|
|
176
|
-
cache = [fromLonLat(event.geography)]
|
|
175
|
+
cache = [getFromLonLat(event.geography)]
|
|
177
176
|
cache.push(cache[0])
|
|
178
177
|
geometry.setCoordinates([cache])
|
|
179
178
|
source.addFeature(feature)
|
|
@@ -30,7 +30,7 @@ const styleVirtual = new Style({
|
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
export function drawPolyline(map: OpenlayerMap, polyline: Polyline<unknown>) {
|
|
33
|
-
const { event, viewer } = map
|
|
33
|
+
const { event, viewer, getFromLonLat } = map
|
|
34
34
|
|
|
35
35
|
const source = new VectorSource();
|
|
36
36
|
|
|
@@ -86,7 +86,7 @@ export function drawPolyline(map: OpenlayerMap, polyline: Polyline<unknown>) {
|
|
|
86
86
|
feature.set('event', _event, true)
|
|
87
87
|
if (polyline.coordinates) {
|
|
88
88
|
status = 2
|
|
89
|
-
geometry.setCoordinates(polyline.coordinates.map(e =>
|
|
89
|
+
geometry.setCoordinates(polyline.coordinates.map(e => getFromLonLat(e)))
|
|
90
90
|
layer.setZIndex(polyline.coordinates[0][2] ?? 1)
|
|
91
91
|
source.addFeature(feature)
|
|
92
92
|
}
|
|
@@ -106,7 +106,7 @@ export function drawPolyline(map: OpenlayerMap, polyline: Polyline<unknown>) {
|
|
|
106
106
|
break;
|
|
107
107
|
case 'coordinates':
|
|
108
108
|
if (polyline.coordinates) {
|
|
109
|
-
geometry.setCoordinates(polyline.coordinates.map(e =>
|
|
109
|
+
geometry.setCoordinates(polyline.coordinates.map(e => getFromLonLat(e)))
|
|
110
110
|
layer.setZIndex(polyline.coordinates[0][2] ?? 1)
|
|
111
111
|
switch (status) {
|
|
112
112
|
case 0:
|
|
@@ -147,11 +147,11 @@ export function drawPolyline(map: OpenlayerMap, polyline: Polyline<unknown>) {
|
|
|
147
147
|
switch (status) {
|
|
148
148
|
case 1:
|
|
149
149
|
cache.pop()
|
|
150
|
-
cache.push(
|
|
150
|
+
cache.push(getFromLonLat(event.geography))
|
|
151
151
|
geometry.setCoordinates(cache)
|
|
152
152
|
break
|
|
153
153
|
case 4:
|
|
154
|
-
activeNode.update(
|
|
154
|
+
activeNode.update(getFromLonLat(event.geography))
|
|
155
155
|
geometry.setCoordinates(editor.getCoordinates())
|
|
156
156
|
break;
|
|
157
157
|
}
|
|
@@ -161,8 +161,8 @@ export function drawPolyline(map: OpenlayerMap, polyline: Polyline<unknown>) {
|
|
|
161
161
|
switch (status) {
|
|
162
162
|
case 0:
|
|
163
163
|
status = 1
|
|
164
|
-
_event.silent = true
|
|
165
|
-
cache = [
|
|
164
|
+
_event.silent = true;
|
|
165
|
+
cache = [getFromLonLat(event.geography)]
|
|
166
166
|
cache.push(cache[0])
|
|
167
167
|
geometry.setCoordinates(cache)
|
|
168
168
|
source.addFeature(feature)
|