geoUtils.js
6.06 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
/*
* 图形相关的操作 js
* */
import layers from '@/assets/json/layers.json'
import queryUtils from "@libs/map/queryUtils";
import {loadModules} from "esri-loader"
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)
}
}
}