geoUtils.js
10 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
/*
* 图形相关的操作 js
* */
import layers from '@/assets/json/layers.json'
import queryUtils from "@libs/map/queryUtils";
import identifyUtils from '@/libs/map/IdentifyUtils'
import {loadModules} from "esri-loader"
import featureUpdate from "@libs/map/featureUpdate";
import arcgisParser from 'terraformer-arcgis-parser'
import wktParse from 'terraformer-wkt-parser'
export default {
data(){
return{
}
},
methods: {
getLayerByName(name) {
for (var i = 0; i < layers.length; i++) {
if (layers[i].layerName == name) {
return layers[i];
}
}
return null;
},
queryGeoByBsm(bsm, type, callBackFunction) {
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 (callBackFunction && typeof callBackFunction == 'function') {
callBackFunction(features);
}
});
},
//生成介质点
craetJZPoint(graphic) {
var geomtry = graphic.geometry,rings = geomtry.rings[0];
var pointInfos = [];
this.getPointByRings(rings,pointInfos);
return pointInfos;
},
getPointByRings(rings,pointInfos){
for(var i = 0;i < rings.length;i++){
var children = rings[i];
if(children.length == 2 && typeof children[0] == 'number'){
var obj = {};
obj.jzdh = "j"+pointInfos.length;
obj.sxh = pointInfos.length;
obj.x = children[0];
obj.y = children[1];
pointInfos.push(obj);
}else {
this.getPointByRings(children,pointInfos);
}
}
},
//生成介质线
createJZLine(graphic,callBackFunction) {
var self = this;
loadModules([
"esri/geometry/support/geodesicUtils",
"esri/geometry/Point",
"esri/geometry/Polyline"
]).then(([
geodesicUtils,
Point,
Polyline
])=>{
//取得各个坐标点 然后生成外围坐标线
var geometry = graphic.geometry,
rings = geometry.rings,
points = [];
if(rings.length > 0){
for(var i = 0;i < rings.length;i++){
var danPoints = [];
self.getPointByRings(rings[i],danPoints);
points.push(danPoints);
}
}else {
var danPoints = [];
self.getPointByRings(rings,danPoints);
points.push(danPoints);
}
var lines = [];
//meters
for(var i = 0;i < points.length;i++){
for(var j = 0;j < points[i].length;j++){
if(j < (points[i].length - 1)){
const join = geodesicUtils.geodesicDistance(
new Point({ x: points[i][j].x, y: points[i][j].y }),
new Point({ x: points[i][j+1].x, y: points[i][j+1].y }),
"meters"
);
const { distance, azimuth } = join;
var obj = {
startPoint:points[i][j].x +"," +points[i][j].y ,
endPoint:points[i][j+1].x +","+points[i][j+1].y,
qdh:points[i][j].sxh,
zdh:points[i][j+1].sxh,
distance:distance,
jzxlx:"",
jzxwz:"",
jzxxz:"",
remark:""
}
lines.push(obj);
}else{
const join = geodesicUtils.geodesicDistance(
new Point({ x: points[i][j].x, y: points[i][j].y }),
new Point({ x: points[i][0].x, y: points[i][0].y }),
"meters"
);
const { distance, azimuth } = join;
var obj = {
startPoint:points[i][j].x +"," +points[i][j].y ,
endPoint:points[i][0].x +"," +points[i][0].y ,
qdh:points[i][j].sxh,
zdh:points[i][0].sxh,
distance:distance,
jzxlx:"",
jzxwz:"",
jzxxz:"",
remark:""
}
lines.push(obj);
}
}
}
if(callBackFunction && typeof callBackFunction == "function"){
callBackFunction(lines);
}
}).catch( err => {
throw (err);
})
},
//wkt转换成arcgis
parseWktToArc(wkt){
var primitive = wktParse.parse(wkt);
/*if(primitive.type == "MultiPolygon"){
primitive.type = "Polygon"
}*/
return arcgisParser.convert(primitive)
},
//导入空间图形是 先判断数据是否跨界
geoJoint(geometry,callBacFunction){
var self = this;
loadModules([
"esri/geometry/geometryEngine",
"esri/geometry/Polygon"
]).then(([
geometryEngine,
Polygon
]) => {
var djqLayer = null,djzqLayer = null,xjzqLayer = null;
djqLayer = self.getLayerByName("DJQ");
djzqLayer = self.getLayerByName("DJZQ");
xjzqLayer = self.getLayerByName("XJZQ");
var layerIds = [];
layerIds.push(djqLayer.id);
layerIds.push(djzqLayer.id);
layerIds.push(xjzqLayer.id);
var polygon = new Polygon(geometry);
identifyUtils.methods.identify(djqLayer.layerUrl,layerIds,polygon,function (res) {
var results = res.results;
var isJoint = false,layerName = "",message="";
if(!results || results.length == 0){
callBacFunction(true,"不在行政区内,请检查空间位置信息!!!");
}
for(var i = 0;i < results.length;i++){
var feature = results[i].feature;
var flag = geometryEngine.disjoint(polygon,feature.geometry);
if(flag){
isJoint = true;
layerName = results[i].layerName;
switch (layerName) {
case 'DJQ':message = "地块跨越地籍区,数据不合法!!!";break;
case 'DJZQ':message = "地块跨越地籍子区,数据不合法!!!";break;
case 'XJZQ':message = "地块跨越行政区,数据不合法!!!";break;
}
break
}
}
if(callBacFunction && typeof callBacFunction == "function"){
callBacFunction(isJoint,message);
}
},true)
}).catch(err => {
console.log(err);
throw (err);
})
},
//保存或者编辑属性信息
updAttributes(bsm,type,attributes,callBackFunction){
var layer = null;
if(type == 'zd'){
layer = this.getLayerByName("ZDJBXX");
}else{
layer = this.getLayerByName("ZRZ");
}
var featureUrl = layer.layerUrl.replace("MapServer","FeatureServer");
featureUrl += "/"+layer.id;
this.queryGeoByBsm(bsm,type,function (features) {
if(features && features.length > 0){
attributes.OBJECTID = features[0].attributes.OBJECTID;
features[0].attributes = attributes;
var wkt = "PROJCS[\"XADFZBX\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",0.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",0.0],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",0.0],UNIT[\"Meter\",1.0]]";
features[0].geometry.spatialReference = {
wkt:wkt
}
featureUpdate.methods.updateGraphic(featureUrl,features[0],callBackFunction);
}else{
var graphic = {
attributes:attributes
}
featureUpdate.methods.addGraphic(featureUrl,graphic,callBackFunction) ;
}
});
}
}
}