mapLayerManager.js
5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import layers from '@/assets/json/layers.json'
import graphicSymbol from '@/assets/json/graphicSymbol.json'
import queryUtils from "@libs/map/queryUtils";
import {loadModules} from "esri-loader"
import {maps} from '@/libs/map/mapUtils'
export default {
methods:{
getLayerByName(name) {
for (var i = 0; i < layers.length; i++) {
if (layers[i].layerName == name) {
return layers[i];
}
}
return null;
},
addGeoByBsm(bsm, type,viewId) {
var self = this;
var layer = null;
if (type == 'zd') {
layer = this.getLayerByName("ZDJBXX");
} else if (type == 'zrz') {
layer = this.getLayerByName("ZRZ");
} else {
console.log("未定义类型!!");
return;
}
if (!layer) {
console.log("没有找到图层,不能查询");
return;
}
queryUtils.methods.queryByWhere(layer.layerUrl+"/"+layer.id, {"BSM": bsm }, null, true, null, null, function (res) {
var features = res.features;
if(features && features.length > 0){
if( !features[0].geometry ){
self.$message.success("暂无图形信息!!");
return;
}
loadModules([
"esri/layers/GraphicsLayer"
]).then( ([
GraphicsLayer
]) => {
var view = maps[viewId];
var layer = view.map.findLayerById("highlightLayer");
if(layer){
layer.removeAll();
}else {
layer = new GraphicsLayer({
id:"highlightLayer"
})
view.map.add(layer,5);
}
var symbol = graphicSymbol.fillSymbol.highlightSymbol;
var graphic = features[0];
graphic.symbol = symbol;
layer.add(graphic);
view.extent = graphic.geometry.extent;
}).catch( err => {
thow(err);
})
}else {
self.$message.success("暂无图形信息!!");
return;
}
});
},
//将查询结果展示在地图上
addSearchResultToMap(searchResult,viewId){
var view = maps[viewId],
self = this;
loadModules([
"esri/layers/GraphicsLayer"
]).then(([
GraphicsLayer
]) => {
if(!searchResult || searchResult.length == 0){
return;
}
for(var i = 0;i < searchResult.length;i++){
var layer = view.map.findLayerById("searchResult"+searchResult.layerName);
if(layer){
layer.removeAll();
}else{
layer = new GraphicsLayer({
id:"searchResult"+searchResult.layerName
})
view.map.add(layer);
}
var symbol = graphicSymbol.fillSymbol.highlightSymbol;
var features = searchResult[i].features;
for(var j = 0;j < features.length;j++){
if(features[j].geometry){
features[j].symbol = symbol;
layer.add(features[j]);
}
}
}
}).catch(err=>{
console.log(err);
})
},
//缩放至当前对象
extentToGraphic(feature,highlightGraohic,viewId,callBackFunction){
var symbol = graphicSymbol.fillSymbol.highlightSymbol;
var highlightSymbol = graphicSymbol.fillSymbol.defaultSymbol;
if(highlightGraohic){
highlightGraohic.symbol = symbol;
}
feature.symbol = highlightSymbol;
var view = maps[viewId];
feature.geometry.type == 'point' ?view.center = feature.geometry :view.extent = feature.geometry.extent;
if(callBackFunction && typeof callBackFunction == 'function'){
callBackFunction();
}
},
clearSearchLayer(viewId){
var view = maps[viewId],
layers = view.map.allLayers;
layers.filter(function (item) {
if(item.id.indexOf("searchResult") != -1){
item.removeAll();
}
});
}
}
}