7

I've created this wrapper around feature layer where I create the empty feature layer as is in the API help page :

new FeatureLayer(featureCollectionObject, options?)

providing the first parameter an object (not url) and some options as the second paramater. then I fill this feature layer with my data that I get from my service (not the esri map service btw)...

So the features are on the map (what a beauty) and then I want to query them, but it seems like this api doesn't do the client side queries with where clause... using queryFeatures or selectFeatures doesn't matter, it always ends up with

"FeatureLayer::_query - query contains one or more unsupported parameters"

I can create my own wrapper and loop through the feature atrributes, and then set them selected based on my search criteria, but I want feature layer to do it for me, without having to send a request to a url (which doesn't exist in our case).

Simple test, now with a proper feature layer (instantiated using the url) with the SNAPSHOT mode, one would expect that query with a where clause would be performed on the client side, but no, it actually sends a request to a server (what for when I have all the data on client?)

I've reused someone else's jsfiddle here -> jsfiddle .Just click in the map to run simple query ("resolution = 3") and you can see it fails.

Can anyone shed more light into this for me please?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Sep 2, 2014 at 7:50
3
  • Did you ever get around this? Pretty lame to not allow this functionality. Commented Dec 1, 2014 at 7:07
  • yep. I'm using underscore to do all my queries now over featureLayer.graphics object. That does it quite nicely. 0 requests to server is quite nice. Commented Dec 3, 2014 at 0:33
  • I experience the same thing, it's just too bad... Commented Feb 4, 2016 at 22:39

2 Answers 2

4

This is a limitation of a feature layer built from a featureCollection. See the help file page which says:

The feature layer, when initialized with a feature collection object... does not support queries that need to be performed on the server, e.g. queries with a where clause or non-extent based spatial queries.

answered Sep 2, 2014 at 7:58
1
  • 4
    thanks. I have seen that exact note before, but still, attribute queries should be available on the client side, it's all downloaded anyway for the snapshot mode.with all respect, it's just lame and this is why esri js api is never considered as a progressive and innovative api... back to writing another wrapper, this time for querying. Commented Sep 2, 2014 at 11:39
2

This is a limitation of the client side FeatureLayer but there is one way to work around that still somewhat uses the API. The FeatureLayer will maintain it's own set of client side objectids, so while you still have to implement the actual querying yourself, you can use those objectids for selectFeatures, etc.

Example of selecting one feature based on an attribute:

// Implementing our "query" to select based on a unique field
var graphicToSelect = myFeatureLayer.graphics.filter(function(g) {
 return g.attributes.someField === myGraphic.attributes.someField;
})[0];
var query = new Query();
query.objectIds = [graphicToSelect.attributes.OID];
myFeatureLayer.selectFeatures(query);

If following this example, make sure you've set a selection symbol on the feature layer or it will look like nothing happened.

answered Mar 22, 2017 at 14:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.