ArcGIS ClassBreaksRenderer with local JSON



我一直在尝试使用ArcGIS JS API中的ClassBreaksRenderer根据属性为多边形着色。我的数据源是一个本地json文件,我怀疑这是它不工作的原因。我基于文档中提供的示例进行测试:https://developers.arcgis.com/javascript/3/jssamples/renderer_class_breaks.html在这里我可以替换FeatureLayer指针如下:

原始:

var featureLayer = new FeatureLayer("https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3", ...

替换:

var featureLayer = new FeatureLayer("./data/check.json", ...
当点击多边形时,geojson层渲染和所有属性在弹出框中都是可见的,但我似乎无法对文件应用任何颜色,它只是以默认的半透明绿色渲染。事实上,唯一能改变json图层颜色的方法就是使用简单的渲染器:esri/renderers/SimpleRenderer然后按如下配置,否则仍然遵循ClassBreaksRenderer的示例:

var simpleJson = {
 "type": "simple",
 "label": "",
 "description": "",
 "symbol": {
     "color": [255,0,50,200],
     "style": "esriSFSSolid",
     "type": "esriSFS"
    }
}
featureLayer.renderer = new SimpleRenderer(simpleJson);

我想知道API是否不支持本地json文件,在这种情况下,我将考虑切换到这个项目的传单。

你是对的,你不能在本地文件系统中实例化一个带有uri的FeatureLayer,它应该是任何有效格式(ArcGIS REST, WMS等)的有效REST服务。

在你的场景中,你能做的是使用一个featurecall来构建你的FeatureLayer,然后继续。

看一下这个例子:https://developers.arcgis.com/javascript/3/jssamples/fl_featureCollection.html

如果有帮助请告诉我。

最新更新