my-openlayer 0.1.2 → 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 +5 -10
- package/dist/core/Point.js +32 -45
- package/dist/core/Polygon.d.ts +5 -4
- package/dist/core/Polygon.js +20 -47
- 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);
|
|
@@ -15,18 +15,13 @@ export default class Point {
|
|
|
15
15
|
* hasImg: Boolean 是否显示图标
|
|
16
16
|
* }
|
|
17
17
|
*/
|
|
18
|
-
addPoint(pointData: PointData[],
|
|
19
|
-
addClusterPoint(pointData:
|
|
20
|
-
|
|
21
|
-
* 添加点 - 闪烁
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
addFlashWarnPoint(img: any): void;
|
|
25
|
-
setTwinkleLayerFromPolygon(twinkleList: any[], className: string, key: string, json: any): void;
|
|
18
|
+
addPoint(pointData: PointData[], options: OptionsType): VectorLayer<VectorSource<import("ol/geom").Geometry>>;
|
|
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 闪烁点数据 - 二维数组 [[],[]]
|
|
29
|
-
* @param className
|
|
24
|
+
* @param className 闪烁点样式,需要和id保持一致
|
|
30
25
|
* @param key 闪烁点索引
|
|
31
26
|
* @param callback
|
|
32
27
|
*/
|
package/dist/core/Point.js
CHANGED
|
@@ -25,14 +25,14 @@ export default class Point {
|
|
|
25
25
|
* hasImg: Boolean 是否显示图标
|
|
26
26
|
* }
|
|
27
27
|
*/
|
|
28
|
-
addPoint(pointData,
|
|
28
|
+
addPoint(pointData, options) {
|
|
29
29
|
const pointFeatureList = [];
|
|
30
30
|
pointData.forEach((item) => {
|
|
31
31
|
const pointFeature = new Feature({
|
|
32
32
|
// clickLocation: options.clickLocation,
|
|
33
33
|
// all: JSON.stringify(item),
|
|
34
34
|
rawData: item, //保存原始数据
|
|
35
|
-
type: type,
|
|
35
|
+
type: options.type,
|
|
36
36
|
geometry: new olPoint([item.lgtd, item.lttd])
|
|
37
37
|
});
|
|
38
38
|
const style = {};
|
|
@@ -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
|
}
|
|
@@ -64,7 +64,7 @@ export default class Point {
|
|
|
64
64
|
pointFeatureList.push(pointFeature);
|
|
65
65
|
});
|
|
66
66
|
const PointVectorLayer = new VectorLayer({
|
|
67
|
-
layerName: type,
|
|
67
|
+
layerName: options.type,
|
|
68
68
|
source: new VectorSource({
|
|
69
69
|
features: pointFeatureList
|
|
70
70
|
}),
|
|
@@ -74,7 +74,7 @@ export default class Point {
|
|
|
74
74
|
this.map.addLayer(PointVectorLayer);
|
|
75
75
|
return PointVectorLayer;
|
|
76
76
|
}
|
|
77
|
-
addClusterPoint(pointData,
|
|
77
|
+
addClusterPoint(pointData, options) {
|
|
78
78
|
const pointFeatureList = [];
|
|
79
79
|
pointData.forEach(item => {
|
|
80
80
|
const pointFeature = new Feature({
|
|
@@ -91,55 +91,42 @@ export default class Point {
|
|
|
91
91
|
source: source,
|
|
92
92
|
});
|
|
93
93
|
const clusterLayer = new VectorLayer({
|
|
94
|
-
layerName: type,
|
|
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');
|
|
@@ -199,7 +186,7 @@ export default class Point {
|
|
|
199
186
|
/**
|
|
200
187
|
* 设置闪烁点
|
|
201
188
|
* @param twinkleList 闪烁点数据 - 二维数组 [[],[]]
|
|
202
|
-
* @param className
|
|
189
|
+
* @param className 闪烁点样式,需要和id保持一致
|
|
203
190
|
* @param key 闪烁点索引
|
|
204
191
|
* @param callback
|
|
205
192
|
*/
|
|
@@ -212,7 +199,7 @@ export default class Point {
|
|
|
212
199
|
arr[i].parentNode?.removeChild(arr[i]);
|
|
213
200
|
}
|
|
214
201
|
}
|
|
215
|
-
const el = document.getElementById(
|
|
202
|
+
const el = document.getElementById(className);
|
|
216
203
|
for (let i = 0; i < twinkleList.length; i++) {
|
|
217
204
|
const twinkleItem = twinkleList[i];
|
|
218
205
|
// 定义图标Dom
|
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 {
|
|
@@ -16,11 +17,10 @@ export default class Polygon {
|
|
|
16
17
|
/**
|
|
17
18
|
* 添加 地图 边框 图层
|
|
18
19
|
* @param data 图层数据
|
|
19
|
-
* @param type 图层类型
|
|
20
20
|
* @param options 图层配置
|
|
21
21
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
addBorderPolygon(data: MapJSONData, options: OptionsType): void;
|
|
23
|
+
addPolygon(dataJSON: MapJSONData, options?: OptionsType): VectorLayer<VectorSource<Geometry>>;
|
|
24
24
|
/**
|
|
25
25
|
* 根据数据数组更新某个面颜色
|
|
26
26
|
* @param layerName 图层名称
|
|
@@ -47,6 +47,7 @@ export default class Polygon {
|
|
|
47
47
|
fillColor?: string;
|
|
48
48
|
strokeWidth?: number;
|
|
49
49
|
strokeColor?: string;
|
|
50
|
+
zIndex?: number;
|
|
50
51
|
}): void;
|
|
51
52
|
/**
|
|
52
53
|
* 添加图片图层
|
|
@@ -55,6 +56,6 @@ export default class Polygon {
|
|
|
55
56
|
* @param extent 图片范围(对角线坐标) [minx, miny, maxx, maxy]
|
|
56
57
|
* @param options 图层配置
|
|
57
58
|
*/
|
|
58
|
-
|
|
59
|
+
addImage(layerName: string, img?: string, extent?: number[], options?: OptionsType): import("ol/layer/Base").default | VectorLayer<VectorSource<Geometry>> | ImageLayer<import("ol/source").Image>;
|
|
59
60
|
removePolygonLayer(layerName: string): void;
|
|
60
61
|
}
|
package/dist/core/Polygon.js
CHANGED
|
@@ -29,48 +29,20 @@ export default class Polygon {
|
|
|
29
29
|
/**
|
|
30
30
|
* 添加 地图 边框 图层
|
|
31
31
|
* @param data 图层数据
|
|
32
|
-
* @param type 图层类型
|
|
33
32
|
* @param options 图层配置
|
|
34
33
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
source: new VectorSource({
|
|
40
|
-
features: (new GeoJSON()).readFeatures(data)
|
|
41
|
-
}),
|
|
42
|
-
style: function (feature) {
|
|
43
|
-
feature.set('type', options.type);
|
|
44
|
-
feature.set('layerName', options.type);
|
|
45
|
-
return new Style({
|
|
46
|
-
stroke: new Stroke({
|
|
47
|
-
color: options.strokeColor || '#EBEEF5',
|
|
48
|
-
width: options.strokeWidth || 3
|
|
49
|
-
}),
|
|
50
|
-
fill: new Fill({ color: 'rgba(255, 255, 255, 0)' }),
|
|
51
|
-
text: new Text({
|
|
52
|
-
text: options.nameKey ? feature.values_[options.nameKey] : "",
|
|
53
|
-
font: options.textFont ?? '14px Calibri,sans-serif',
|
|
54
|
-
fill: new Fill({ color: options.textFillColor ?? '#FFF' }),
|
|
55
|
-
stroke: new Stroke({
|
|
56
|
-
color: options.textStrokeColor ?? '#409EFF',
|
|
57
|
-
width: options.textStrokeWidth ?? 2
|
|
58
|
-
})
|
|
59
|
-
})
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
zIndex: options.zIndex ?? 2
|
|
63
|
-
});
|
|
64
|
-
borderLayer.setVisible(options.visible === undefined ? true : options.visible);
|
|
65
|
-
this.map.addLayer(borderLayer);
|
|
34
|
+
addBorderPolygon(data, options) {
|
|
35
|
+
options.type = options.type ?? 'border';
|
|
36
|
+
options.fillColor = options.fillColor ?? 'rgba(255, 255, 255, 0)';
|
|
37
|
+
this.addPolygon(data, options);
|
|
66
38
|
if (options.mask)
|
|
67
39
|
this.setOutLayer(data);
|
|
68
40
|
}
|
|
69
41
|
// 添加分区
|
|
70
42
|
//fyBasinJson中的id的key需要跟options中的nameKey一致
|
|
71
|
-
|
|
43
|
+
addPolygon(dataJSON, options = {}) {
|
|
72
44
|
if (options.type != null) {
|
|
73
|
-
|
|
45
|
+
MapTools.removeLayer(this.map, options.type);
|
|
74
46
|
}
|
|
75
47
|
const layer = new VectorLayer({
|
|
76
48
|
name: options.type,
|
|
@@ -84,13 +56,13 @@ export default class Polygon {
|
|
|
84
56
|
return new Style({
|
|
85
57
|
stroke: new Stroke({
|
|
86
58
|
color: options.strokeColor ?? '#EBEEF5',
|
|
87
|
-
width: options.strokeWidth ??
|
|
59
|
+
width: options.strokeWidth ?? 2,
|
|
88
60
|
lineDash: options.lineDash,
|
|
89
61
|
lineDashOffset: options.lineDashOffset
|
|
90
62
|
}),
|
|
91
63
|
fill: new Fill({ color: options.fillColor || 'rgba(255, 255, 255, 0.3)' }),
|
|
92
64
|
text: new Text({
|
|
93
|
-
text: options.nameKey ? feature.values_[options.nameKey] : "",
|
|
65
|
+
text: options.textVisible && options.nameKey ? feature.values_[options.nameKey] : "",
|
|
94
66
|
font: options.textFont ?? '14px Calibri,sans-serif',
|
|
95
67
|
fill: new Fill({ color: options.textFillColor ?? '#FFF' }),
|
|
96
68
|
stroke: new Stroke({
|
|
@@ -124,7 +96,7 @@ export default class Polygon {
|
|
|
124
96
|
* @param options 配置项
|
|
125
97
|
*/
|
|
126
98
|
updateFeatureColors(layerName, colorObj, options) {
|
|
127
|
-
const layer = this.map
|
|
99
|
+
const layer = MapTools.getLayerByLayerName(this.map, layerName)[0];
|
|
128
100
|
if (layer instanceof VectorLayer) {
|
|
129
101
|
const source = layer.getSource();
|
|
130
102
|
const features = source.getFeatures();
|
|
@@ -136,7 +108,7 @@ export default class Polygon {
|
|
|
136
108
|
feature.setStyle(new Style({
|
|
137
109
|
stroke: new Stroke({
|
|
138
110
|
color: options.strokeColor ?? '#EBEEF5',
|
|
139
|
-
width: options.strokeWidth ??
|
|
111
|
+
width: options.strokeWidth ?? 2
|
|
140
112
|
}),
|
|
141
113
|
fill: new Fill({ color: newColor }),
|
|
142
114
|
text: new Text({
|
|
@@ -231,7 +203,7 @@ export default class Polygon {
|
|
|
231
203
|
const vtLayer = new VectorLayer({
|
|
232
204
|
source: vtSource,
|
|
233
205
|
style: shadeStyle,
|
|
234
|
-
zIndex: 99
|
|
206
|
+
zIndex: options?.zIndex ?? 99
|
|
235
207
|
});
|
|
236
208
|
this.map.addLayer(vtLayer);
|
|
237
209
|
const features = new GeoJSON().readFeatures(data);
|
|
@@ -251,20 +223,22 @@ export default class Polygon {
|
|
|
251
223
|
* @param extent 图片范围(对角线坐标) [minx, miny, maxx, maxy]
|
|
252
224
|
* @param options 图层配置
|
|
253
225
|
*/
|
|
254
|
-
|
|
226
|
+
addImage(layerName, img, extent, options = { zIndex: 3 }) {
|
|
227
|
+
let imageLayer = MapTools.getLayerByLayerName(this.map, layerName)[0];
|
|
255
228
|
if (img && extent) {
|
|
256
229
|
const source = new ImageStatic({
|
|
257
230
|
url: img,
|
|
258
231
|
imageExtent: extent
|
|
259
232
|
});
|
|
260
|
-
if (
|
|
261
|
-
|
|
233
|
+
if (imageLayer && imageLayer instanceof ImageLayer) {
|
|
234
|
+
imageLayer.setSource(source);
|
|
262
235
|
}
|
|
263
236
|
else {
|
|
264
|
-
|
|
237
|
+
imageLayer = new ImageLayer();
|
|
265
238
|
imageLayer.set('name', layerName);
|
|
266
239
|
imageLayer.set('layerName', layerName);
|
|
267
|
-
imageLayer
|
|
240
|
+
if (imageLayer instanceof ImageLayer)
|
|
241
|
+
imageLayer.setSource(source);
|
|
268
242
|
imageLayer.setZIndex(options.zIndex ?? 3);
|
|
269
243
|
imageLayer.setOpacity(options.opacity ?? 1);
|
|
270
244
|
if (options.visible !== undefined)
|
|
@@ -273,16 +247,15 @@ export default class Polygon {
|
|
|
273
247
|
imageLayer = MapTools.setMapClip(imageLayer, options.mapClipData);
|
|
274
248
|
}
|
|
275
249
|
this.map.addLayer(imageLayer);
|
|
276
|
-
this[layerName] = imageLayer;
|
|
277
250
|
}
|
|
278
251
|
}
|
|
279
252
|
else {
|
|
280
253
|
this.removePolygonLayer(layerName);
|
|
281
254
|
}
|
|
282
|
-
return
|
|
255
|
+
return imageLayer;
|
|
283
256
|
}
|
|
284
257
|
removePolygonLayer(layerName) {
|
|
285
|
-
|
|
258
|
+
MapTools.removeLayer(this.map, layerName);
|
|
286
259
|
this[layerName] = null;
|
|
287
260
|
}
|
|
288
261
|
}
|
package/dist/types.d.ts
CHANGED