mapTools.js
6.12 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
import {loadModules} from 'esri-loader'
import {maps} from '@/libs/map/mapUtils'
import graphicSymbol from '@/assets/json/graphicSymbol.json'
import point from "shapefile/shp/point";
import queryUtils from "@libs/map/queryUtils";
import layers from '@/assets/json/layers.json'
import arcgisParser from 'terraformer-arcgis-parser'
import wktParse from 'terraformer-wkt-parser'
export default {
methods:{
getLayerByName(name) {
for (var i = 0; i < layers.length; i++) {
if (layers[i].layerName == name) {
return layers[i];
}
}
return null;
},
//创建buffer图形
createBuffer(geometry,distance,viewId,callBackFunction){
loadModules([
"esri/geometry/geometryEngine",
"esri/Graphic",
"esri/layers/GraphicsLayer"
]).then(([
geometryEngine,
Graphic,
GraphicsLayer
])=>{
var view = maps[viewId];
var bufferGeometry = geometryEngine.buffer(geometry,distance,'meters',true);
var layer = view.map.findLayerById("identifyLayer");
if(layer){
layer.removeAll();
}else {
layer = new GraphicsLayer({
id:"identifyLayer"
})
view.map.add(layer);
}
var symbol = geometry.type == 'point' ? graphicSymbol.pointSymbol.bufferSymbol : graphicSymbol.fillSymbol.bufferSymbol;
var oldGraphic = new Graphic({
geometry:geometry,
symbol:symbol
})
layer.add(oldGraphic);
var graphic = new Graphic({
geometry:bufferGeometry,
symbol:graphicSymbol.fillSymbol.bufferGeoSymbol
})
layer.add(graphic);
view.center = graphic.geometry.extent.center;
if(callBackFunction && typeof callBackFunction == 'function'){
callBackFunction(bufferGeometry);
}
}).catch(err => {
console.log(err);
})
},
queryAttributes(url,where,callbackFunction){
queryUtils.methods.queryByWhere(url,where,null,false,"",null,function (res) {
var features = res.features;
if(callbackFunction && typeof callbackFunction == 'function'){
callbackFunction(features);
}
})
},
//清除缓冲图层
clearBufferLayer(viewId){
var view = maps[viewId];
var layer = view.map.findLayerById("identifyLayer");
if(layer){
layer.removeAll();
}
},
//查询地籍区/地籍子区根据区域代码
queryDjqByDm(url,type,dm,callBackFunction){
var where = "";
if(type == 'djq'){
where = {"DJQDM":dm}
}else if(type == 'djzq'){
where = {"DJZQDM":dm}
}
queryUtils.methods.queryByWhere(url,where,null,true,"","",function (res) {
var features = res.features;
if(callBackFunction && typeof callBackFunction == 'function'){
callBackFunction(features);
}
});
},
parseWktToArc(wkt){
var primitive = wktParse.parse(wkt);
/*if(primitive.type == "MultiPolygon"){
primitive.type = "Polygon"
}*/
return arcgisParser.convert(primitive)
},
//添加添加元素和覆盖的元素到地图上
addOverLayer(geometry){
var view = maps["testMap"];
loadModules([
"esri/Graphic",
"esri/geometry/Polygon",
"esri/layers/GraphicsLayer",
"esri/geometry/geometryEngineAsync",
"esri/geometry/Extent"
]).then(([
Graphic,
Polygon,
GraphicsLayer,
geometryEngineAsync,
Extent
])=>{
var graphic = new Graphic({
geometry:geometry
})
var layer = view.map.findLayerById("identifyLayer");
if(layer){
layer.removeAll();
}else {
layer = new GraphicsLayer({
id:"identifyLayer"
})
view.map.add(layer);
}
var impotSymbol = graphicSymbol.fillSymbol.importSymbol;
graphic.symbol = impotSymbol;
layer.add(graphic);
var extent = new Extent(JSON.parse(JSON.stringify(graphic.geometry.extent)))
extent.spatialReference = view.spatialReference;
// view.extent = extent;
view.center = extent.center;
view.zoom = 15;
}).catch(err => {
console.log(err);
})
},
//定位到一个点上
postionToPoint(viewId,x,y){
var self = this;
loadModules([
"esri/geometry/Point",
"esri/symbols/PictureMarkerSymbol",
"esri/geometry/coordinateFormatter",
"esri/Graphic"
]).then(([
Point,
PictureMarkerSymbol,
coordinateFormatter,
Graphic
])=>{
var point = new Point({
x:x,
y:y,
});
var view = maps[viewId];
var symbol = new PictureMarkerSymbol({
url:require('@assets/images/map/postion.png'),
width:"32px",
height:'32px'
});
view.graphics.removeAll();
view.graphics.add(new Graphic({
geometry:point,
symbol:symbol
}));
view.center = point;
}).catch(err => {
console.log(err);
})
},
//清除定位图层
clearPostionLayer(viewId){
var view = maps[viewId];
view.graphics.removeAll();
}
}
}