I'm trying to draw the features resulting from a query of a feature layer onto a graphics layer.
var query = abstracts.createQuery();
query.where = "ANUM = '1'";
query.returnGeometry = true;
var rl = map.findLayerById("graphics");
abstracts.queryFeatures(query).then(function (results) {
rl.removeAll();
var features = results.features.map(function (graphic) {
graphic.symbol = new SimpleLineSymbol({
size: 6.5,
color: "darkorange"
});
return graphic;
});
rl.addMany(features);
});
When I set a breakpoint before the last line(rl.addMany(features)), I see that features contains the expected feature, and the symbol is set properly. Also, I know that the feature exists, but is not appearing on the map. Also, below is my declaration of feature layer and graphics layer.
var abstracts = new FeatureLayer({
url: "@arcgisServerServiceUrl/" + featureLayerId,
outFields: ["*"],
visible:false,
mode: FeatureLayer.MODE_ONDEMAND,
maxScale: 0,
minScale: 290000,
renderer: renderer,
});
var resultsLayer = new GraphicsLayer({id:"graphics"});
map.layers.addMany([
abstracts,
resultsLayer,
]);
1 Answer 1
I can't answer why what I did above didn't work, but I can give the answer I found. For each feature in results.features
above:
var polygon = new Polygon({
rings: feature.geometry.rings
});
var lineSymbol = new SimpleLineSymbol({
color: [226, 119, 40],
width: 4
});
var polygonGraphic = new Graphic({
geometry: polygon,
symbol: lineSymbol
});
resultsLayer.add(polygonGraphic);