3

I have an ArcGIS JavaScript map that I'm trying to use with a Query Task. The query runs fine on the server side and the proper geometry is returned. Then, I draw the feature as follows:

var features = featureSet.features;

for (var i = 0; i < features.length; i++) {
    var feature = features[i];
    feature.setSymbol(lbSymbol);
    feature.setInfoTemplate(lbInfoTemplate);
    map.graphics.add(feature);
}

This was working for a while but it randomly broke and I can't figure out why. No errors -- the map just doesn't draw anything. If I listen for the graphics-add event on the graphics layer it fires and all the event data looks fine (including spatial reference, geometry, etc.) Can anyone think of why this wouldn't work or how else to troubleshoot?

For what it's worth - this code to zoom to the extent of the feature is also broken:

var extent = esri.graphicsExtent(features);
if (extent) {
    extent = extent.expand(3.0);
    map.setExtent(extent);
}

The extent of esri.graphicsExtent(features) matches the extent of the feature. Not sure why the map doesn't zoom on setExtent.

UPDATE: I noticed that graphics layer is referenced to WGS84, while the map and graphic feature are State Plane. I'm just using the built-in map.graphics layer -- I assumed this would match the spatial reference of the map automatically. Still puzzled.

2
  • are you setting outSpatialReference for the query? does this spatial reference match your map? can you post a link to broken app or write a complete fiddle pointing at a public service? Oct 16, 2013 at 5:16
  • Hi John, I'm not setting outSpatialReference but it matches the map's so I think it's okay. Unfortunately I'm using intranet services so I can't post a working link, but here is a fiddle of the relevant code: jsfiddle.net/panbalanga/Re5AB/5
    – serverpunk
    Oct 16, 2013 at 15:51

1 Answer 1

0

What do you mean "the graphics layer is referenced to WGS84?" The map's graphics layer uses the spatial reference of the map. You have to project the geometry from your query, as John Gravois said.

Is the query task talking to a map service? If so, you should use a feature layer and let it handle the results of your query.

1
  • The graphics layer (map.graphics) has a property called spatialReference with a WKID of 4326 (WGS84). The map uses State Plane. Not sure if the SR of the graphics layer matters, but it's there. The geometry of the query is the same as the map so I didn't think I would need to project. The query task is talking to a map service -- I didn't even think to use a feature layer but that sounds like a good idea. I'll try that next. Thanks!
    – serverpunk
    Oct 18, 2013 at 5:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.