Ive done this many times, but for some reason this is not working for me and I have no clue why.
The execute statement looks like
qt.execute(query, function(results) {
console.log(results.features[0]);
//symbol not used(will be used once polygon is figured out
var redSymbol1 = new SimpleFillSymbol(
SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0]), 3),
new Color([255, 0, 0, 0.4])
);
var graphic1 = new Graphic(results.features[0].geometry, redSymbol1);
//Add graphic to the map graphics layer.
map.graphics.add(graphic1);
});
the console.log mentioned above shows this has an output
Solved! Go to Solution.
It looks like the issue is related to the coordinate system of the Parcels layer. It's currently using WKID 2881. The query results are returning the results in this coordinate system, but the map's spatial reference is in Web Mercator.
You will just need to set the outSpatialReference property for the Query class to the map's spatial reference. Ex:
query.where = "PARCELID ='" + graphic.attributes["PARCELID"] + "'";
query.returnGeometry = true;
outFields = ["*"];
query.outSpatialReference = map.spatialReference;
query.outFields = outFields;
Hi Ibrahim,
I think you want to change:
var graphic1 = new Graphic(results.features[0].geometry, redSymbol1);
to
var graphic1 = new Graphic(results[0].features.geometry, redSymbol1);
Hi Jake, Thanks for the reply.
tried what you suggested and it didnt work, I put the console log as well as results[0].features and it returned an error. So I think the results.features[0] is correct.
Would you be able to post all of your code?
Yeah, heres a fiddle
Thanks
It looks like the issue is related to the coordinate system of the Parcels layer. It's currently using WKID 2881. The query results are returning the results in this coordinate system, but the map's spatial reference is in Web Mercator.
You will just need to set the outSpatialReference property for the Query class to the map's spatial reference. Ex:
query.where = "PARCELID ='" + graphic.attributes["PARCELID"] + "'";
query.returnGeometry = true;
outFields = ["*"];
query.outSpatialReference = map.spatialReference;
query.outFields = outFields;
Thanks, that worked.
Shouldn't that be
var graphic1 = new Graphic(results[0].feature.geometry, redSymbol1);
(no "s" in feature)
Hey Ken, hmm dont think so, when I view the results of the query it shows as features. tried what you suggested just in case and got a TypeError: Cannot read property 'feature' of undefined
Yes, you're correct. I was looking at another example that had the results in a different format.