如果您引用下面的图像,JSON字符串和代码片段,它会概述代码,控制台输出以及尝试使用ESRI ArcGIS Javascript API绘制多边形(或任何几何/图形)的预期行为。不知道发生了什么......请帮忙!
JSON字符串:
{"几何" {"环":[[[ - 91.89013671874848,38.03029444608522],[ - 91.653930664061,38.00865683368494],[ - 91.64843749999851,38.00432854459864],[ - 91.5935058593735, 37.93070854451552],[ - 91.577026367186,37.88303274722063],[ - 91.577026367186,37.79192956603227],[ - 91.631958007811,37.73982010276601],[ - 91.70886230468598,37.73547599031287],[ - 91.763793945311,37.76587942393493],[ - 91.85168457031098,37.85701474874939],[ - 91.88464355468598,37.9956711998967 ],[ - 91.89013671874848,38.03029444608522]]],"的SpatialReference" {" WKID":4326}},"符号" {"颜色&# 34;:[0,0,0,64],"概要" {"颜色":[0,0,0,255]"宽度":1 "类型":" esriSLS""风格":" esriSLSSolid"}"类型":&#34 ; esriSFS""风格":" esriSFSSolid"}}
将形状添加到地图的代码:
{ test: /\.png$/, loader: "url-loader?mimetype=image/png" }
答案 0 :(得分:4)
图像中显示的JSON字符串用于Graphic
对象,而不是几何。如您所见,它包含geometry
& symbol
,如果将其传递给Graphic,它将起作用。
map.graphics.add(new Graphic(jsontext));
或者,如果您只想要多边形,那么您的代码应该是这样的。
var polygon = new esri.geometry.Polygon(jsontext.geometry);
此外,不要将传统和AMD风格结合在一起。
答案 1 :(得分:0)
正如T Kambi所说,你的字符串是图形而不是几何,但我将在json和esriGeometry之间转换时展示一些想法。
您可以使用以下任意方式将 json 转换为esri.Geometry
:
JsonUtils
(esri/geometry/jsonUtils
)或esri.geometry.fromJson
方法。 以下是代码:
方法一(使用JsonUtils
)
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);
});
方法二(使用geometry.fromJson
方法)
var jsonGeometry = {"x":10,"y":20,"spatialReference":{"wkid":3857}};
var geometry = esri.geometry.fromJson(jsonGeometry);
var graphic = new esri.Graphic(geometry);