add data widget Renderer error getFieldsUsedInExpressions is not a function

346
3
Jump to solution
08-11-2020 05:48 AM
deleted-user-wcpelUUf_XXx
New Contributor III

Im creating a widget to upload a specific shp file.

using the add data widget with only the 'file' enabled.

I have added a renderer to the code from the output of a service of the same layer extracting it using layer.renderer,

i get the error "getFieldsUsedInExpressions is not a function".

this is the code from AddFromFilePane file inside /search of add data widget

added line 15 end the renderer

    _addFeatures: function(job,featureCollection) {
//var triggerError = null; triggerError.length;
var fullExtent, layers = [], map = job.map, nLayers = 0;
var loader = new LayerLoader();
if (featureCollection.layers) {
nLayers = featureCollection.layers.length;
}
array.forEach(featureCollection.layers,function(layer) {
var featureLayer = new FeatureLayer(layer, {
id: loader._generateLayerId(),
outFields: ["*"]
});
featureLayer.xtnAddData = true;
if (featureLayer.graphics) {
featureLayer.renderer = {
"_cache": {
"rotationInfo": null,
"colorInfo": null,
"opacityInfo": null,

*only the start of the renderer for comfort 

full file as txt:

https://codepen.io/segev-salman/pen/NWNGpOz?editors=1000 

0 Kudos
1 Solution

Accepted Solutions
CarlosNantes
New Contributor III

You probably have to instantiate a proper Renderer object.

From the docs (FeatureLayer | API Reference | ArcGIS API for JavaScript 3.33 :(

Here you have plain object without methods, only properties:

 featureLayer.renderer = {
        "_cache": {
    "rotationInfo": null,
    "colorInfo": null,
    "opacityInfo": null,

It probably should be something like this :

 var renderer = new SimpleRenderer({ ClassBreaksRenderer, or UniqueValueRenderer.
    "rotationInfo": null,
    "colorInfo": null,
    "opacityInfo": null,
...
});

featureLayer.setRenderer(renderer);

View solution in original post

3 Replies
CarlosNantes
New Contributor III

You probably have to instantiate a proper Renderer object.

From the docs (FeatureLayer | API Reference | ArcGIS API for JavaScript 3.33 :(

Here you have plain object without methods, only properties:

 featureLayer.renderer = {
        "_cache": {
    "rotationInfo": null,
    "colorInfo": null,
    "opacityInfo": null,

It probably should be something like this :

 var renderer = new SimpleRenderer({ ClassBreaksRenderer, or UniqueValueRenderer.
    "rotationInfo": null,
    "colorInfo": null,
    "opacityInfo": null,
...
});

featureLayer.setRenderer(renderer);

View solution in original post

deleted-user-wcpelUUf_XXx
New Contributor III

good catch, the renderer from the original layer seems to be a uniquevalue, with the value field already inside.

adding it to the function undid the error but the layer is still 'invisble'*.

asking for a console.log of the featureLayer renderer after setting it returns a renderer object with undefined in every field.

do i need to delete something from the renderer or cycle through like a graphic layer symbology?

does a 'raw' renderer object from a layer needs to be changed before being set?

in the sample they made the renderer from scratch but i seem to have everything inside the object.

*the add data widget as shp works and i can highlight the polygons through the table attrubute table they just have no symbology now.

full file V2 as txt:

https://codepen.io/segev-salman/pen/gOrayBR?editors=1000 

0 Kudos
deleted-user-wcpelUUf_XXx
New Contributor III

so here some of the answers to my questions;

instead of copying it with 'copy(layer.renderer)' i used copy(json.stringify(layer.renderer.toJSON())

do i need to delete something from the renderer? 

the object has a delimeter attribute that should be deleted.

cycle through like a graphic layer symbology?

no, at least i don't think so setting the renderer worked for changing the symbology when getting the graphics.

now the problem is the symbology, the add data layer is losing some of the not simple symbols:

original symbology in the layernew symbology on add data layer

0 Kudos