Select to view content in your preferred language

Supported Operations on Layers -- attention to esri.layers.FeatureLayer().queryIds

1867
8
12-09-2010 02:45 PM
GregCorradini
Emerging Contributor
Hello,
When i use two different MapServer layers to create an instance of esri.layers.FeatureLayer and execute the queryIds method I get different results. I assume the difference in results is the product of each layer's Supported Operations.

This layer
("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/Since_1970/MapServer/0")
has a Supported Operation of "Query" whereas this other layer
("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3")
has a Supported Operations of type "Query_Layer".

The earthquake layer (the former example) will return only the objectIds as intended when you call the featurelayer.queryIds() method, but the demographic layer (the latter example) returns a JSON object of all attributes.

My question is simple. Where is the documentation that explains the differences between how to interact with different Supported Operations of a Feature Layer? There is NO warning/mention in the JavaScript API Reference under FeatureLayer or under Query about this behavior with different Supported Operations. I spent 1.5 hours trying to figure out why I was getting different results from each layer.

I would think that at least when I execute featurelayer.queryIds(query, callback) against a MapServer layer that only has a Supported Operations of "Query_Layer" I would get an error or something telling me this MapServer layer doesn't do that.

Maybe I'm missing something and  someone can point me to some documentation that I didn't see that explicitly explains this. Ideas?

Thanks
0 Kudos
8 Replies
KristofVydt
Emerging Contributor
Without being able to answer your question, I'd like to give 2 remarks:

Note 1: You are comparing an ArcGIS Server 9.3.1 map service with an ArcGIS Server 10 map service.

Note 2: Both operations are called "query", but just get another label on the HTML page.
- http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3/...
- http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/Since_1970/MapServer/0/query

Both can be queried on ID:
- http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3/...
- http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/Since_1970/MapServer/0/query?...

Kristof Vydt
Esri Certified Desktop Associate
Esri BeLux
0 Kudos
KristofVydt
Emerging Contributor
At 10, support for query based on objectIds was added.

At 10, query operation returns additional fields array (JSON and AMF only) that contains array of field information for returned values.  This array contains only fields specified in outFields parameter.

(source: http://sampleserver3.arcgisonline.com/ArcGIS/SDK/REST/query.html)

Kristof Vydt
Esri Certified Desktop Associate
Esri BeLux
0 Kudos
GregCorradini
Emerging Contributor
Hey Kristof Vydt,

Thanks for your comments. I was aware that the difference between the MapServer layers was based on the difference between ArcGIS Server 9.3.1 and ArcGIS Server 10. I was just interested to find the documentation on this difference.

You did answer my question as to where it is documented. Thanks 🙂

It looks like the lesson is this: I should be reading the AGS REST API because it has more detail in some areas than the JavaScript API Reference.

Though I would argue that some of that detail in the AGS REST API should be duplicated in the JavaScript API Reference because that's probably where most people building with this solution go first.

I'd also like to see a section in one of the APIs explicitly talking about what the difference between the Supported Operations means for different versions of the API and different types of operations. While AGS REST API does provide an overview of the ideas here, neither API reference talks about the specific examples that I can see yet.

Thanks for your help
0 Kudos
GregCorradini
Emerging Contributor
One more thing Krystof,

I fear that my first post wasn't clear enough about the problem. I'm not interested in querying on ID but getting a response of only IDs form the map service.

The confusion happens between these different 10.0 (example 1) and 9.3.1 (example 2) map service calls. Notice how the returnsIdOnly parameter in the URL equals 'true' for the 9.3.1 map service request also. So i guess that extra information is ignored because it isn't supported. For some reason I thought this would throw some kind of error though. But I'm no JS Dev whiz.

1) featurelayer.queryIDs() for 10.0 map service

2) featurelayer.queryIDs() for 9.3.1 map service
0 Kudos
timgogl
Deactivated User
is this the same issue joanv was having here?

i think they got an answer there towards the end....
0 Kudos
KristofVydt
Emerging Contributor
We should indeed not mix REST and JS API.

The syntax featureLayer.queryIDs() is JS API (v2.1), but the link you added to it in your last post, is REST. Linking these doesn't make sense.

But up till now, I couldn't make it work with sampleserver1 (ArcGIS Server 9.3.1).

Querying FeatureLayer is new since v2.0 of the JS API (http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp_start.htm#jshelp/new_v20.htm) and therefore linked to ArcGIS Server 10 (I suppose).

If this assumption is correct, we still end up with the conclusion that there's no way to detect server side support.
0 Kudos
GregCorradini
Emerging Contributor
Hey Kristof,

Thanks for the input. A few things. I'm not mixing the REST and JS API. Nor am I asking to have them mixed. These APIs have a relationship. In JS API v2.0 when you call .queryIds() method on a FeatureLayer it sends a restful URL to the server with a number of parameters. One of those is returnIdsOnly, which specifies that you only want IDs returned. This happens even if you are doing .queryIds() on a 9.3.1 map service. See the example code below.

Yes, queryIds is functionality that is supported at 10.0 MapServices and not 9.3.1 MapServices. However, that doesn't mean that people aren't using the JS 2.0 API to make calls to 9.3.1 map services. ESRI's samples for JS 2.0 API are full of examples like here. Sure, people SHOULD know that they won't be able to use the full functionality of the 2.0 API against old map services (as I did when I started this last week). But that doesn't mean they won't forget.

And they will try to make 2.0 method calls (like queryIds()) by mistake and there is NO mention of these problematic version conflicts in the JS 2.0 API. That's all I'm saying. Wouldn't it be nice if people using the new 2.0 FeatureLayer had a sentence at the beginning of this doc saying a word or two reminding them that certain methods are going to get unexpected results when using 9.3.1 map services. Right now the ONLY mention of this potentiality is here. I don't think that is a unreasonable request. Just trying to make the documentation better.

Why do I think this is confusing for some people? Because when you're using the JS API v2.0 .queryIds() method  on a 9.3.1 MapService (see code example below) even if you shouldn't be it still works -- and you still get features back and it still executes your callback all is if the 9.3.1 map service supports that call in a weird way. No errors returned. Not too confusing once you figure it out. But it kept me going for an hour. See the actual requests generated from the script below at the very bottom of this post.

function initQueryIDCalls(){

 var mapService931URL = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3";
 var mapService10URL = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/Since_1970/MapServer/0";
 
 featurelayer931 = new esri.layers.FeatureLayer(mapService931URL, {mode: esri.layers.FeatureLayer.MODE_SNAPSHOT});
 featurelayer10 = new esri.layers.FeatureLayer(mapService10URL, {mode: esri.layers.FeatureLayer.MODE_SNAPSHOT});
 
 var query = new esri.tasks.Query();
 query.where = "1=1";
 
 featurelayer931.queryIds(query);
 featurelayer10.queryIds(query);
  
}




1) JS API 2.0 queryIds() request on 9.3.1 Map Service

2) JS API 2.0 queryIds() request on 10.0 Map Service
0 Kudos
KristofVydt
Emerging Contributor
You convinced me completely.
0 Kudos