将多边形添加到要素图层
可使用ArcGIS API for JavaScript来将多边形添加到要素图层中。示例代码如下:
require([ "esri/layers/FeatureLayer", "esri/Graphic", "esri/geometry/Polygon" ], function(FeatureLayer, Graphic, Polygon) { const featureLayer = new FeatureLayer({ url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/USA_County_Boundaries/FeatureServer/0" });
const polygon = new Polygon({ rings: [ [-122.63, 45.52], [-122.57, 45.54], [-122.52, 45.52], [-122.49, 45.48], [-122.64, 45.49], [-122.63, 45.52] ] });
const graphic = new Graphic({ geometry: polygon, attributes: { NAME: "Multnomah" } });
featureLayer.applyEdits({ addFeatures: [graphic] }); });