uniqueValues function error

162
1
Jump to solution
01-24-2019 12:04 PM
LenielMaccaferri
New Contributor II

Hello,

I'm trying to make use of uniqueValues function: uniqueValues | API Reference | ArcGIS API for JavaScript 4.10 

However, it's failing with this message:

message: "view is required to query stats from layerView"
name: "feature-layer-adapter:insufficient-data"

I have a FeatureLayer with features and a field called sStatus... I also have a Legend setup that is working just fine with a UniqueValueRenderer based on this sStatus field.

This is my code:

uniqueValues({
layer: layer,
field: "sStatus"
}).then(function (response) {
// prints each unique value and the count of features containing that value
var infos = response.uniqueValueInfos;

console.log('test');

infos.forEach(function (info) {
console.log("Wells : ", info.value, " # OF CAMPAIGN STOPS: ", info.count);
});
}).catch(errback);

Note: if I change the field name to something as "status" the error message in the Console changes:

message: "Unknown fields: status. You can only use fields defined in the layer schema"
name: "unique-values:invalid-parameters"

This shows that my field sStatus is right but I don't get why it doesn't work out of the box.

Any ideas why this is failing?

0 Kudos
1 Solution

Accepted Solutions
LenielMaccaferri
New Contributor II

Ohhh... after I posted the question I got the answer by re-reading the uniqueValues function documentation.

The message was clear in the first place: it was missing the view.

There's a view parameter for the uniqueValues function that was not part of the sample code...

view View

optional

A SceneView or MapView instance is required when a valueExpression is specified.

So what I had to do was this:

uniqueValues({
layer: layer,
field: "sStatus",

view: mapView
}).then(function (response) {
// prints each unique value and the count of features containing that value
var infos = response.uniqueValueInfos;

console.log('test');

infos.forEach(function (info) {
console.log("Wells : ", info.value, " # OF CAMPAIGN STOPS: ", info.count);
});
}).catch(errback);

View solution in original post

0 Kudos
1 Reply
LenielMaccaferri
New Contributor II

Ohhh... after I posted the question I got the answer by re-reading the uniqueValues function documentation.

The message was clear in the first place: it was missing the view.

There's a view parameter for the uniqueValues function that was not part of the sample code...

view View

optional

A SceneView or MapView instance is required when a valueExpression is specified.

So what I had to do was this:

uniqueValues({
layer: layer,
field: "sStatus",

view: mapView
}).then(function (response) {
// prints each unique value and the count of features containing that value
var infos = response.uniqueValueInfos;

console.log('test');

infos.forEach(function (info) {
console.log("Wells : ", info.value, " # OF CAMPAIGN STOPS: ", info.count);
});
}).catch(errback);

View solution in original post

0 Kudos