my-openlayer 0.1.4 → 0.1.6
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/README.md +2 -1
- package/dist/core/Line.js +3 -3
- package/dist/core/MapBaseLayers.js +3 -3
- package/dist/core/MeasureHandler.d.ts +58 -0
- package/dist/core/MeasureHandler.js +296 -0
- package/dist/core/Point.js +3 -3
- package/dist/core/Polygon.d.ts +6 -5
- package/dist/core/Polygon.js +101 -54
- package/dist/types.d.ts +10 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/core/Line.js
CHANGED
|
@@ -26,7 +26,7 @@ export default class Line {
|
|
|
26
26
|
}),
|
|
27
27
|
});
|
|
28
28
|
},
|
|
29
|
-
zIndex: options.zIndex ??
|
|
29
|
+
zIndex: options.zIndex ?? 15
|
|
30
30
|
});
|
|
31
31
|
this[options.type + 'Layer'] = layer;
|
|
32
32
|
this.map.addLayer(layer);
|
|
@@ -64,7 +64,7 @@ export default class Line {
|
|
|
64
64
|
})
|
|
65
65
|
});
|
|
66
66
|
},
|
|
67
|
-
zIndex: options.zIndex ??
|
|
67
|
+
zIndex: options.zIndex ?? 15
|
|
68
68
|
});
|
|
69
69
|
riverLayer.setVisible(false);
|
|
70
70
|
this.riverLayerList.push(riverLayer);
|
|
@@ -102,7 +102,7 @@ export default class Line {
|
|
|
102
102
|
features: (new GeoJSON()).readFeatures(arr)
|
|
103
103
|
}),
|
|
104
104
|
style: (feature) => this.setFeatureAttr(feature),
|
|
105
|
-
zIndex:
|
|
105
|
+
zIndex: 15
|
|
106
106
|
});
|
|
107
107
|
this.map.addLayer(riverLayer);
|
|
108
108
|
}
|
|
@@ -30,7 +30,7 @@ export default class MapBaseLayers {
|
|
|
30
30
|
}
|
|
31
31
|
if (this.layers && Object.keys(this.layers).length !== 0) {
|
|
32
32
|
this.addMapLayer();
|
|
33
|
-
|
|
33
|
+
this.switchBaseLayer(Object.keys(this.layers)[0]);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -42,13 +42,13 @@ export default class MapBaseLayers {
|
|
|
42
42
|
for (const key in this.layers) {
|
|
43
43
|
this.layers[key]?.forEach((layer) => {
|
|
44
44
|
layer.setVisible(key === type);
|
|
45
|
-
console.log(layer)
|
|
45
|
+
// console.log(layer)
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
initLayer() {
|
|
50
50
|
if (this.layers && this.options.token) {
|
|
51
|
-
const { token, zIndex =
|
|
51
|
+
const { token, zIndex = 9 } = this.options;
|
|
52
52
|
this.layers.vec_c = [MapBaseLayers.getTiandiTuLayer({ type: 'vec_c', token, zIndex, visible: false })];
|
|
53
53
|
this.layers.img_c = [MapBaseLayers.getTiandiTuLayer({ type: 'img_c', token, zIndex, visible: false })];
|
|
54
54
|
this.layers.ter_c = [MapBaseLayers.getTiandiTuLayer({ type: 'ter_c', token, zIndex, visible: false })];
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import Map from "ol/Map";
|
|
2
|
+
import { MeasureHandlerType } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* @classdesc MeausreHandler
|
|
5
|
+
*/
|
|
6
|
+
export default class MeasureHandler {
|
|
7
|
+
private readonly source;
|
|
8
|
+
private readonly vector;
|
|
9
|
+
private sketch;
|
|
10
|
+
private helpTooltipElement;
|
|
11
|
+
private helpTooltip;
|
|
12
|
+
private _map;
|
|
13
|
+
private measureTooltipElement;
|
|
14
|
+
private measureTooltip;
|
|
15
|
+
private continuePolygonMsg;
|
|
16
|
+
private continueLineMsg;
|
|
17
|
+
private _tipsCollection;
|
|
18
|
+
private _mouseListener;
|
|
19
|
+
private _draw;
|
|
20
|
+
constructor(map: Map);
|
|
21
|
+
/**
|
|
22
|
+
* destory the object
|
|
23
|
+
*/
|
|
24
|
+
destory(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Format length output.
|
|
27
|
+
* @param {LineString} line The line.
|
|
28
|
+
* @return {string} The formatted length.
|
|
29
|
+
*/
|
|
30
|
+
formatLength(line: any): string;
|
|
31
|
+
/**
|
|
32
|
+
* Format area output.
|
|
33
|
+
* @param {Polygon} polygon The polygon.
|
|
34
|
+
* @return {string} Formatted area.
|
|
35
|
+
*/
|
|
36
|
+
formatArea(polygon: any): string;
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param {String} type the values such as 'Polygon','LineString'
|
|
40
|
+
*/
|
|
41
|
+
start(type: MeasureHandlerType): void;
|
|
42
|
+
/**
|
|
43
|
+
* end the measure drawing
|
|
44
|
+
*/
|
|
45
|
+
end(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new help tooltip
|
|
48
|
+
*/
|
|
49
|
+
createHelpTooltip(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new measure tooltip
|
|
52
|
+
*/
|
|
53
|
+
createMeasureTooltip(): void;
|
|
54
|
+
/**
|
|
55
|
+
* clean the all result of measure
|
|
56
|
+
*/
|
|
57
|
+
clean(): void;
|
|
58
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import Draw from 'ol/interaction/Draw.js';
|
|
2
|
+
import Overlay from 'ol/Overlay.js';
|
|
3
|
+
import { Circle as CircleStyle, Fill, Stroke, Style } from 'ol/style.js';
|
|
4
|
+
import { LineString, Polygon } from 'ol/geom.js';
|
|
5
|
+
import { Vector as VectorSource } from 'ol/source.js';
|
|
6
|
+
import { Vector as VectorLayer } from 'ol/layer.js';
|
|
7
|
+
import { getArea, getLength } from 'ol/sphere.js';
|
|
8
|
+
import { unByKey } from 'ol/Observable.js';
|
|
9
|
+
/**
|
|
10
|
+
* @classdesc MeausreHandler
|
|
11
|
+
*/
|
|
12
|
+
export default class MeasureHandler {
|
|
13
|
+
constructor(map) {
|
|
14
|
+
this._map = null;
|
|
15
|
+
this._draw = null;
|
|
16
|
+
this.source = new VectorSource();
|
|
17
|
+
this.vector = new VectorLayer({
|
|
18
|
+
source: this.source,
|
|
19
|
+
style: new Style({
|
|
20
|
+
fill: new Fill({
|
|
21
|
+
color: 'rgba(255, 255, 255, 0.2)',
|
|
22
|
+
}),
|
|
23
|
+
stroke: new Stroke({
|
|
24
|
+
color: 'rgba(0, 255, 0, 0.8)',
|
|
25
|
+
lineDash: [10, 10],
|
|
26
|
+
width: 2,
|
|
27
|
+
}),
|
|
28
|
+
image: new CircleStyle({
|
|
29
|
+
radius: 5,
|
|
30
|
+
stroke: new Stroke({
|
|
31
|
+
color: 'rgba(0, 255, 0, 0.8)'
|
|
32
|
+
}),
|
|
33
|
+
fill: new Fill({
|
|
34
|
+
color: 'rgba(255, 255, 255, 0.2)',
|
|
35
|
+
}),
|
|
36
|
+
}),
|
|
37
|
+
}),
|
|
38
|
+
zIndex: 999,
|
|
39
|
+
});
|
|
40
|
+
this._map = map;
|
|
41
|
+
/**
|
|
42
|
+
* Currently drawn feature.
|
|
43
|
+
* @type {import("ol/Feature.js").default}
|
|
44
|
+
*/
|
|
45
|
+
this.sketch = null;
|
|
46
|
+
/**
|
|
47
|
+
* The help tooltip element.
|
|
48
|
+
* @type {HTMLElement}
|
|
49
|
+
*/
|
|
50
|
+
this.helpTooltipElement = null;
|
|
51
|
+
/**
|
|
52
|
+
* Overlay to show the help messages.
|
|
53
|
+
* @type {Overlay}
|
|
54
|
+
*/
|
|
55
|
+
this.helpTooltip = null;
|
|
56
|
+
/**
|
|
57
|
+
* The measure tooltip element.
|
|
58
|
+
* @type {HTMLElement}
|
|
59
|
+
*/
|
|
60
|
+
this.measureTooltipElement = null;
|
|
61
|
+
/**
|
|
62
|
+
* Overlay to show the measurement.
|
|
63
|
+
* @type {Overlay}
|
|
64
|
+
*/
|
|
65
|
+
this.measureTooltip = null;
|
|
66
|
+
/**
|
|
67
|
+
* Message to show when the user is drawing a polygon.
|
|
68
|
+
* @type {string}
|
|
69
|
+
*/
|
|
70
|
+
this.continuePolygonMsg = '双击结束绘制';
|
|
71
|
+
/**
|
|
72
|
+
* Message to show when the user is drawing a line.
|
|
73
|
+
* @type {string}
|
|
74
|
+
*/
|
|
75
|
+
this.continueLineMsg = '双击结束绘制';
|
|
76
|
+
/**
|
|
77
|
+
* contain the the overlays of tips
|
|
78
|
+
* @type {Array}
|
|
79
|
+
*/
|
|
80
|
+
this._tipsCollection = [];
|
|
81
|
+
/**
|
|
82
|
+
*
|
|
83
|
+
* @param evt
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
this._mouseListener = (evt) => {
|
|
87
|
+
if (evt.dragging) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
/** @type {string} */
|
|
91
|
+
let helpMsg = '单击开始绘制';
|
|
92
|
+
if (this.sketch) {
|
|
93
|
+
const geom = this.sketch.getGeometry();
|
|
94
|
+
if (geom instanceof Polygon) {
|
|
95
|
+
helpMsg = this.continuePolygonMsg;
|
|
96
|
+
}
|
|
97
|
+
else if (geom instanceof LineString) {
|
|
98
|
+
helpMsg = this.continueLineMsg;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (this.helpTooltipElement) {
|
|
102
|
+
this.helpTooltipElement.innerHTML = helpMsg;
|
|
103
|
+
}
|
|
104
|
+
this.helpTooltip?.setPosition(evt.coordinate);
|
|
105
|
+
this._map?.addLayer(this.vector);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* destory the object
|
|
110
|
+
*/
|
|
111
|
+
destory() {
|
|
112
|
+
this.clean();
|
|
113
|
+
this._map?.removeLayer(this.vector);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Format length output.
|
|
117
|
+
* @param {LineString} line The line.
|
|
118
|
+
* @return {string} The formatted length.
|
|
119
|
+
*/
|
|
120
|
+
formatLength(line) {
|
|
121
|
+
const length = getLength(line, {
|
|
122
|
+
projection: "EPSG:4326"
|
|
123
|
+
});
|
|
124
|
+
let output;
|
|
125
|
+
if (length > 100) {
|
|
126
|
+
output = Math.round((length / 1000) * 100) / 100 + ' ' + 'km';
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
output = Math.round(length * 100) / 100 + ' ' + 'm';
|
|
130
|
+
}
|
|
131
|
+
return output;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Format area output.
|
|
135
|
+
* @param {Polygon} polygon The polygon.
|
|
136
|
+
* @return {string} Formatted area.
|
|
137
|
+
*/
|
|
138
|
+
formatArea(polygon) {
|
|
139
|
+
const area = getArea(polygon, {
|
|
140
|
+
projection: "EPSG:4326"
|
|
141
|
+
});
|
|
142
|
+
let output;
|
|
143
|
+
if (area > 10000) {
|
|
144
|
+
output = Math.round((area / 1000000) * 100) / 100 + ' ' + 'km<sup>2</sup>';
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
output = Math.round(area * 100) / 100 + ' ' + 'm<sup>2</sup>';
|
|
148
|
+
}
|
|
149
|
+
return output;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
*
|
|
153
|
+
* @param {String} type the values such as 'Polygon','LineString'
|
|
154
|
+
*/
|
|
155
|
+
start(type) {
|
|
156
|
+
if (!this._map) {
|
|
157
|
+
throw new Error("MeasureHandler has not been register to the map");
|
|
158
|
+
}
|
|
159
|
+
this.createMeasureTooltip();
|
|
160
|
+
this.createHelpTooltip();
|
|
161
|
+
if (this._draw) {
|
|
162
|
+
this._map.removeInteraction(this._draw);
|
|
163
|
+
}
|
|
164
|
+
this._draw = new Draw({
|
|
165
|
+
source: this.source,
|
|
166
|
+
type: type,
|
|
167
|
+
style: (feature) => {
|
|
168
|
+
const geometryType = feature.getGeometry()?.getType();
|
|
169
|
+
if (geometryType === type || geometryType === 'Point') {
|
|
170
|
+
return new Style({
|
|
171
|
+
fill: new Fill({
|
|
172
|
+
color: 'rgba(220, 255, 255, 0.2)',
|
|
173
|
+
}),
|
|
174
|
+
stroke: new Stroke({
|
|
175
|
+
color: 'rgba(255, 0, 0, 0.7)',
|
|
176
|
+
lineDash: [10, 10],
|
|
177
|
+
width: 2,
|
|
178
|
+
}),
|
|
179
|
+
image: new CircleStyle({
|
|
180
|
+
radius: 5,
|
|
181
|
+
stroke: new Stroke({
|
|
182
|
+
color: 'rgba(255, 0, 0, 0.7)',
|
|
183
|
+
}),
|
|
184
|
+
fill: new Fill({
|
|
185
|
+
color: 'rgba(255, 255, 255, 0.2)',
|
|
186
|
+
}),
|
|
187
|
+
}),
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
this._map.addInteraction(this._draw);
|
|
193
|
+
let listener;
|
|
194
|
+
this._draw.on('drawstart', (evt) => {
|
|
195
|
+
// set sketch
|
|
196
|
+
this.sketch = evt.feature;
|
|
197
|
+
/** @type {import("ol/coordinate.js").Coordinate|undefined} */
|
|
198
|
+
let tooltipCoord = evt?.coordinate;
|
|
199
|
+
listener = this.sketch.getGeometry().on('change', (evt) => {
|
|
200
|
+
const geom = evt.target;
|
|
201
|
+
let output;
|
|
202
|
+
if (geom instanceof Polygon) {
|
|
203
|
+
output = this.formatArea(geom);
|
|
204
|
+
tooltipCoord = geom.getInteriorPoint().getCoordinates();
|
|
205
|
+
}
|
|
206
|
+
else if (geom instanceof LineString) {
|
|
207
|
+
output = this.formatLength(geom);
|
|
208
|
+
tooltipCoord = geom.getLastCoordinate();
|
|
209
|
+
}
|
|
210
|
+
if (this.measureTooltipElement) {
|
|
211
|
+
this.measureTooltipElement.innerHTML = output;
|
|
212
|
+
}
|
|
213
|
+
this.measureTooltip?.setPosition(tooltipCoord);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
this._draw.on('drawend', () => {
|
|
217
|
+
if (this.measureTooltipElement) {
|
|
218
|
+
this.measureTooltipElement.className = 'ol-tooltip ol-tooltip-static';
|
|
219
|
+
}
|
|
220
|
+
this.measureTooltip?.setOffset([0, -7]);
|
|
221
|
+
// unset sketch
|
|
222
|
+
this.sketch = null;
|
|
223
|
+
// unset tooltip so that a new one can be created
|
|
224
|
+
this.measureTooltipElement = null;
|
|
225
|
+
this.createMeasureTooltip();
|
|
226
|
+
unByKey(listener);
|
|
227
|
+
});
|
|
228
|
+
this._map.on('pointermove', this._mouseListener);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* end the measure drawing
|
|
232
|
+
*/
|
|
233
|
+
end() {
|
|
234
|
+
if (this._draw) {
|
|
235
|
+
this._map?.removeInteraction(this._draw);
|
|
236
|
+
}
|
|
237
|
+
if (this.helpTooltipElement) {
|
|
238
|
+
this.helpTooltipElement.parentNode?.removeChild(this.helpTooltipElement);
|
|
239
|
+
this.helpTooltipElement = null;
|
|
240
|
+
}
|
|
241
|
+
if (this.measureTooltipElement) {
|
|
242
|
+
this.measureTooltipElement.parentNode?.removeChild(this.measureTooltipElement);
|
|
243
|
+
this.measureTooltipElement = null;
|
|
244
|
+
}
|
|
245
|
+
this._map?.un("pointermove", this._mouseListener);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Creates a new help tooltip
|
|
249
|
+
*/
|
|
250
|
+
createHelpTooltip() {
|
|
251
|
+
if (this.helpTooltipElement) {
|
|
252
|
+
this.helpTooltipElement.parentNode?.removeChild(this.helpTooltipElement);
|
|
253
|
+
}
|
|
254
|
+
this.helpTooltipElement = document.createElement('div');
|
|
255
|
+
this.helpTooltipElement.className = 'ol-tooltip';
|
|
256
|
+
this.helpTooltip = new Overlay({
|
|
257
|
+
element: this.helpTooltipElement,
|
|
258
|
+
offset: [15, 0],
|
|
259
|
+
positioning: 'center-left',
|
|
260
|
+
});
|
|
261
|
+
this._map?.addOverlay(this.helpTooltip);
|
|
262
|
+
this._tipsCollection.push(this.helpTooltip);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Creates a new measure tooltip
|
|
266
|
+
*/
|
|
267
|
+
createMeasureTooltip() {
|
|
268
|
+
if (this.measureTooltipElement) {
|
|
269
|
+
this.measureTooltipElement.parentNode?.removeChild(this.measureTooltipElement);
|
|
270
|
+
}
|
|
271
|
+
this.measureTooltipElement = document.createElement('div');
|
|
272
|
+
this.measureTooltipElement.className = 'ol-tooltip ol-tooltip-measure';
|
|
273
|
+
this.measureTooltip = new Overlay({
|
|
274
|
+
element: this.measureTooltipElement,
|
|
275
|
+
offset: [0, -15],
|
|
276
|
+
positioning: 'bottom-center',
|
|
277
|
+
stopEvent: false,
|
|
278
|
+
insertFirst: false,
|
|
279
|
+
});
|
|
280
|
+
this._tipsCollection.push(this.measureTooltip);
|
|
281
|
+
this._map?.addOverlay(this.measureTooltip);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* clean the all result of measure
|
|
285
|
+
*/
|
|
286
|
+
clean() {
|
|
287
|
+
this._tipsCollection.forEach((item) => {
|
|
288
|
+
this._map?.removeOverlay(item);
|
|
289
|
+
});
|
|
290
|
+
this.source.clear(true);
|
|
291
|
+
if (this._draw) {
|
|
292
|
+
this._map?.removeInteraction(this._draw);
|
|
293
|
+
}
|
|
294
|
+
this._tipsCollection = [];
|
|
295
|
+
}
|
|
296
|
+
}
|
package/dist/core/Point.js
CHANGED
|
@@ -68,7 +68,7 @@ export default class Point {
|
|
|
68
68
|
source: new VectorSource({
|
|
69
69
|
features: pointFeatureList
|
|
70
70
|
}),
|
|
71
|
-
zIndex: options.zIndex ||
|
|
71
|
+
zIndex: options.zIndex || 21,
|
|
72
72
|
});
|
|
73
73
|
PointVectorLayer.setVisible(options.visible === undefined ? true : options.visible);
|
|
74
74
|
this.map.addLayer(PointVectorLayer);
|
|
@@ -122,7 +122,7 @@ export default class Point {
|
|
|
122
122
|
}
|
|
123
123
|
return new Style(style);
|
|
124
124
|
},
|
|
125
|
-
zIndex: options.zIndex ||
|
|
125
|
+
zIndex: options.zIndex || 21,
|
|
126
126
|
});
|
|
127
127
|
clusterLayer.setVisible(options.visible === undefined ? true : options.visible);
|
|
128
128
|
this.map.addLayer(clusterLayer);
|
|
@@ -177,7 +177,7 @@ export default class Point {
|
|
|
177
177
|
})
|
|
178
178
|
});
|
|
179
179
|
},
|
|
180
|
-
zIndex:
|
|
180
|
+
zIndex: 21
|
|
181
181
|
});
|
|
182
182
|
this.map.addLayer(basinLayer);
|
|
183
183
|
this.setTwinkleLayer(twinkleList, className, key, (twinkleItem) => {
|
package/dist/core/Polygon.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import VectorLayer from "ol/layer/Vector";
|
|
|
3
3
|
import VectorSource from "ol/source/Vector";
|
|
4
4
|
import { Image as ImageLayer } from "ol/layer";
|
|
5
5
|
import { Geometry } from "ol/geom";
|
|
6
|
-
import { OptionsType, MapJSONData } from '../types';
|
|
6
|
+
import { OptionsType, MapJSONData, PointData, HeatMapOptions } from '../types';
|
|
7
7
|
export default class Polygon {
|
|
8
8
|
map: Map;
|
|
9
9
|
private colorMap;
|
|
@@ -19,21 +19,21 @@ export default class Polygon {
|
|
|
19
19
|
* @param data 图层数据
|
|
20
20
|
* @param options 图层配置
|
|
21
21
|
*/
|
|
22
|
-
addBorderPolygon(data: MapJSONData, options
|
|
22
|
+
addBorderPolygon(data: MapJSONData, options?: OptionsType): void;
|
|
23
23
|
addPolygon(dataJSON: MapJSONData, options?: OptionsType): VectorLayer<VectorSource<Geometry>>;
|
|
24
24
|
/**
|
|
25
25
|
* 根据数据数组更新某个面颜色
|
|
26
26
|
* @param layerName 图层名称
|
|
27
|
-
* @param colorObj 数据
|
|
27
|
+
* @param colorObj 数据 不传或者传{}则重置所有颜色
|
|
28
28
|
* colorObj:{
|
|
29
29
|
* 对应geojson文件中的索引字段[propName]: 'rgba(255, 0, 0, 0.6)', // 颜色
|
|
30
30
|
* ...
|
|
31
31
|
* }
|
|
32
32
|
* @param options 配置项
|
|
33
33
|
*/
|
|
34
|
-
updateFeatureColors(layerName: string, colorObj
|
|
34
|
+
updateFeatureColors(layerName: string, colorObj?: {
|
|
35
35
|
[propName: string]: string;
|
|
36
|
-
}, options
|
|
36
|
+
}, options?: OptionsType): void;
|
|
37
37
|
/**
|
|
38
38
|
* 设置外围蒙版图层
|
|
39
39
|
*
|
|
@@ -57,5 +57,6 @@ export default class Polygon {
|
|
|
57
57
|
* @param options 图层配置
|
|
58
58
|
*/
|
|
59
59
|
addImage(layerName: string, img?: string, extent?: number[], options?: OptionsType): import("ol/layer/Base").default | VectorLayer<VectorSource<Geometry>> | ImageLayer<import("ol/source").Image>;
|
|
60
|
+
addHeatmap(layerName: string, pointData: PointData[], options: HeatMapOptions): void;
|
|
60
61
|
removePolygonLayer(layerName: string): void;
|
|
61
62
|
}
|
package/dist/core/Polygon.js
CHANGED
|
@@ -3,8 +3,8 @@ import VectorLayer from "ol/layer/Vector";
|
|
|
3
3
|
import VectorSource from "ol/source/Vector";
|
|
4
4
|
import GeoJSON from "ol/format/GeoJSON";
|
|
5
5
|
import { Fill, Stroke, Style, Text } from "ol/style";
|
|
6
|
-
import { Image as ImageLayer } from "ol/layer";
|
|
7
|
-
import { Geometry, LinearRing } from "ol/geom";
|
|
6
|
+
import { Image as ImageLayer, Heatmap } from "ol/layer";
|
|
7
|
+
import { Geometry, LinearRing, Point } from "ol/geom";
|
|
8
8
|
import { fromExtent } from "ol/geom/Polygon";
|
|
9
9
|
import Feature from "ol/Feature";
|
|
10
10
|
import ImageStatic from "ol/source/ImageStatic";
|
|
@@ -32,6 +32,7 @@ export default class Polygon {
|
|
|
32
32
|
* @param options 图层配置
|
|
33
33
|
*/
|
|
34
34
|
addBorderPolygon(data, options) {
|
|
35
|
+
options = options ?? {};
|
|
35
36
|
options.type = options.type ?? 'border';
|
|
36
37
|
options.fillColor = options.fillColor ?? 'rgba(255, 255, 255, 0)';
|
|
37
38
|
this.addPolygon(data, options);
|
|
@@ -40,7 +41,8 @@ export default class Polygon {
|
|
|
40
41
|
}
|
|
41
42
|
// 添加分区
|
|
42
43
|
//fyBasinJson中的id的key需要跟options中的nameKey一致
|
|
43
|
-
addPolygon(dataJSON, options
|
|
44
|
+
addPolygon(dataJSON, options) {
|
|
45
|
+
options = options ?? {};
|
|
44
46
|
if (options.type != null) {
|
|
45
47
|
MapTools.removeLayer(this.map, options.type);
|
|
46
48
|
}
|
|
@@ -50,29 +52,52 @@ export default class Polygon {
|
|
|
50
52
|
source: new VectorSource({
|
|
51
53
|
features: (new GeoJSON()).readFeatures(dataJSON, options.projectionOptOptions ?? {})
|
|
52
54
|
}),
|
|
53
|
-
style: function (feature) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
// style: function (feature: any) {
|
|
56
|
+
// feature.set('type', options?.type)
|
|
57
|
+
// feature.set('layerName', options?.type)
|
|
58
|
+
// return new Style({
|
|
59
|
+
// stroke: new Stroke({
|
|
60
|
+
// color: options?.strokeColor ?? '#EBEEF5',
|
|
61
|
+
// width: options?.strokeWidth ?? 2,
|
|
62
|
+
// lineDash: options?.lineDash,
|
|
63
|
+
// lineDashOffset: options?.lineDashOffset
|
|
64
|
+
// }),
|
|
65
|
+
// fill: new Fill({ color: options?.fillColor || 'rgba(255, 255, 255, 0.3)' }),
|
|
66
|
+
// text: new Text({
|
|
67
|
+
// text: options?.textVisible && options.nameKey ? feature.values_[options.nameKey] : "",
|
|
68
|
+
// font: options?.textFont ?? '14px Calibri,sans-serif',
|
|
69
|
+
// fill: new Fill({ color: options?.textFillColor ?? '#FFF' }),
|
|
70
|
+
// stroke: new Stroke({
|
|
71
|
+
// color: options?.textStrokeColor ?? '#409EFF',
|
|
72
|
+
// width: options?.textStrokeWidth ?? 2
|
|
73
|
+
// })
|
|
74
|
+
// })
|
|
75
|
+
// })
|
|
76
|
+
// },
|
|
77
|
+
zIndex: options.zIndex ?? 11
|
|
78
|
+
});
|
|
79
|
+
const features = layer.getSource()?.getFeatures();
|
|
80
|
+
features?.forEach(feature => {
|
|
81
|
+
feature.set('type', options?.type);
|
|
82
|
+
feature.set('layerName', options?.type);
|
|
83
|
+
feature.setStyle(new Style({
|
|
84
|
+
stroke: new Stroke({
|
|
85
|
+
color: options?.strokeColor ?? '#EBEEF5',
|
|
86
|
+
width: options?.strokeWidth ?? 2,
|
|
87
|
+
lineDash: options?.lineDash,
|
|
88
|
+
lineDashOffset: options?.lineDashOffset
|
|
89
|
+
}),
|
|
90
|
+
fill: new Fill({ color: options?.fillColor || 'rgba(255, 255, 255, 0.3)' }),
|
|
91
|
+
text: new Text({
|
|
92
|
+
text: options?.textVisible && options.nameKey ? feature.get(options.nameKey) : "",
|
|
93
|
+
font: options?.textFont ?? '14px Calibri,sans-serif',
|
|
94
|
+
fill: new Fill({ color: options?.textFillColor ?? '#FFF' }),
|
|
57
95
|
stroke: new Stroke({
|
|
58
|
-
color: options
|
|
59
|
-
width: options
|
|
60
|
-
lineDash: options.lineDash,
|
|
61
|
-
lineDashOffset: options.lineDashOffset
|
|
62
|
-
}),
|
|
63
|
-
fill: new Fill({ color: options.fillColor || 'rgba(255, 255, 255, 0.3)' }),
|
|
64
|
-
text: new Text({
|
|
65
|
-
text: options.textVisible && options.nameKey ? feature.values_[options.nameKey] : "",
|
|
66
|
-
font: options.textFont ?? '14px Calibri,sans-serif',
|
|
67
|
-
fill: new Fill({ color: options.textFillColor ?? '#FFF' }),
|
|
68
|
-
stroke: new Stroke({
|
|
69
|
-
color: options.textStrokeColor ?? '#409EFF',
|
|
70
|
-
width: options.textStrokeWidth ?? 2
|
|
71
|
-
})
|
|
96
|
+
color: options?.textStrokeColor ?? '#409EFF',
|
|
97
|
+
width: options?.textStrokeWidth ?? 2
|
|
72
98
|
})
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
zIndex: options.zIndex ?? 2
|
|
99
|
+
})
|
|
100
|
+
}));
|
|
76
101
|
});
|
|
77
102
|
layer.setVisible(options.visible === undefined ? true : options.visible);
|
|
78
103
|
this.map.addLayer(layer);
|
|
@@ -88,7 +113,7 @@ export default class Polygon {
|
|
|
88
113
|
/**
|
|
89
114
|
* 根据数据数组更新某个面颜色
|
|
90
115
|
* @param layerName 图层名称
|
|
91
|
-
* @param colorObj 数据
|
|
116
|
+
* @param colorObj 数据 不传或者传{}则重置所有颜色
|
|
92
117
|
* colorObj:{
|
|
93
118
|
* 对应geojson文件中的索引字段[propName]: 'rgba(255, 0, 0, 0.6)', // 颜色
|
|
94
119
|
* ...
|
|
@@ -98,30 +123,31 @@ export default class Polygon {
|
|
|
98
123
|
updateFeatureColors(layerName, colorObj, options) {
|
|
99
124
|
const layer = MapTools.getLayerByLayerName(this.map, layerName)[0];
|
|
100
125
|
if (layer instanceof VectorLayer) {
|
|
101
|
-
const
|
|
102
|
-
const features = source.getFeatures();
|
|
126
|
+
const features = layer.getSource()?.getFeatures();
|
|
103
127
|
features.forEach((feature) => {
|
|
104
|
-
if (options.
|
|
105
|
-
const name = feature
|
|
106
|
-
const newColor = colorObj[name];
|
|
107
|
-
|
|
108
|
-
|
|
128
|
+
if (options?.nameKey || (!colorObj || Object.keys(colorObj).length === 0)) {
|
|
129
|
+
const name = options?.nameKey ? feature.get(options.nameKey) : '';
|
|
130
|
+
const newColor = colorObj?.[name];
|
|
131
|
+
// const oldStyle = feature.getStyle()
|
|
132
|
+
// console.log(oldStyle)
|
|
133
|
+
// if (newColor) {
|
|
134
|
+
feature.setStyle(new Style({
|
|
135
|
+
stroke: new Stroke({
|
|
136
|
+
color: options?.strokeColor ?? '#EBEEF5',
|
|
137
|
+
width: options?.strokeWidth ?? 2
|
|
138
|
+
}),
|
|
139
|
+
fill: new Fill({ color: newColor || options?.fillColor || 'rgba(255, 255, 255, 0.3)' }),
|
|
140
|
+
text: new Text({
|
|
141
|
+
text: options?.textVisible === false ? "" : name,
|
|
142
|
+
font: options?.textFont ?? '14px Calibri,sans-serif',
|
|
143
|
+
fill: new Fill({ color: options?.textFillColor || '#FFF' }),
|
|
109
144
|
stroke: new Stroke({
|
|
110
|
-
color: options
|
|
111
|
-
width: options
|
|
112
|
-
}),
|
|
113
|
-
fill: new Fill({ color: newColor }),
|
|
114
|
-
text: new Text({
|
|
115
|
-
text: options.textVisible === false ? "" : name,
|
|
116
|
-
font: options.textFont ?? '14px Calibri,sans-serif',
|
|
117
|
-
fill: new Fill({ color: options.textFillColor || '#FFF' }),
|
|
118
|
-
stroke: new Stroke({
|
|
119
|
-
color: options.textStrokeColor ?? '#409EFF',
|
|
120
|
-
width: options.textStrokeWidth ?? 2
|
|
121
|
-
})
|
|
145
|
+
color: options?.textStrokeColor ?? '#409EFF',
|
|
146
|
+
width: options?.textStrokeWidth ?? 2
|
|
122
147
|
})
|
|
123
|
-
})
|
|
124
|
-
}
|
|
148
|
+
})
|
|
149
|
+
}));
|
|
150
|
+
// }
|
|
125
151
|
}
|
|
126
152
|
});
|
|
127
153
|
}
|
|
@@ -203,7 +229,7 @@ export default class Polygon {
|
|
|
203
229
|
const vtLayer = new VectorLayer({
|
|
204
230
|
source: vtSource,
|
|
205
231
|
style: shadeStyle,
|
|
206
|
-
zIndex: options?.zIndex ??
|
|
232
|
+
zIndex: options?.zIndex ?? 12
|
|
207
233
|
});
|
|
208
234
|
this.map.addLayer(vtLayer);
|
|
209
235
|
const features = new GeoJSON().readFeatures(data);
|
|
@@ -223,7 +249,7 @@ export default class Polygon {
|
|
|
223
249
|
* @param extent 图片范围(对角线坐标) [minx, miny, maxx, maxy]
|
|
224
250
|
* @param options 图层配置
|
|
225
251
|
*/
|
|
226
|
-
addImage(layerName, img, extent, options
|
|
252
|
+
addImage(layerName, img, extent, options) {
|
|
227
253
|
let imageLayer = MapTools.getLayerByLayerName(this.map, layerName)[0];
|
|
228
254
|
if (img && extent) {
|
|
229
255
|
const source = new ImageStatic({
|
|
@@ -239,12 +265,12 @@ export default class Polygon {
|
|
|
239
265
|
imageLayer.set('layerName', layerName);
|
|
240
266
|
if (imageLayer instanceof ImageLayer)
|
|
241
267
|
imageLayer.setSource(source);
|
|
242
|
-
imageLayer.setZIndex(options
|
|
243
|
-
imageLayer.setOpacity(options
|
|
244
|
-
if (options
|
|
245
|
-
imageLayer.setVisible(options
|
|
246
|
-
if (options
|
|
247
|
-
imageLayer = MapTools.setMapClip(imageLayer, options
|
|
268
|
+
imageLayer.setZIndex(options?.zIndex ?? 11);
|
|
269
|
+
imageLayer.setOpacity(options?.opacity ?? 1);
|
|
270
|
+
if (options?.visible !== undefined)
|
|
271
|
+
imageLayer.setVisible(options?.visible);
|
|
272
|
+
if (options?.mapClip && options?.mapClipData) {
|
|
273
|
+
imageLayer = MapTools.setMapClip(imageLayer, options?.mapClipData);
|
|
248
274
|
}
|
|
249
275
|
this.map.addLayer(imageLayer);
|
|
250
276
|
}
|
|
@@ -254,6 +280,27 @@ export default class Polygon {
|
|
|
254
280
|
}
|
|
255
281
|
return imageLayer;
|
|
256
282
|
}
|
|
283
|
+
addHeatmap(layerName, pointData, options) {
|
|
284
|
+
const heatmapLayer = new Heatmap({
|
|
285
|
+
source: new VectorSource(),
|
|
286
|
+
weight: function (fea) {
|
|
287
|
+
return fea.get('weight');
|
|
288
|
+
},
|
|
289
|
+
blur: options.blur ?? 15,
|
|
290
|
+
radius: options.radius ?? 10,
|
|
291
|
+
zIndex: options.zIndex ?? 11,
|
|
292
|
+
opacity: options.opacity ?? 1,
|
|
293
|
+
});
|
|
294
|
+
heatmapLayer.set('layerName', layerName);
|
|
295
|
+
this.map.addLayer(heatmapLayer);
|
|
296
|
+
const max = Math.max(...pointData.map(item => item[options.valueKey]));
|
|
297
|
+
pointData.forEach((item) => {
|
|
298
|
+
heatmapLayer?.getSource().addFeature(new Feature({
|
|
299
|
+
geometry: new Point([item.lgtd, item.lttd]),
|
|
300
|
+
weight: item[options.valueKey] / max //热力值范围是【0,1】;热力值计算 = 找出数据集中的最大值,然后用值除以最大值
|
|
301
|
+
}));
|
|
302
|
+
});
|
|
303
|
+
}
|
|
257
304
|
removePolygonLayer(layerName) {
|
|
258
305
|
MapTools.removeLayer(this.map, layerName);
|
|
259
306
|
this[layerName] = null;
|
package/dist/types.d.ts
CHANGED
|
@@ -48,6 +48,15 @@ export interface AnnotationLayerOptions {
|
|
|
48
48
|
zIndex?: number;
|
|
49
49
|
visible?: boolean;
|
|
50
50
|
}
|
|
51
|
+
export interface HeatMapOptions {
|
|
52
|
+
radius?: number;
|
|
53
|
+
blur?: number;
|
|
54
|
+
gradient?: string[];
|
|
55
|
+
opacity?: number;
|
|
56
|
+
visible?: boolean;
|
|
57
|
+
zIndex?: number;
|
|
58
|
+
valueKey: string;
|
|
59
|
+
}
|
|
51
60
|
export interface OptionsType {
|
|
52
61
|
type?: string;
|
|
53
62
|
nameKey?: string;
|
|
@@ -81,3 +90,4 @@ export interface PointData {
|
|
|
81
90
|
lttd: number;
|
|
82
91
|
[propName: string]: any;
|
|
83
92
|
}
|
|
93
|
+
export type MeasureHandlerType = 'Polygon' | 'LineString';
|