my-openlayer 0.1.3 → 0.1.4
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/dist/MyOl.d.ts +0 -6
- package/dist/MyOl.js +0 -60
- package/dist/core/DomPoint.d.ts +2 -2
- package/dist/core/Line.d.ts +1 -1
- package/dist/core/Line.js +2 -2
- package/dist/core/MapTools.d.ts +27 -2
- package/dist/core/MapTools.js +48 -6
- package/dist/core/Point.d.ts +3 -8
- package/dist/core/Point.js +25 -38
- package/dist/core/Polygon.d.ts +5 -3
- package/dist/core/Polygon.js +18 -17
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
package/dist/MyOl.d.ts
CHANGED
|
@@ -64,10 +64,4 @@ export default class MyOl {
|
|
|
64
64
|
* @param callback 回调函数
|
|
65
65
|
*/
|
|
66
66
|
mapOnEvent(eventType: string | undefined, callback: (feature?: any, e?: any) => void, clickType?: 'point' | 'line' | 'polygon' | undefined): void;
|
|
67
|
-
/**
|
|
68
|
-
* 隐藏&展示图层
|
|
69
|
-
* @param layerName 图层名称
|
|
70
|
-
* @param show 是否显示
|
|
71
|
-
*/
|
|
72
|
-
showMapLayer(layerName: string, show?: boolean): boolean;
|
|
73
67
|
}
|
package/dist/MyOl.js
CHANGED
|
@@ -21,8 +21,6 @@ class MyOl {
|
|
|
21
21
|
if (Array.isArray(options.layers)) {
|
|
22
22
|
layers = options.layers;
|
|
23
23
|
}
|
|
24
|
-
else {
|
|
25
|
-
}
|
|
26
24
|
this.map = new Map({
|
|
27
25
|
target: id, // 地图容器
|
|
28
26
|
view: MyOl.getView(this.options), // 视图
|
|
@@ -55,7 +53,6 @@ class MyOl {
|
|
|
55
53
|
units: "degrees"
|
|
56
54
|
});
|
|
57
55
|
olProjAddProjection(cgsc2000);
|
|
58
|
-
// debugger
|
|
59
56
|
// 视图配置
|
|
60
57
|
const viewOptions = {
|
|
61
58
|
projection: cgsc2000, // 坐标系
|
|
@@ -156,63 +153,6 @@ class MyOl {
|
|
|
156
153
|
mapOnEvent(eventType = "def", callback, clickType) {
|
|
157
154
|
MapTools.mapOnEvent(this.map, eventType, callback, clickType);
|
|
158
155
|
}
|
|
159
|
-
/**
|
|
160
|
-
* 隐藏&展示图层
|
|
161
|
-
* @param layerName 图层名称
|
|
162
|
-
* @param show 是否显示
|
|
163
|
-
*/
|
|
164
|
-
showMapLayer(layerName, show = true) {
|
|
165
|
-
if (!layerName) {
|
|
166
|
-
console.error("缺少图层名称");
|
|
167
|
-
return false;
|
|
168
|
-
}
|
|
169
|
-
let layers = this.getTools().getLayerByLayerName(layerName);
|
|
170
|
-
if (!Array.isArray(layers))
|
|
171
|
-
layers = [layers];
|
|
172
|
-
// 无图层返回不继续操作
|
|
173
|
-
if (layers.length === 0)
|
|
174
|
-
return false;
|
|
175
|
-
const zoom = this.map.getView().getZoom();
|
|
176
|
-
for (const layer of layers) {
|
|
177
|
-
if (layer) {
|
|
178
|
-
if (layer.getVisible() === show)
|
|
179
|
-
return false; // 相同则不处理
|
|
180
|
-
const layerName = layer.values_.layerName;
|
|
181
|
-
let isMoreLayer = false;
|
|
182
|
-
// 若为打开,查找是否按层级显示的图层
|
|
183
|
-
if (show) {
|
|
184
|
-
for (let i = 2; i <= 5; i++) {
|
|
185
|
-
if (["reservoir_frgrd_" + i, "city_frgrd_" + i, "rain_frgrd_" + i].includes(layerName)) {
|
|
186
|
-
let minZoom = 10;
|
|
187
|
-
switch (i) {
|
|
188
|
-
case 2:
|
|
189
|
-
minZoom = 10;
|
|
190
|
-
break;
|
|
191
|
-
case 3:
|
|
192
|
-
minZoom = 11;
|
|
193
|
-
break;
|
|
194
|
-
case 4:
|
|
195
|
-
minZoom = 12;
|
|
196
|
-
break;
|
|
197
|
-
case 5:
|
|
198
|
-
minZoom = 13;
|
|
199
|
-
break;
|
|
200
|
-
}
|
|
201
|
-
isMoreLayer = true; // 有进入,单下面未进入则代表不显示与下面的continue使用
|
|
202
|
-
if (zoom && (zoom > minZoom && zoom < 20)) {
|
|
203
|
-
layer.setVisible(true);
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
if (!isMoreLayer) {
|
|
210
|
-
layer.setVisible(show);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return true;
|
|
215
|
-
}
|
|
216
156
|
}
|
|
217
157
|
MyOl.DefaultOptions = {
|
|
218
158
|
layers: undefined,
|
package/dist/core/DomPoint.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ interface Options {
|
|
|
12
12
|
export default class DomPoint {
|
|
13
13
|
private map;
|
|
14
14
|
private app;
|
|
15
|
-
private anchor;
|
|
16
|
-
private dom;
|
|
15
|
+
private readonly anchor;
|
|
16
|
+
private readonly dom;
|
|
17
17
|
constructor(map: Map, options: Options);
|
|
18
18
|
setVisible(visible: boolean): void;
|
|
19
19
|
remove(): void;
|
package/dist/core/Line.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export default class Line {
|
|
|
9
9
|
riverLayerShow: boolean;
|
|
10
10
|
[propertyName: string]: any;
|
|
11
11
|
constructor(map: Map);
|
|
12
|
-
|
|
12
|
+
addLine(data: MapJSONData, options: OptionsType): VectorLayer<VectorSource<import("ol/geom").Geometry>>;
|
|
13
13
|
addRiverLayersByZoom(fyRiverJson: MapJSONData, options?: OptionsType): void;
|
|
14
14
|
showRiverLayer(show: boolean): void;
|
|
15
15
|
showRiverLayerByZoom(): void;
|
package/dist/core/Line.js
CHANGED
|
@@ -9,7 +9,7 @@ export default class Line {
|
|
|
9
9
|
this.riverLayerShow = false;
|
|
10
10
|
this.map = map;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
addLine(data, options) {
|
|
13
13
|
const layer = new VectorLayer({
|
|
14
14
|
name: options.type,
|
|
15
15
|
layerName: options.type,
|
|
@@ -22,7 +22,7 @@ export default class Line {
|
|
|
22
22
|
return new Style({
|
|
23
23
|
stroke: new Stroke({
|
|
24
24
|
color: options.strokeColor || 'rgba(3, 122, 255, 1)',
|
|
25
|
-
width: options.strokeWidth ||
|
|
25
|
+
width: options.strokeWidth || 2
|
|
26
26
|
}),
|
|
27
27
|
});
|
|
28
28
|
},
|
package/dist/core/MapTools.d.ts
CHANGED
|
@@ -1,18 +1,43 @@
|
|
|
1
1
|
import Map from "ol/Map";
|
|
2
2
|
import { MapJSONData } from "../types";
|
|
3
|
+
import VectorLayer from "ol/layer/Vector";
|
|
4
|
+
import VectorSource from "ol/source/Vector";
|
|
5
|
+
import BaseLayer from "ol/layer/Base";
|
|
6
|
+
import ImageLayer from "ol/layer/Image";
|
|
7
|
+
import ImageSource from "ol/source/Image";
|
|
3
8
|
export default class MapTools {
|
|
4
|
-
private map;
|
|
9
|
+
private readonly map;
|
|
5
10
|
constructor(map: Map);
|
|
6
11
|
/**
|
|
7
12
|
* 根据名称获取图层
|
|
8
13
|
* @param layerName 图层名称
|
|
9
14
|
*/
|
|
10
|
-
getLayerByLayerName(layerName: string):
|
|
15
|
+
getLayerByLayerName(layerName: string): (BaseLayer | VectorLayer<VectorSource<import("ol/geom").Geometry>> | ImageLayer<ImageSource>)[];
|
|
16
|
+
static getLayerByLayerName(map: Map, layerName: string): (BaseLayer | VectorLayer<VectorSource<import("ol/geom").Geometry>> | ImageLayer<ImageSource>)[];
|
|
11
17
|
/**
|
|
12
18
|
* 设置地图裁剪
|
|
13
19
|
*/
|
|
14
20
|
static setMapClip(baseLayer: any, data: MapJSONData): any;
|
|
21
|
+
/**
|
|
22
|
+
* 移除图层
|
|
23
|
+
* @param layerName 图层名称
|
|
24
|
+
*/
|
|
15
25
|
removeLayer(layerName: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* 移除图层
|
|
28
|
+
* @param map 地图对象
|
|
29
|
+
* @param layerName 图层名称
|
|
30
|
+
*/
|
|
31
|
+
static removeLayer(map: Map, layerName: string): void;
|
|
32
|
+
setLayerVisible(layerName: string, visible: boolean): void;
|
|
33
|
+
/**
|
|
34
|
+
* 设置图层可见性
|
|
35
|
+
* @param map
|
|
36
|
+
* @param layerName 图层名称
|
|
37
|
+
* @param visible 是否可见
|
|
38
|
+
*/
|
|
39
|
+
static setLayerVisible: (map: Map, layerName: string, visible: boolean) => void;
|
|
40
|
+
mapOnEvent(eventType: string, callback: (feature?: any, e?: any) => void, clickType?: 'point' | 'line' | 'polygon' | undefined): void;
|
|
16
41
|
/**
|
|
17
42
|
* 地图监听事件
|
|
18
43
|
* @param map
|
package/dist/core/MapTools.js
CHANGED
|
@@ -4,7 +4,7 @@ import VectorSource from "ol/source/Vector";
|
|
|
4
4
|
import GeoJSON from "ol/format/GeoJSON";
|
|
5
5
|
import { Fill, Style } from "ol/style";
|
|
6
6
|
import { getVectorContext } from "ol/render";
|
|
7
|
-
|
|
7
|
+
class MapTools {
|
|
8
8
|
constructor(map) {
|
|
9
9
|
this.map = map;
|
|
10
10
|
}
|
|
@@ -14,17 +14,19 @@ export default class MapTools {
|
|
|
14
14
|
*/
|
|
15
15
|
getLayerByLayerName(layerName) {
|
|
16
16
|
if (!this.map)
|
|
17
|
-
return
|
|
17
|
+
return [];
|
|
18
|
+
return MapTools.getLayerByLayerName(this.map, layerName);
|
|
19
|
+
}
|
|
20
|
+
static getLayerByLayerName(map, layerName) {
|
|
18
21
|
const targetLayer = [];
|
|
19
|
-
const layers =
|
|
22
|
+
const layers = map.getLayers().getArray();
|
|
20
23
|
Object.keys(layers).forEach(function (key) {
|
|
21
24
|
const _layerName = layers[key]['values_'].layerName;
|
|
22
|
-
// if (_layerName && _layerName.toString().includes(layerName)) {
|
|
23
25
|
if (_layerName && _layerName === layerName) {
|
|
24
26
|
targetLayer.push(layers[key]);
|
|
25
27
|
}
|
|
26
28
|
});
|
|
27
|
-
return targetLayer
|
|
29
|
+
return targetLayer;
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
30
32
|
* 设置地图裁剪
|
|
@@ -60,8 +62,35 @@ export default class MapTools {
|
|
|
60
62
|
});
|
|
61
63
|
return baseLayer;
|
|
62
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* 移除图层
|
|
67
|
+
* @param layerName 图层名称
|
|
68
|
+
*/
|
|
63
69
|
removeLayer(layerName) {
|
|
64
|
-
this.map
|
|
70
|
+
if (!this.map)
|
|
71
|
+
return;
|
|
72
|
+
MapTools.removeLayer(this.map, layerName);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 移除图层
|
|
76
|
+
* @param map 地图对象
|
|
77
|
+
* @param layerName 图层名称
|
|
78
|
+
*/
|
|
79
|
+
static removeLayer(map, layerName) {
|
|
80
|
+
const layers = MapTools.getLayerByLayerName(map, layerName);
|
|
81
|
+
layers.forEach(layer => {
|
|
82
|
+
map.removeLayer(layer);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
setLayerVisible(layerName, visible) {
|
|
86
|
+
if (!this.map)
|
|
87
|
+
return;
|
|
88
|
+
MapTools.setLayerVisible(this.map, layerName, visible);
|
|
89
|
+
}
|
|
90
|
+
mapOnEvent(eventType, callback, clickType) {
|
|
91
|
+
if (!this.map)
|
|
92
|
+
return;
|
|
93
|
+
MapTools.mapOnEvent(this.map, eventType, callback, clickType);
|
|
65
94
|
}
|
|
66
95
|
/**
|
|
67
96
|
* 地图监听事件
|
|
@@ -104,3 +133,16 @@ export default class MapTools {
|
|
|
104
133
|
}
|
|
105
134
|
}
|
|
106
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* 设置图层可见性
|
|
138
|
+
* @param map
|
|
139
|
+
* @param layerName 图层名称
|
|
140
|
+
* @param visible 是否可见
|
|
141
|
+
*/
|
|
142
|
+
MapTools.setLayerVisible = (map, layerName, visible) => {
|
|
143
|
+
const layers = MapTools.getLayerByLayerName(map, layerName);
|
|
144
|
+
layers.forEach(layer => {
|
|
145
|
+
layer.setVisible(visible);
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
export default MapTools;
|
package/dist/core/Point.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Map from "ol/Map";
|
|
2
2
|
import VectorLayer from "ol/layer/Vector";
|
|
3
3
|
import VectorSource from "ol/source/Vector";
|
|
4
|
-
import { OptionsType, PointData } from '../types';
|
|
4
|
+
import { MapJSONData, OptionsType, PointData } from '../types';
|
|
5
5
|
export default class Point {
|
|
6
6
|
private map;
|
|
7
7
|
constructor(map: Map);
|
|
@@ -16,13 +16,8 @@ export default class Point {
|
|
|
16
16
|
* }
|
|
17
17
|
*/
|
|
18
18
|
addPoint(pointData: PointData[], options: OptionsType): VectorLayer<VectorSource<import("ol/geom").Geometry>>;
|
|
19
|
-
addClusterPoint(pointData:
|
|
20
|
-
|
|
21
|
-
* 添加点 - 闪烁
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
addFlashWarnPoint(img: any): void;
|
|
25
|
-
setTwinkleLayerFromPolygon(twinkleList: any[], className: string, key: string, json: any): void;
|
|
19
|
+
addClusterPoint(pointData: PointData[], options: OptionsType): void;
|
|
20
|
+
setTwinkleLayerFromPolygon(twinkleList: any[], className: string, key: string, json: MapJSONData): void;
|
|
26
21
|
/**
|
|
27
22
|
* 设置闪烁点
|
|
28
23
|
* @param twinkleList 闪烁点数据 - 二维数组 [[],[]]
|
package/dist/core/Point.js
CHANGED
|
@@ -55,8 +55,8 @@ export default class Point {
|
|
|
55
55
|
src: options.img,
|
|
56
56
|
scale: options.scale ?? 1,
|
|
57
57
|
};
|
|
58
|
-
if (options.
|
|
59
|
-
iconOptions.color = options.
|
|
58
|
+
if (options.iconColor) {
|
|
59
|
+
iconOptions.color = options.iconColor;
|
|
60
60
|
}
|
|
61
61
|
style.image = new Icon(iconOptions);
|
|
62
62
|
}
|
|
@@ -94,52 +94,39 @@ export default class Point {
|
|
|
94
94
|
layerName: options.type,
|
|
95
95
|
source: clusterSource,
|
|
96
96
|
style: function (feature) {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
text: aviValue,
|
|
104
|
-
font: '12px Calibri,sans-serif',
|
|
97
|
+
const name = feature.get('features')[0].get(options.nameKey);
|
|
98
|
+
const style = {};
|
|
99
|
+
if (options.nameKey) {
|
|
100
|
+
style.text = new Text({
|
|
101
|
+
text: name,
|
|
102
|
+
font: options.textFont || '12px Calibri,sans-serif',
|
|
105
103
|
fill: new Fill({
|
|
106
|
-
color: '#FFF'
|
|
104
|
+
color: options.textFillColor || '#FFF'
|
|
107
105
|
}),
|
|
108
106
|
stroke: new Stroke({
|
|
109
|
-
color: '#000',
|
|
110
|
-
width: 3
|
|
107
|
+
color: options.textStrokeColor || '#000',
|
|
108
|
+
width: options.textStrokeWidth || 3
|
|
111
109
|
}),
|
|
112
|
-
offsetY: 20,
|
|
113
|
-
})
|
|
114
|
-
}
|
|
110
|
+
offsetY: options.textOffsetY || 20,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (options.hasImg || options.hasImg === undefined) {
|
|
114
|
+
const iconOptions = {
|
|
115
|
+
src: options.img,
|
|
116
|
+
scale: options.scale ?? 1,
|
|
117
|
+
};
|
|
118
|
+
if (options.iconColor) {
|
|
119
|
+
iconOptions.color = options.iconColor;
|
|
120
|
+
}
|
|
121
|
+
style.image = new Icon(iconOptions);
|
|
122
|
+
}
|
|
123
|
+
return new Style(style);
|
|
115
124
|
},
|
|
116
125
|
zIndex: options.zIndex || 4,
|
|
117
126
|
});
|
|
118
127
|
clusterLayer.setVisible(options.visible === undefined ? true : options.visible);
|
|
119
128
|
this.map.addLayer(clusterLayer);
|
|
120
129
|
}
|
|
121
|
-
/**
|
|
122
|
-
* 添加点 - 闪烁
|
|
123
|
-
*
|
|
124
|
-
*/
|
|
125
|
-
addFlashWarnPoint(img) {
|
|
126
|
-
const flashIconLayer = new VectorLayer({
|
|
127
|
-
source: new VectorSource({
|
|
128
|
-
features: [
|
|
129
|
-
new Feature({
|
|
130
|
-
geometry: new olPoint([119.81, 29.969]),
|
|
131
|
-
})
|
|
132
|
-
]
|
|
133
|
-
}),
|
|
134
|
-
style: new Style({
|
|
135
|
-
image: new Icon({
|
|
136
|
-
src: img,
|
|
137
|
-
})
|
|
138
|
-
}),
|
|
139
|
-
zIndex: 99
|
|
140
|
-
});
|
|
141
|
-
this.map.addLayer(flashIconLayer);
|
|
142
|
-
}
|
|
143
130
|
// 在流域中心添加闪烁点位
|
|
144
131
|
setTwinkleLayerFromPolygon(twinkleList, className, key, json) {
|
|
145
132
|
new MapTools(this.map).removeLayer('twinklePoint');
|
package/dist/core/Polygon.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Map from "ol/Map";
|
|
2
2
|
import VectorLayer from "ol/layer/Vector";
|
|
3
3
|
import VectorSource from "ol/source/Vector";
|
|
4
|
+
import { Image as ImageLayer } from "ol/layer";
|
|
4
5
|
import { Geometry } from "ol/geom";
|
|
5
6
|
import { OptionsType, MapJSONData } from '../types';
|
|
6
7
|
export default class Polygon {
|
|
@@ -18,8 +19,8 @@ export default class Polygon {
|
|
|
18
19
|
* @param data 图层数据
|
|
19
20
|
* @param options 图层配置
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
addBorderPolygon(data: MapJSONData, options: OptionsType): void;
|
|
23
|
+
addPolygon(dataJSON: MapJSONData, options?: OptionsType): VectorLayer<VectorSource<Geometry>>;
|
|
23
24
|
/**
|
|
24
25
|
* 根据数据数组更新某个面颜色
|
|
25
26
|
* @param layerName 图层名称
|
|
@@ -46,6 +47,7 @@ export default class Polygon {
|
|
|
46
47
|
fillColor?: string;
|
|
47
48
|
strokeWidth?: number;
|
|
48
49
|
strokeColor?: string;
|
|
50
|
+
zIndex?: number;
|
|
49
51
|
}): void;
|
|
50
52
|
/**
|
|
51
53
|
* 添加图片图层
|
|
@@ -54,6 +56,6 @@ export default class Polygon {
|
|
|
54
56
|
* @param extent 图片范围(对角线坐标) [minx, miny, maxx, maxy]
|
|
55
57
|
* @param options 图层配置
|
|
56
58
|
*/
|
|
57
|
-
|
|
59
|
+
addImage(layerName: string, img?: string, extent?: number[], options?: OptionsType): import("ol/layer/Base").default | VectorLayer<VectorSource<Geometry>> | ImageLayer<import("ol/source").Image>;
|
|
58
60
|
removePolygonLayer(layerName: string): void;
|
|
59
61
|
}
|
package/dist/core/Polygon.js
CHANGED
|
@@ -31,18 +31,18 @@ export default class Polygon {
|
|
|
31
31
|
* @param data 图层数据
|
|
32
32
|
* @param options 图层配置
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
addBorderPolygon(data, options) {
|
|
35
35
|
options.type = options.type ?? 'border';
|
|
36
36
|
options.fillColor = options.fillColor ?? 'rgba(255, 255, 255, 0)';
|
|
37
|
-
this.
|
|
37
|
+
this.addPolygon(data, options);
|
|
38
38
|
if (options.mask)
|
|
39
39
|
this.setOutLayer(data);
|
|
40
40
|
}
|
|
41
41
|
// 添加分区
|
|
42
42
|
//fyBasinJson中的id的key需要跟options中的nameKey一致
|
|
43
|
-
|
|
43
|
+
addPolygon(dataJSON, options = {}) {
|
|
44
44
|
if (options.type != null) {
|
|
45
|
-
|
|
45
|
+
MapTools.removeLayer(this.map, options.type);
|
|
46
46
|
}
|
|
47
47
|
const layer = new VectorLayer({
|
|
48
48
|
name: options.type,
|
|
@@ -56,13 +56,13 @@ export default class Polygon {
|
|
|
56
56
|
return new Style({
|
|
57
57
|
stroke: new Stroke({
|
|
58
58
|
color: options.strokeColor ?? '#EBEEF5',
|
|
59
|
-
width: options.strokeWidth ??
|
|
59
|
+
width: options.strokeWidth ?? 2,
|
|
60
60
|
lineDash: options.lineDash,
|
|
61
61
|
lineDashOffset: options.lineDashOffset
|
|
62
62
|
}),
|
|
63
63
|
fill: new Fill({ color: options.fillColor || 'rgba(255, 255, 255, 0.3)' }),
|
|
64
64
|
text: new Text({
|
|
65
|
-
text: options.nameKey ? feature.values_[options.nameKey] : "",
|
|
65
|
+
text: options.textVisible && options.nameKey ? feature.values_[options.nameKey] : "",
|
|
66
66
|
font: options.textFont ?? '14px Calibri,sans-serif',
|
|
67
67
|
fill: new Fill({ color: options.textFillColor ?? '#FFF' }),
|
|
68
68
|
stroke: new Stroke({
|
|
@@ -96,7 +96,7 @@ export default class Polygon {
|
|
|
96
96
|
* @param options 配置项
|
|
97
97
|
*/
|
|
98
98
|
updateFeatureColors(layerName, colorObj, options) {
|
|
99
|
-
const layer = this.map
|
|
99
|
+
const layer = MapTools.getLayerByLayerName(this.map, layerName)[0];
|
|
100
100
|
if (layer instanceof VectorLayer) {
|
|
101
101
|
const source = layer.getSource();
|
|
102
102
|
const features = source.getFeatures();
|
|
@@ -108,7 +108,7 @@ export default class Polygon {
|
|
|
108
108
|
feature.setStyle(new Style({
|
|
109
109
|
stroke: new Stroke({
|
|
110
110
|
color: options.strokeColor ?? '#EBEEF5',
|
|
111
|
-
width: options.strokeWidth ??
|
|
111
|
+
width: options.strokeWidth ?? 2
|
|
112
112
|
}),
|
|
113
113
|
fill: new Fill({ color: newColor }),
|
|
114
114
|
text: new Text({
|
|
@@ -203,7 +203,7 @@ export default class Polygon {
|
|
|
203
203
|
const vtLayer = new VectorLayer({
|
|
204
204
|
source: vtSource,
|
|
205
205
|
style: shadeStyle,
|
|
206
|
-
zIndex: 99
|
|
206
|
+
zIndex: options?.zIndex ?? 99
|
|
207
207
|
});
|
|
208
208
|
this.map.addLayer(vtLayer);
|
|
209
209
|
const features = new GeoJSON().readFeatures(data);
|
|
@@ -223,20 +223,22 @@ export default class Polygon {
|
|
|
223
223
|
* @param extent 图片范围(对角线坐标) [minx, miny, maxx, maxy]
|
|
224
224
|
* @param options 图层配置
|
|
225
225
|
*/
|
|
226
|
-
|
|
226
|
+
addImage(layerName, img, extent, options = { zIndex: 3 }) {
|
|
227
|
+
let imageLayer = MapTools.getLayerByLayerName(this.map, layerName)[0];
|
|
227
228
|
if (img && extent) {
|
|
228
229
|
const source = new ImageStatic({
|
|
229
230
|
url: img,
|
|
230
231
|
imageExtent: extent
|
|
231
232
|
});
|
|
232
|
-
if (
|
|
233
|
-
|
|
233
|
+
if (imageLayer && imageLayer instanceof ImageLayer) {
|
|
234
|
+
imageLayer.setSource(source);
|
|
234
235
|
}
|
|
235
236
|
else {
|
|
236
|
-
|
|
237
|
+
imageLayer = new ImageLayer();
|
|
237
238
|
imageLayer.set('name', layerName);
|
|
238
239
|
imageLayer.set('layerName', layerName);
|
|
239
|
-
imageLayer
|
|
240
|
+
if (imageLayer instanceof ImageLayer)
|
|
241
|
+
imageLayer.setSource(source);
|
|
240
242
|
imageLayer.setZIndex(options.zIndex ?? 3);
|
|
241
243
|
imageLayer.setOpacity(options.opacity ?? 1);
|
|
242
244
|
if (options.visible !== undefined)
|
|
@@ -245,16 +247,15 @@ export default class Polygon {
|
|
|
245
247
|
imageLayer = MapTools.setMapClip(imageLayer, options.mapClipData);
|
|
246
248
|
}
|
|
247
249
|
this.map.addLayer(imageLayer);
|
|
248
|
-
this[layerName] = imageLayer;
|
|
249
250
|
}
|
|
250
251
|
}
|
|
251
252
|
else {
|
|
252
253
|
this.removePolygonLayer(layerName);
|
|
253
254
|
}
|
|
254
|
-
return
|
|
255
|
+
return imageLayer;
|
|
255
256
|
}
|
|
256
257
|
removePolygonLayer(layerName) {
|
|
257
|
-
|
|
258
|
+
MapTools.removeLayer(this.map, layerName);
|
|
258
259
|
this[layerName] = null;
|
|
259
260
|
}
|
|
260
261
|
}
|
package/dist/types.d.ts
CHANGED