MapManager.js
17 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
define("esri/config esri/core/urlUtils dojo/_base/declare lib/BaseWidget dojo/_base/lang dojo/_base/array dojo/dom dojo/on dojo/topic dojo/cookie dojo/Deferred dojo/_base/html dojo/dom-class esri/Map esri/views/MapView esri/layers/Layer esri/layers/TileLayer esri/layers/VectorTileLayer esri/layers/FeatureLayer esri/layers/MapImageLayer esri/widgets/Legend esri/geometry/Extent esri/geometry/SpatialReference dojo/request/xhr dojo/promise/all esri/widgets/support/widget".split(" "), function (esriConfig, urlUtils, l, m, d, f, y, z, e, n, A, B, C, p, q, D, r, t, u, mapImageLayer,Legend, v, E, w, x, wu) {
//arcgis跨域调取地图代理服务设置
var url = "http://10.7.120.165/onemap/proxy/proxy.ashx?http://172.16.128.165:6080/ArcGIS/rest/services/basicmapservice/MapServer?account=xxzxweb_111111&f=json";
$.ajax({
url: url,
timeout: 500,
success: function (data) {
esriConfig.request.corsEnabledServers.push("http://10.7.120.8/onemap/proxy/proxy.ashx");
urlUtils.addProxyRule({
urlPrefix: "http://172.16.128.165:6080/",
proxyUrl: url
});
window.url=url;
},
error:function(error){
esriConfig.request.corsEnabledServers.push("http://172.16.128.165/onemap/proxy/proxy.ashx");
urlUtils.addProxyRule({
urlPrefix: "http://172.16.128.165:6080/",
proxyUrl: "http://172.16.128.165/onemap/proxy/proxy.ashx?http://172.16.128.165:6080/ArcGIS/rest/services/basicmapservice/MapServer?account=xxzxweb_111111&f=json"
});
url="http://172.16.128.165/onemap/proxy/proxy.ashx?http://172.16.128.165:6080/ArcGIS/rest/services/basicmapservice/MapServer?account=xxzxweb_111111&f=json"
window.url=url;
}
});
esriConfig.request.corsDetection=true;
var g = null,
h;
h = l(m, {
map: null,
legend: null,
appConfig: null,
extent: null,
ping0: 0,
layerconfig: "./config/layer.json",
layerattr: "./config/attribute.json",
legendurl: "./config/legend.json",
LoadedLayers: [],
constructor: function (a) {
this.appConfig = a || "";
this.listenBuilderEvents();
window.changeBaseLayer = d.hitch(this, this.changeBaseLayer);
a != "" && (window.ONEMAP_SERVER = this.httpIndexOf(a.hosts.serverhost));
},
listenBuilderEvents: function () {
e.subscribe("builder/mapReload", d.hitch(this, this._onMapReload));
e.subscribe("addLayer", d.hitch(this, this.LoadLayer));
e.subscribe("loadBaseMapLayers", d.hitch(this, this.loadBaseMapLayers));
e.subscribe("visibleLayer", d.hitch(this, this.visibleLayer));
e.subscribe("getLayerInfos", d.hitch(this, this.getLayerInfos));
e.subscribe("openSplitMap", d.hitch(this, this.openSplitMap));
e.subscribe("setSplitMapLayers", d.hitch(this, this.setSplitMapLayers))
},
initMap: function () {
isServer_SET ? this.requestDefaultByUrlAndParam(this.getRequestUrlByLabel("configbase"), JSON.stringify({
name: "main_config,attrs"
})).then(d.hitch(this, function (a) {
0 == a.status ? (a = JSON.parse(a.result.config[0].content), this.appConfig.map = a.map, this.appConfig.map.basemaps[0].visible = !0, this.appConfig.map.basemaps[1].visible = !1, this.LoadMap()) : console.log(a)
}))/* : netServer && "admin" != n("username") ? this.requestDefaultByUrlAndParam(this.getRequestUrlByLabel("configbase"), JSON.stringify({
name: "main_config,attrs,layers,legend"
})).then(d.hitch(this, function (a) {
if (0 == a.status) {
var b = JSON.parse(a.result.config[0].content);
this.appConfig.map = b.map;
this.appConfig.map.basemaps[0].visible = !0;
this.appConfig.map.basemaps[1].visible = !1;
a.result.attrs && (this.attrs = a.result.attrs ? a.result.attrs : []);
a.result.layers && (this.layers = a.result.layers ? a.result.layers : []);
a.result.legend && (this.legends = a.result.legend ? a.result.legend : []);
this.LoadMap()
} else console.log(a)
})) */: x([this._LoadLayerInfos(this.layerconfig), this._LoadLayerInfos(this.layerattr), this._LoadLayerInfos(this.legendurl)]).then(d.hitch(this, function (a) {
this.layers = a[0].layers;
this.attrs = a[1].attrs;
this.legends = a[2].legends;
this.LoadMap();
// 原设计逻辑为 widget 的加载在 LoadMap 中进行
// 略微延迟后,进行 widget 的加载
this.LoadWidget();
}), function (a) {
console.log(a)
})
},
LoadMap: function () {
"" != this.appConfig && (this.extent = new v({
xmin: this.appConfig.map.extent.xmin,
ymin: this.appConfig.map.extent.ymin,
xmax: this.appConfig.map.extent.xmax,
ymax: this.appConfig.map.extent.ymax,
spatialReference: new E(this.appConfig.map.extent.spatialReference)
}), this.map = new p, this.view = new q({
container: mapDivId,
/*extent: this.extent,*/
zoom: 2,
map: this.map
}), this.view.constraints = {
rotationEnabled: false //ldq20180719禁止旋转
}, this.legend1 = new Legend({
view: this.view,
layerInfos: []
}),
(this.view.extent = this.extent),
/* window.AAA = {},
Object.defineProperty(this, 'view', {
get: function () {
return AAA;
},
set: function(value) {
window.AAA = value;
console.log('set:' + value);
}
}),*/
this.loadBaseMapLayers(this.map),
this.view.then(d.hitch(this, function () {
e.publish("mapLoaded", this.map, this.view);
window.mapview = this.view;
})));
this.view.ui.add(this.legend1, "bottom-left");
this.legendRender(this.legend1, this.appConfig.map.basemaps);
},
/**
* 重写Legend render 方法(arcgis_js_api/esri/widgets/Legend.js)
* @param legendObject 图例对象
* @param basemap 配置文件所配置的底图
* hzw 20190424 隐藏服务图例需求
*/
legendRender: function (legendObject, basemap) {
legendObject.render = function () {
var a = legendObject,
e = a.activeLayerInfos,
b = "esri-legend esri-widget",
e = e && e.toArray().map(function (b) {
// 如果是底图,则清空所有图例
window.mapview && window.mapview.allLayerViews &&
mapview.allLayerViews.toArray().map(function (m) {
m.layer && Array.isArray(basemap) && basemap.forEach( function (value) {
if (value.url == m.layer.url && b.title == m.layer.title) {
b.legendElements = [];
}
})
});
// 去掉 ‘2018违法建设图斑’ 服务的图例
if(b.title == "2018违法建设图斑") {
b.legendElements = [];
}
// ---------------------
return a._renderLegendForLayer(b)
}).filter(function (a) {
return !!a
});
return wu.tsx("div", {class: b},
wu.tsx("div", { class: "esri-legend__top", style: "height: 42px;background-color:#F8F8F8"},
wu.tsx("span", { style: "width:30px;margin-left:10%;margin-top:15px;float:left;color:black;"}, "图例"),
wu.tsx("span", { id: "esri-legend__close", class: "esri-popup__icon esri-icon-close", onclick: "legendClose()", style: "margin-right:10%;margin-top:13px;float:right;cursor: pointer;"},
wu.tsx("img", { src: "images/x.png"}))),
wu.tsx("div", { class: "esri-legend__coot" }, e));
}
},
LoadWidget: function () {
e.publish("loadwidget", this.map, this.view);
},
loadBaseMapLayers: function (a) {
f.forEach(this.appConfig.map.basemaps, d.hitch(this, function (b, c) {
this._loadBaseLayers(b, a);
}));
f.forEach(this.appConfig.map.operationallayers, d.hitch(this, function (b, c) {
this._loadBaseLayers(b, a)
}))
},
checkIsBaseLayer: function (a) {
var b = !1;
f.forEach(this.appConfig.map.basemaps, d.hitch(this, function (c, d) {
c.key == a && (b = !0)
}));
f.forEach(this.appConfig.map.operationallayers, d.hitch(this, function (c, d) {
c.key == a && (b = !0)
}));
return b
},
getLayerInfos: function (a, b) {
a[b] = this[b]
},
visibleLayer: function (a, b) {
try {
if ("string" === typeof a) {
var c = this.map.findLayerById(a);
"undefined" === typeof c ? b && (e.publish("layer-change"), this.LoadLayer(a)) : ((c.visible = b) || this.checkIsBaseLayer(a) || this.map.remove(this.map.findLayerById(a)), e.publish("layer-change"))
}
} catch (k) {
isDebug_L && (console.log(a + " visible:" + b + "error:"), console.log(k))
}
},
_loadBaseLayers: function (a, b) {
var that=this;
try {
if ("undefined" === typeof a || "undefined" === typeof a.url || "" === a.url) return 0;
var c = this._createlayer(a);
"string" === typeof a.label && (c.name = a.label);
"string" === typeof a.key && (c.id = a.key);
"boolean" === typeof a.visible && (c.visible = a.visible);
"number" === typeof a.opacity && (c.opacity = a.opacity);
null != c && b && b.add(c);
var url = a.url;
var showSuccessMap = function (status) {
var _visible = true;
var basemaps = that.appConfig.map.basemaps;
window.baseMapsCase = window['baseMapsCase'] || {};
baseMapsCase.success || (baseMapsCase.success = []);
status == "success" && baseMapsCase.success.push(c);
baseMapsCase.error || (baseMapsCase.error = []);
status == "error" && baseMapsCase.error.push(c);
var size = baseMapsCase.success.length + baseMapsCase.error.length;
if (Array.isArray(basemaps) && basemaps.length == size) {
baseMapsCase.error.forEach( function (value) {
value.visible = false;
})
baseMapsCase.success.forEach( function (value) {
value.visible == true && (_visible = false);
});
if (_visible && typeof baseMapsCase.success[0] == "object") {
baseMapsCase.success[0].visible = true;
}
}
};
$.ajax({
url: url,
timeout:4000,
success: function (data) {
showSuccessMap("success");
},
error:function(error){
showSuccessMap("error");
}
});
} catch (k) {
}
},
LoadLayer: function (a, b) {
try {
"string" === typeof a && f.forEach(this.layers, d.hitch(this, function (c, d) {
a == c.key && "undefined" !== typeof c && "undefined" !== typeof c.url && "" !== c.url && "undefined" === typeof(b ? b.findLayerById(a) : this.map.findLayerById(a)) && (d = this._createlayer(c), "string" === typeof c.label && (d.name = c.label), "string" === typeof c.key && (d.id = c.key), "boolean" === typeof c.visible && (d.visible = c.visible), "number" === typeof c.opacity && (d.opacity = c.opacity), null != d && ("undefined" === typeof b ? "undefined" !== typeof c.baselayer && c.baselayer ? (d.baselayer = c.baselayer, this.map.add(d, this.appConfig.map.basemaps.length)) : this.map.add(d) : b.add(d)))
}))
} catch (c) {
}
},
_createlayer: function (a) {
var b = this.GetLayerByKey(a.key),
c;
if (b) return b;
c = this.getMapServerUrl(a.url);
"dynamic" == a.type ? (b = new mapImageLayer({url: c})) :
"tiled" == a.type ? b = new r(c) : "vector" == a.type ? (b = new t({
url: c
}), b.title = a.label) : "feature" == a.type && (b = new u(c, {
outFields: ["*"]
}), "string" === typeof a.label && (b.label = a.label));
b.always(d.hitch(this, function () {
isDebug_L && console.log(a.label + "(" + a.key + "):" + b.loadStatus);
"failed" == b.loadStatus && (isDebug_L && console.log(a.label + "(" + a.key + ") error:"), isDebug_L && console.log(b.loadError));
"loaded" == b.loadStatus && this.AddLoadedLayers(b)
}));
return b
},
ReLoadLayer: function(a){
a.url="http://10.7.120.30:6080/arcgis/rest/services/遥感数据/2018西安影像/MapServer";
this.map.remove(this.map.findLayerById("dzdt"));
this.map.remove(this.map.findLayerById("yxdt"));
this.map.remove(this.map.findLayerById("dxfandshplayer"));
this._loadBaseLayers(a, this.map);
var key="3G_GH_DLHX";
this.LoadLayer(key, this.map);
return 1;
},
_LoadLayerInfos: function (a) {
return w(a, {
handleAs: "json"
})
},
getMapServerUrl: function (a) {
return -1 != a.indexOf("http://") ? a : "http://" + this.appConfig.hosts.mapserverhost + "/" + a
},
_onMapReload: function () {
},
openSplitMap: function (a) {
a ? ($("#map .esri-zoom").hide(), $("#map .split-title").show()) : ($("#map .esri-zoom").show(), $("#map .split-title").hide(), this.clearMapBaseLayer())
},
setSplitMapLayers: function (a) {
f.forEach(a, d.hitch(this, function (a, c) {
f.forEach(a.rounds, d.hitch(this, function (b, c) {
"nnsz-splitscreen-round-selected" == b.class && "1" == b.name && (this.selectedLayer = a, this.selectedRound = b)
}))
}));
this.clearMapBaseLayer();
this.selectedLayer && ((a = this.map.findLayerById(this.selectedLayer.key)) ? a.visible = !0 : e.publish("addLayer", this.selectedLayer.key, this.map), $("#map .split-title").children("span").html(this.selectedLayer.parent + "_" + this.selectedLayer.label))
},
clearMapBaseLayer: function () {
this.map.allLayers.forEach(d.hitch(this, function (a, b) {
if (a) {
a.type && "graphics" != a.type && (a.visible = !1);
a.visible || this.checkIsBaseLayer(a.id) || this.map.remove(this.map.findLayerById(a.id))
}
}));
f.forEach(this.appConfig.map.basemaps, d.hitch(this, function (a, b) {
(b = this.map.findLayerById(a.key)) && a.visible && (b.visible = a.visible)
}))
},
AddLoadedLayers: function (a) {
f.forEach(this.LoadedLayers, d.hitch(this, function (b, c) {
b.id == a.id && !1
}));
this.LoadedLayers.push(a)
},
GetLayerByKey: function (a) {
f.forEach(this.LoadedLayers, d.hitch(this, function (b, c) {
b.id == a && 0 == b
}));
return !1
},
changeBaseLayer: function (a) {
this.map.remove(this.map.findLayerById("dzdt"));
this.map.remove(this.map.findLayerById("yxdt"));
"dzdt" == a.key ? this.appConfig.map.basemaps[0] = a : "yxdt" == a.key && (this.appConfig.map.basemaps[1] = a);
this.loadBaseMapLayers(this.map);
e.publish("changeBaseLayer", a)
}
});
h.getInstance = function (a) {
null === g ? g = new h(a) : g.appConfig = a;
return g
};
return h
});