I have a map service that has 2 layers. One is a polygon layer that contains a single large polygon, and the other is a point layer that contains many points located both inside and outside of the large polygon.
I've turned both layers into FeatureLayers
:
var polygonFeatureLayer= new FeatureLayer(myPolygonLayer, {
outFields: ["*"]
});
var pointFeatureLayer= new FeatureLayer(myPointLayer, {
outFields: ["*"]
});
And I want to use a Geometry Service to find out how many points are located within the polygon.
geometryService = new GeometryService(myGeometryService);
var relationParams = new RelationParameters();
relationParams.geometries1 = myPolygonGeometry;
relationParams.geometries2 = myPointGeometries;
relationParams.relation = RelationParameters.SPATIAL_REL_WITHIN;
geometryService.relation(relationParams).then(addRelateResultsToMap);
But I can't figure out how to get the geometry of the features from the FeatureLayer.
I thought the most obiously way was to use the FeatureLayers's graphics
property which supposedly returns an array of Graphics for each feature in the layer.
I then figured after that I'd use graphicsUtils method getGeometries()
which supposedly returns an array of Geometries for each graphic in the array.
Hey! That sounds great! Exactly what I need, but I can't get it to work.
I did a simple test:
var polygonFeatureLayer= new FeatureLayer(myPolygonLayer, {
outFields: ["*"]
});
map.addLayers([polygonFeatureLayer]);
polygonFeatureLayer.on("load", getPolygonGeometry);
function getPolygonGeometry(evt) {
console.log(graphicsUtils.getGeometries(polygonFeatureLayer.graphics));
}
}
The console just logs an empty array []
.
In my mind this should work. Any idea why it doesn't? What do I need to do to get this to work?
EDIT
If you have a different approach, then I'll consider it, but it has to work knowing that both layers are part of a map service.