我有一个返回Json字符串的webApi
[{"MapEast":504743,"MapNorth":439624},{"MapEast":504736,"MapNorth":439622},{"MapEast":504775,"MapNorth":439722},{"MapEast":504739,"MapNorth":439738},{"MapEast":504774,"MapNorth":439715},{"MapEast":504739,"MapNorth":439734},{"MapEast":504773,"MapNorth":439711},{"MapEast":504739,"MapNorth":439728},{"MapEast":504773,"MapNorth":439705},{"MapEast":504739,"MapNorth":439724},{"MapEast":504773,"MapNorth":439699},{"MapEast":504743,"MapNorth":439718},{"MapEast":504773,"MapNorth":439694},{"MapEast":504743,"MapNorth":439713},{"MapEast":504776,"MapNorth":439688},{"MapEast":504742,"MapNorth":439708},{"MapEast":504773,"MapNorth":439680},{"MapEast":504743,"MapNorth":439703},{"MapEast":504774,"MapNorth":439674},{"MapEast":504742,"MapNorth":439698},{"MapEast":504773,"MapNorth":439668},{"MapEast":504743,"MapNorth":439693},{"MapEast":504773,"MapNorth":439663},{"MapEast":504740,"MapNorth":439688},{"MapEast":504773,"MapNorth":439658},{"MapEast":504742,"MapNorth":439679},{"MapEast":504775,"MapNorth":439653},{"MapEast":504742,"MapNorth":439676},{"MapEast":504743,"MapNorth":439670},{"MapEast":504742,"MapNorth":439665},{"MapEast":504742,"MapNorth":439660},{"MapEast":504741,"MapNorth":439656},{"MapEast":504741,"MapNorth":439650},{"MapEast":504741,"MapNorth":439645},{"MapEast":504740,"MapNorth":439640},{"MapEast":504741,"MapNorth":439634},{"MapEast":504740,"MapNorth":439631}]`我需要弄清楚如何将这些数据放在arcMap javascript中创建一个层。
function updateExtent(){
var myMultiPoint = {
"geometry":{
"points":[[504743,439624],[504736,439622],[504775,439722]],
"spatialReference":27700
},
"symbol":{
"color":[255,255,255,64],
"size":12,
"angle":0,
"xoffset":0,
"yoffset":0,
"type":"esriSMS",
"style":"esriSMSCircle",
"outline":{
"color":[0,0,0,255],
"width":1,
"type":"esriSLS",
"style":"esriSLSSolid"
}
}
};
var gra = new esri.Graphic(myMultiPoint);
myMap.graphics.add(gra);
var graExtent = esri.graphicsExtent(myMap.graphics.graphics);
myMap.setExtent(graExtent);
}我已经测试了上面的代码,它可以创建图层,并且工作正常。我只需要一些指导,说明如何将json数据从webApi导入到myMultiPoint变量创建中。
谢谢
发布于 2014-01-31 13:46:12
使用此方法将JSON数据转换为points数组:
var myData = JSON.parse('[{"MapEas... ...9631}]');
var points = myData.map(function(x){
return [x.MapEast, x.MapNorth];
});然后,您可以简单地将其添加如下:
var myMultiPoint = {
"geometry":{
"points":points, // Just reference the array, here.
"spatialReference":27700
},
"symbol":{
"color":[255,255,255,64],
"size":12,
"angle":0,
"xoffset":0,
"yoffset":0,
"type":"esriSMS",
"style":"esriSMSCircle",
"outline":{
"color":[0,0,0,255],
"width":1,
"type":"esriSLS",
"style":"esriSLSSolid"
}
}
};发布于 2017-07-31 04:37:19
您可以使用以下任何一种方法将json转换为esri.Geometry:
JsonUtils (esri/geometry/jsonUtils)或esri.geometry.fromJson法以下是代码:
方法一(使用)
require(
["esri/map", "esri/geometry/jsonUtils", "esri/config", "dojo/domReady!"],
function (Map, JsonUtils, esriConfig) {
var jsonGeometry = {"x":10,"y":20,"spatialReference":{"wkid":3857}};
//Note: you should not use JsonUtils.fromJson(JSON.stringify(jsonGeometry))
var geometry = JsonUtils.fromJson(jsonGeometry);
var graphic = new esri.Graphic(firstGeometry);
});方法二(使用方法)
var jsonGeometry = {"x":10,"y":20,"spatialReference":{"wkid":3857}};
var geometry = esri.geometry.fromJson(jsonGeometry);
var graphic = new esri.Graphic(geometry);https://stackoverflow.com/questions/21481510
复制相似问题