绘制要素图层面的质心

Plot Centroid of Feature Layer Polygon

本文关键字:图层 绘制      更新时间:2023-09-26

这是我正在使用的其余服务:http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3

我目前对显示要素图层的要求如下:

var recLayer = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3",{
    infoTemplate: recParkTemplate,
    outFields: ["STATE_NAME"]
  });
map.addLayer(recLayer);

但是,不是在地图上绘制面,因为这是一个 esriGeometricPolygon。我宁愿让它像 esriGeometryPoint 一样在地图上绘制。我知道这种方法可以获取特定多边形的质心:

https://developers.arcgis.com/javascript/jsapi/polygon-amd.html#getcentroid

我的问题是我无法弄清楚如何在要素图层中的所有面之间循环,然后绘制这些面。我只能指向并单击并显示与此 ESRI 示例的工作方式类似的方式:https://developers.arcgis.com/javascript/jssamples/util_label_point.html

感谢您的协助。如果您想查看一下,这里是当前网站:http://joshferrell.net/ece_project/

要在要素图层中的所有几何之间循环,您可以执行以下操作:

            recLayer.on("update-end", function changeHandler(evt) {
            require(["dojo/_base/array"], function (array) {
                array.forEach(recLayer.graphics, function (entry, i) {
                    console.debug(entry, "at index", i);
                });
            });
        });

在循环内使用 getCentroid 并将结果添加到地图中