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?
Solved! Go to Solution.
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...
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);
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...
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);