function coordinate(result,Point,SpatialReference,GeometryService,ProjectParameters){
var data=[];
for(var i=0;i<result.length;i++){
var geometryService = new GeometryService("http://localhost:6080/arcgis/rest/services/Utilities/Geometry/GeometryServer");
var incoord = 4549; //当前坐标系
var outcoord = 4490; //目标坐标系
var x=result[i]["x"];
var y=result[i]["y"];
var inSR = new SpatialReference({wkid: incoord });
var outSR = new SpatialReference({wkid: outcoord});
var inputpoint = new Point(x,y, inSR);
var PrjParams = new ProjectParameters();
PrjParams.geometries = [inputpoint];
PrjParams.outSR = outSR;
geometryService.project(PrjParams,function(outputpoint){
data.push(outputpoint);
});
}
return data;
}
$(document).ready(function(){
require([
"esri/geometry/Point","esri/SpatialReference","esri/tasks/GeometryService","esri/tasks/ProjectParameters",
"dojo/domReady!"
], function(Point,SpatialReference,GeometryService,ProjectParameters) {
var type=$(":radio[name='optionsRadios']:checked").val();
var stime=$("#class_time option:selected").val();
var data=[];
$.ajax({
type:"post",
async:true,
url:"../zj/Aggregation.action",
data:{"type":parseInt(type),"stime":stime},
dataType: "json", //返回数据形式为json
success:function(result){
var d=result.slice(0,3);
var data=coordinate(d,Point,SpatialReference,GeometryService,ProjectParameters);
console.log(data);
}
});
});
});
需要将数据添加到data里面然后返回,但geometryService.project这个方法里面有个回调函数.第一张图是输出结果,但那个空的数组点开是由内容的。
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…