cd-mapgis 1.0.53 → 1.0.55
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/package.json +1 -1
- package/src/MapView.js +27 -2
- package/src/OM.js +29 -6
- package/src/SwipeUtil.js +89 -0
- package/test-om.js +11 -11
package/package.json
CHANGED
package/src/MapView.js
CHANGED
|
@@ -3,6 +3,8 @@ import Map from 'ol/Map.js';
|
|
|
3
3
|
import LayerUtil from './LayerUtil.js';
|
|
4
4
|
import StyleUtil from './StyleUtil.js';
|
|
5
5
|
import MapDrawUtil from './MapDrawUtil.js';
|
|
6
|
+
import SwipeUtil from './SwipeUtil.js';
|
|
7
|
+
import DragPan from 'ol/interaction/DragPan.js';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* ol地图显示
|
|
@@ -13,6 +15,7 @@ export default class MapView {
|
|
|
13
15
|
this.params = p;
|
|
14
16
|
this.view = null;
|
|
15
17
|
this.map = null;
|
|
18
|
+
this.target = null;
|
|
16
19
|
//基础图层,一般用于可以只显示其中一个图层的场景,使用layerGroupViewOne切换{group,key,name,layer}
|
|
17
20
|
//group:分组名 key:组内唯一值 name:图层名称 layer:ol图层对象
|
|
18
21
|
this.layerGroup = [];
|
|
@@ -26,6 +29,7 @@ export default class MapView {
|
|
|
26
29
|
MapView.Instance = this;
|
|
27
30
|
|
|
28
31
|
this.mapDrawUtil = null;//绘制工具
|
|
32
|
+
this.swipeUtil = null;//卷帘工具
|
|
29
33
|
}
|
|
30
34
|
//初始化地图及其他参数
|
|
31
35
|
_init(p) {
|
|
@@ -41,10 +45,10 @@ export default class MapView {
|
|
|
41
45
|
projection: projection
|
|
42
46
|
});
|
|
43
47
|
}
|
|
44
|
-
|
|
48
|
+
this.target = p.target ? p.target : 'map';//地图div的id
|
|
45
49
|
let layers = p.layers ? p.layers : [];
|
|
46
50
|
this.map = new Map({
|
|
47
|
-
target: target,
|
|
51
|
+
target: this.target,
|
|
48
52
|
controls: [],
|
|
49
53
|
layers: layers,
|
|
50
54
|
view: this.view
|
|
@@ -206,4 +210,25 @@ export default class MapView {
|
|
|
206
210
|
view.fit(extent);
|
|
207
211
|
return true;
|
|
208
212
|
}
|
|
213
|
+
//启用或禁用鼠标拖动地图
|
|
214
|
+
dragPan(flag) {
|
|
215
|
+
this.map.getInteractions().forEach(function (element, index, array) {
|
|
216
|
+
if (element instanceof DragPan) {
|
|
217
|
+
element.setActive(flag);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
//开启卷帘
|
|
222
|
+
startSwipe(layer, model) {
|
|
223
|
+
this.closeSwipe();
|
|
224
|
+
this.swipeUtil = new SwipeUtil({ mapView: this });
|
|
225
|
+
this.swipeUtil.start(layer, model);
|
|
226
|
+
}
|
|
227
|
+
//关闭卷帘
|
|
228
|
+
closeSwipe() {
|
|
229
|
+
if (this.swipeUtil != null) {
|
|
230
|
+
this.swipeUtil.close();
|
|
231
|
+
this.swipeUtil = null;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
209
234
|
}
|
package/src/OM.js
CHANGED
|
@@ -131,7 +131,11 @@ export default class OM {
|
|
|
131
131
|
}
|
|
132
132
|
/**
|
|
133
133
|
* 向地图视图添加图层
|
|
134
|
-
* @param {*} p {mapViews(单个对象或者数组),
|
|
134
|
+
* @param {*} p {mapViews(单个对象或者数组),
|
|
135
|
+
* geoLayers(geoServer固定图层),
|
|
136
|
+
* server(url,data,sort,layerCall),
|
|
137
|
+
* comm{mapKey(dic中的key)}
|
|
138
|
+
* }
|
|
135
139
|
*/
|
|
136
140
|
static async viewLayers(p) {
|
|
137
141
|
let params = OM._getParams();
|
|
@@ -147,7 +151,8 @@ export default class OM {
|
|
|
147
151
|
});
|
|
148
152
|
}
|
|
149
153
|
//先加载后端默认加载的图层
|
|
150
|
-
let
|
|
154
|
+
let mapKey = (p.comm && p.comm.mapKey) ? p.comm.mapKey : 'def_view_layers';
|
|
155
|
+
let postRes = await OM.getDic(mapKey);
|
|
151
156
|
let defViewLayers = postRes.data ? JSON.parse(postRes.data) : [];
|
|
152
157
|
//遍历每个地图容器
|
|
153
158
|
for (let k = 0; k < mapViews.length; k++) {
|
|
@@ -198,10 +203,11 @@ export default class OM {
|
|
|
198
203
|
wmsUrl = InnerUtil.getGeoServerUrl(wmsUrl, geoLayerUrl);
|
|
199
204
|
let geoParam = { workspace: geoserverDic.workspace, url: wmsUrl };
|
|
200
205
|
let _layers = [];
|
|
201
|
-
let
|
|
206
|
+
let layerNames = {};
|
|
202
207
|
for (let i = 0; i < p.geoLayers.length; i++) {
|
|
203
|
-
|
|
204
|
-
|
|
208
|
+
let l = p.geoLayers[i];
|
|
209
|
+
_layers.push(l.layerName);
|
|
210
|
+
layerNames[l.layerName] = l.title;
|
|
205
211
|
}
|
|
206
212
|
postRes = await OM.checkPushLayers({ layers: _layers });
|
|
207
213
|
let pushLayers = postRes.data ? postRes.data : [];
|
|
@@ -212,7 +218,7 @@ export default class OM {
|
|
|
212
218
|
geoParam.name = pushLayers[i];
|
|
213
219
|
let layer = LayerUtil.geoServerWmsLayer(geoParam);
|
|
214
220
|
map.addLayer(layer);
|
|
215
|
-
mapView.viewLayers.push({ type: 'geoLayer', name:
|
|
221
|
+
mapView.viewLayers.push({ type: 'geoLayer', name: layerNames[geoParam.name], layer: layer });
|
|
216
222
|
mapView.geoServerLayers.push(geoParam.name);
|
|
217
223
|
}
|
|
218
224
|
}
|
|
@@ -278,6 +284,23 @@ export default class OM {
|
|
|
278
284
|
return mapViews[0].viewLayers;
|
|
279
285
|
}
|
|
280
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* 将地图缩放到指定的图层范围
|
|
289
|
+
* @param {*} p {layers:[]}
|
|
290
|
+
*/
|
|
291
|
+
static async viewToLayer(p) {
|
|
292
|
+
let res = await OM.getBound(p);
|
|
293
|
+
if (res.data) {
|
|
294
|
+
var bounds = [res.data.minX, res.data.minY, res.data.maxX, res.data.maxY];
|
|
295
|
+
for (let k = 0; k < mapViews.length; k++) {
|
|
296
|
+
let mapView = mapViews[k];
|
|
297
|
+
let map = mapView.map;
|
|
298
|
+
map.getView().fit(bounds, map.getSize());
|
|
299
|
+
}
|
|
300
|
+
} else {
|
|
301
|
+
console.log("未查询到图层:", p);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
281
304
|
/**
|
|
282
305
|
* 将地图缩放到指定的图层范围
|
|
283
306
|
* @param {*} p
|
package/src/SwipeUtil.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 卷帘工具
|
|
3
|
+
*/
|
|
4
|
+
export default class SwipeUtil {
|
|
5
|
+
constructor(p) {
|
|
6
|
+
this.mapView = p.mapView;
|
|
7
|
+
this.map = p.mapView.map;
|
|
8
|
+
|
|
9
|
+
this.map_event_pointerdown = null;//注册鼠标在地图上按下事件
|
|
10
|
+
this.map_event_pointerup = null;//注册鼠标在地图上弹起事件
|
|
11
|
+
this.map_event_pointermove = null;//注册鼠标在地图上移动事件
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 开始卷帘
|
|
15
|
+
* @param {*} layer 需要操作的图层
|
|
16
|
+
* @param {*} model 1保留左边 2保留上面 3保留右边 4保留下面
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
start(layer, model) {
|
|
20
|
+
if (this.map_event_pointerdown) return;//判断是否开启
|
|
21
|
+
let _map = this.map;
|
|
22
|
+
let _mapView = this.mapView;
|
|
23
|
+
let h = document.getElementById(this.mapView.target).clientHeight;//图形高度
|
|
24
|
+
let w = document.getElementById(this.mapView.target).clientWidth;//图形宽度
|
|
25
|
+
let pixel;//鼠标的屏幕像素点
|
|
26
|
+
let layer_event_precompose;//图层在地图渲染之前事件
|
|
27
|
+
let layer_event_postcompose;//图层在地图渲染之后事件
|
|
28
|
+
//注册鼠标在地图上按下事件
|
|
29
|
+
map_event_pointerdown = _map.on('pointerdown', function (e) {
|
|
30
|
+
pixel = e.pixel;
|
|
31
|
+
//图层在地图渲染之前触发
|
|
32
|
+
layer_event_precompose = layer.on('precompose', function (event) {
|
|
33
|
+
var ctx = event.context;//获得canvas渲染上下文
|
|
34
|
+
var dx;
|
|
35
|
+
if (model == 1 || model == 3) {
|
|
36
|
+
dx = ctx.canvas.width * (pixel[0] / w);
|
|
37
|
+
} else {
|
|
38
|
+
dx = ctx.canvas.height * (pixel[1] / h);
|
|
39
|
+
}
|
|
40
|
+
ctx.save();// 保存canvas设置
|
|
41
|
+
ctx.beginPath();// 开始绘制路径
|
|
42
|
+
//设置绘制矩形
|
|
43
|
+
if (model == 1) {
|
|
44
|
+
ctx.rect(0, 0, dx, ctx.canvas.height);
|
|
45
|
+
} else if (model == 2) {
|
|
46
|
+
ctx.rect(0, 0, ctx.canvas.width, dx);
|
|
47
|
+
} else if (model == 3) {
|
|
48
|
+
ctx.rect(dx, 0, ctx.canvas.width - dx, ctx.canvas.height);
|
|
49
|
+
} else if (model == 4) {
|
|
50
|
+
ctx.rect(0, dx, ctx.canvas.width, ctx.canvas.height - dx);
|
|
51
|
+
}
|
|
52
|
+
ctx.clip();// 裁剪Bing地图,以形成卷帘效果
|
|
53
|
+
});
|
|
54
|
+
//图层在地图渲染之后触发
|
|
55
|
+
layer_event_postcompose = layer.on('postcompose', function (event) {
|
|
56
|
+
var ctx = event.context;
|
|
57
|
+
ctx.restore(); // 恢复canvas设置
|
|
58
|
+
});
|
|
59
|
+
// 立即渲染地图
|
|
60
|
+
_map.render();
|
|
61
|
+
//禁用鼠标拖动地图
|
|
62
|
+
_mapView.dragPan(false);
|
|
63
|
+
});
|
|
64
|
+
//注册鼠标在地图上弹起事件
|
|
65
|
+
map_event_pointerup = _map.on('pointerup', function (e) {
|
|
66
|
+
//移除图层的事件
|
|
67
|
+
layer.un(layer_event_precompose.type, layer_event_precompose.listener);
|
|
68
|
+
layer.un(layer_event_postcompose.type, layer_event_postcompose.listener);
|
|
69
|
+
// 渲染地图
|
|
70
|
+
_map.render();
|
|
71
|
+
//启用鼠标拖动地图
|
|
72
|
+
_mapView.dragPan(true);
|
|
73
|
+
});
|
|
74
|
+
//注册鼠标在地图上移动事件
|
|
75
|
+
map_event_pointermove = _map.on('pointermove', (e) => {
|
|
76
|
+
pixel = e.pixel;
|
|
77
|
+
_map.render();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 关闭卷帘
|
|
82
|
+
*/
|
|
83
|
+
close() {
|
|
84
|
+
if (!this.map_event_pointerdown) return;//判断是否开启
|
|
85
|
+
this.map.un(this.map_event_pointerdown.type, this.map_event_pointerdown.listener);
|
|
86
|
+
this.map.un(this.map_event_pointerup.type, this.map_event_pointerup.listener);
|
|
87
|
+
this.map.un(this.map_event_pointermove.type, this.map_event_pointermove.listener);
|
|
88
|
+
}
|
|
89
|
+
}
|
package/test-om.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// 导入 OM 类
|
|
2
|
-
import { OM } from './src/index.js';
|
|
3
|
-
|
|
4
|
-
// 打印 OM 类,检查是否为类而不是字符串
|
|
5
|
-
console.log('OM 类型:', typeof OM);
|
|
6
|
-
console.log('OM 类定义:', OM);
|
|
7
|
-
|
|
8
|
-
// 测试调用静态方法(不执行实际初始化,只检查方法是否存在)
|
|
9
|
-
console.log('OM.initMap 存在:', typeof OM.initMap === 'function');
|
|
10
|
-
|
|
11
|
-
console.log('测试完成,请检查输出结果。');
|
|
1
|
+
// 导入 OM 类
|
|
2
|
+
import { OM } from './src/index.js';
|
|
3
|
+
|
|
4
|
+
// 打印 OM 类,检查是否为类而不是字符串
|
|
5
|
+
console.log('OM 类型:', typeof OM);
|
|
6
|
+
console.log('OM 类定义:', OM);
|
|
7
|
+
|
|
8
|
+
// 测试调用静态方法(不执行实际初始化,只检查方法是否存在)
|
|
9
|
+
console.log('OM.initMap 存在:', typeof OM.initMap === 'function');
|
|
10
|
+
|
|
11
|
+
console.log('测试完成,请检查输出结果。');
|