Query feature layer to show graphic

4219
9
Jump to solution
02-19-2015 09:01 AM
IbrahimHussein
Occasional Contributor

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 querygraph.jpg

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

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;

View solution in original post

9 Replies
JakeSkinner
Esri Esteemed Contributor

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);

0 Kudos
IbrahimHussein
Occasional Contributor

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.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Would you be able to post all of your code?

0 Kudos
IbrahimHussein
Occasional Contributor

Yeah, heres a fiddle

Thanks

0 Kudos
JakeSkinner
Esri Esteemed Contributor

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;

IbrahimHussein
Occasional Contributor

Thanks, that worked.

0 Kudos
KenBuja
MVP Esteemed Contributor

Shouldn't that be

var graphic1 = new Graphic(results[0].feature.geometry, redSymbol1);

(no "s" in feature)

0 Kudos
IbrahimHussein
Occasional Contributor

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

0 Kudos
KenBuja
MVP Esteemed Contributor

Yes, you're correct. I was looking at another example that had the results in a different format.