Issue in Updating Unique Value Renderer of Hosted Feature Layer

221
2
02-13-2024 11:39 PM
jauhari_mani
Occasional Contributor

Hi Community,

I am trying to modify the unique value renderer of a hosted feature layer. I do not get any error on executing save() operation of the layer but the unique value renderer of the layer changes in simple renderer (default renderer of feature layer).

I have attached my JS code below. Kindly let me know what I must be doing wrong.

 

import FeatureLayer from "@arcgis/core/layers/FeatureLayer.js";
import UniqueValueRenderer from "@arcgis/core/renderers/UniqueValueRenderer.js";

const layer = new FeatureLayer({
    portalItem: {
       id: ""//Hosted Feature Layer id.
    }
});

const tempRenderer = layer.renderer.clone().toJSON();
const UniqueValueInfoTemp = {
   label: "",//label of name
   symbol: newSymbol, //Picture Maker symbol
   value: "" //same as label
};
const uniqueValueGroup = tempRenderer.uniqueValueGroups[0].classes;
const newClass = {
   label: "",//label of name
   symbol: newSymbol, //Picture Maker symbol
   value: "" //same as label
};
uniqueValueGroup.push(newClass);
uniqueValueInfos.push(UniqueValueInfoTemp);
const renderer = UniqueValueRenderer.fromJSON(tempRenderer);
layer.renderer = tempRenderer;
layer.refresh();
await layer.save();

 

Regards,
Mani

 

0 Kudos
2 Replies
UndralBatsukh
Esri Regular Contributor

Guessing the issue where you are creating the UniqueValueRenderer. Please take a look at this doc and make sure you are setting everything right: https://developers.arcgis.com/javascript/latest/visualization/data-driven-styles/unique-types/

0 Kudos
jauhari_mani
Occasional Contributor

Hi @UndralBatsukh ,

I have checked my JSON Object against the one mentioned in the link you provided they turn out to be same.

0 Kudos