mapLayerManager.js
6.26 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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;
}
var view = maps[viewId];
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 || features[0].geometry.rings.length == 0){
self.$message.success("暂无图形信息!!");
return;
}
loadModules([
"esri/layers/GraphicsLayer"
]).then( ([
GraphicsLayer
]) => {
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;
view.center = graphic.geometry.extent.center;
view.zoom = 15;
}).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[i].layerId);
if(layer){
layer.removeAll();
}else{
layer = new GraphicsLayer({
id:"searchResult"+searchResult[i].layerId
})
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();
}
});
},
//给默认加载矢量图形中添加或者移除图层
addSublayers(viewId,layers){
var view = maps[viewId],
layer = view.map.findLayerById("testLayer");
for(var i = 0;i < layers.length;i++){
var sublayer = layer.findSublayerById(layers[i].layerId);
if(sublayer){
sublayer.visible = true;
}else{
sublayer = {
id:layers[i].layerId,
visible:true
}
layer.sublayers.push(sublayer);
}
}
},
removeSublayer(viewId,layers){
var view = maps[viewId],
layer = view.map.findLayerById("testLayer");
var items = layer.sublayers.items;
for(var i = 0;i < layers.length;i++){
for (var k = 0;k<items.length;k++) {
if(layers[i].layerId == items[k].id){
items.splice(k, 1);
break;
}
}
}
layer.sublayers = items;
},
//设置图层透明度
setLayerOpacity(viewId,layers,value){
var view = maps[viewId],
layer = view.map.findLayerById("testLayer");
for(var i = 0;i < layers.length;i++){
var sublayer = layer.findSublayerById(layers[i].layerId);
if(sublayer){
sublayer.opacity = value/100;
}
}
}
}
}