由于刚接触Cesium,在加载的3DTitles数据中没有属性数据,所有需要读shp中的属性,用来进行接下来的分析功能,但是由于数据量太大,直接读取会造成内存过溢,浏览器崩掉,所以,在学长的帮助下,提议将shp数据发布服务,进行分析时(例如管线的爆管分析),点击某个管线时,获取点击的坐标,然后定义一个Geometry extent范围,查询定义的范围内的数据,来进行各种分析功能。
首先根据点击的管线,可以得到屏幕坐标,将屏幕坐标转成84坐标,可以以这个点的坐标为中心定义范围,从而查询数据
var cartesian = viewer.scene.camera.pickEllipsoid(movement.position, viewer.scene.globe.ellipsoid);//movement.position为屏幕坐标
var p=Conversion.Cartesian3ToWGS84(cartesian);
/**
* 笛卡尔坐标转WGS84
* @param Cartesian3 单个点或点数组
* @returns {lng: *, alt: *, lat: *} or {{lng: *, alt: *, lat: *},...}
*/
Cartesian3ToWGS84 : function (Cartesian3) {
if(Array.prototype.isPrototypeOf(Cartesian3)==true ){
if(!Cartesian3 || Cartesian3.length<2 || !Cartesian3[0].x) {
throw "Error in parameters";
}
if(Cartesian3&&Cartesian3.length>0&&Cartesian3[0].x&&Cartesian3[0].y&&Cartesian3[0].z){
let list=[];
for(let i=0;i
得到点坐标后,进行访问服务,定义查询范围,
require([
"esri/tasks/IdentifyTask",
"esri/tasks/IdentifyParameters",
"esri/SpatialReference",
"dojo/_base/lang",
"esri/geometry/Extent",
"esri/map",
],function(
IdentifyTask,
IdentifyParameters,
SpatialReference,
lang,
Extent,
map
) {
window.RequestPoint = {
/**
* 一米对应的经度
* @param lat 在哪个纬度
*/
oneMeter2Lng: (lat) => {
//不同纬度,地球的周长不一样
const earthLength = 2 * 6378137 * Math.PI;//赤道长度(最大长度)
let lat2EarthLength = earthLength * Math.cos(Math.abs(lat));
return parseFloat(360 / lat2EarthLength).toFixed(10);
},
/**
* 一米对应的纬度
* @param lat
*/
oneMeter2Lat: () => {
const earthLength = 2 * 6378137 * Math.PI;
return parseFloat(360 / earthLength).toFixed(10);
},
identifyQuery : (url,layerIds,Point,ServiceData)=> {
console.log(url,layerIds,Point,ServiceData);
let identifyTask = new IdentifyTask(url);
let identifyParams = new IdentifyParameters();
identifyParams.returnGeometry = true;
identifyParams.tolerance = 5;
identifyParams.layerIds = layerIds;
identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_VISIBLE;
var xmin,ymin,xmax,ymax;
xmin=Point.lng - (200*RequestPoint.oneMeter2Lng(Point.lat));
xmax=Point.lng + (200*RequestPoint.oneMeter2Lng(Point.lat));
ymin=Point.lat - (200*RequestPoint.oneMeter2Lat());
ymax=Point.lat + (200*RequestPoint.oneMeter2Lat());
//定义查询范围 大约是200m*300米范围
var Geoextent = new Extent(xmin,ymin,xmax,ymax, new SpatialReference({ wkid:4326 }));//4326代表84坐标系
identifyParams.geometry = Geoextent;
console.log(Geoextent);
identifyParams.mapExtent = Geoextent;
identifyParams.spatialReference = new SpatialReference(4326);
identifyTask.execute(identifyParams,lang.hitch(this,
(results) => {
debugger
// console.log("results:" + results);
if (lang.isFunction(ServiceData)) {
ServiceData(results, map);
}
}), (err) => {
console.log(err);
debugger
});
}
};
}
)
然后,使用
let url="http://10.10.10.181:6080/arcgis/rest/services/pro/XW/MapServer/";
RequestPoint.identifyQuery(url,[52],p,function(res){
debugger
});
等下有事。时间比较匆忙,简单记录下来,有时间补充完善。
菜鸟努力中....