Push values from FeatureLayer into JavaScript array

910
4
Jump to solution
02-11-2018 08:00 AM
MichaelLodes2
Occasional Contributor

Hi all,

I'm working with JS 4.6.

I want to query the table of a FeatureLayer to get all of its containing values and then push it into a JavaScript array? I can't find any sample code.

My FeatureLayer ist hosted on ArcGis Online. This is my code but I get featureset "length: 0" in my console

    var queryStatesTask  = new QueryTask({
      url: "..."
    });
      var query = new Query();
        queryStatesTask.execute(query).then(function(result){
          console.log(result.features);
         });
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Michael,

  Your Query Class needs a where property and outFields and optionally outSpatialReference.

var query = new Query();
query.where = "1=1";
query.outFields = ["*"];
query.outSpatialReference = map.spatialReference;

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

Michael,

  Your Query Class needs a where property and outFields and optionally outSpatialReference.

var query = new Query();
query.where = "1=1";
query.outFields = ["*"];
query.outSpatialReference = map.spatialReference;
MichaelLodes2
Occasional Contributor

Thank you Robert for your fast reply. They are all in the same spatial reference, so I think I don't need the

query.outSpatialReference = map.spatialReference;

I still get length: 0 as result in the console

Is there something wrong with my layer? Its a "hosted feature layer" on ArcGis Online containing 59 features. It is also set as "Public (everyone)".

    var queryStatesTask  = new QueryTask({
      url: "https://services6.arcgis.com/zsStDqlI7B7GPAe2/arcgis/rest/services/Hundestation/FeatureServer"
    });
      var query = new Query();
        query.where = "1=1";
        query.outFields = ["*"];
        queryStatesTask.execute(query).then(function(result){
          
          console.log(result.features);
         });
0 Kudos
MichaelLodes2
Occasional Contributor

btw: How can I debug such things... It's very difficult to notice the problems...

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Michael,

   You need to use a url that is specific to the layer of the service you want to query:

https://services6.arcgis.com/zsStDqlI7B7GPAe2/ArcGIS/rest/services/Hundestation/FeatureServer/0