AnsweredAssumed Answered

Modify Renderer of FeatureLayer

Question asked by azatrain on Apr 2, 2015
Latest reply on May 31, 2016 by LDanzinger-esristaff

I am trying to modify the renderer on a FeatureLayer from a local geodatabase and have not had much success.  I can see my modifications to the renderer when I console.log its json, but the changes do not get applied to the layer in the map.  FeatureLayer does not have a refresh like dynamic map layers do, so I'm not sure how to update the layer in the map so it reflects the changes I made to the renderer.   I have included my code below.  Does anyone have any ideas?

 

import QtQuick 2.3

import QtQuick.Controls 1.2

import ArcGIS.Runtime 10.25

import ArcGIS.Extras 1.0

 

 

ApplicationWindow {

    id: appWindow

    width: 800

    height: 600

    title: "SmallSymbolFix"

 

    property string m_LocalDataPath: System.userHomeFolder.path + "/Documents"

 

 

    Map {

        id: appMap

        anchors.fill: parent

        wrapAroundEnabled: true

 

        ArcGISTiledMapServiceLayer {

            url: "http://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer"

        }

 

        onStatusChanged: {

           if (status === Enums.MapStatusReady)

              damageGdb.path = m_LocalDataPath + "/EpochField/Data/DamageAssessment/WorkAssignments.geodatabase"

        }

 

        FeatureLayer {

            id: featLyr

            featureTable: featTab

 

            onStatusChanged: {

                if (status === Enums.LayerStatusInitialized) {

                    var newRenderer = ArcGISRuntime.createObject("UniqueValueRenderer");

                    var oldRenderer = featLyr.renderer;

 

                    for (var l = 0; l < oldRenderer.uniqueValues.length; ++l) {

                        var newSym = ArcGISRuntime.createObject("PictureMarkerSymbol");

                        newSym = oldRenderer.uniqueValues[l].symbol

                        newSym.height = 40;

                        newSym.width = 40;

 

                        var newUVI = ArcGISRuntime.createObject("UniqueValueInfo");

                        newUVI = oldRenderer.uniqueValues[l];

                        newUVI.symbol = newSym;

                        //console.log("\n\nNEW SYMBOL: " + JSON.stringify(newSym.json));

 

                        newRenderer.addValue(newUVI);

                    }

 

                    featLyr.renderer = newRenderer;

                    console.log("\n\nNEW RENDERER: " + JSON.stringify(newRenderer.json));

                }

            }

        }

    }

 

    Geodatabase {

        id: damageGdb

 

        onValidChanged: {

            if (valid) {

                //  Add feature layer to map

 

                var gdbFeatTab = geodatabaseFeatureTable("Work Assignment");

                var operLayer = ArcGISRuntime.createObject("FeatureLayer");

                operLayer.featureTable = gdbFeatTab;

                appMap.addLayer(operLayer);

            }

        }

    }

 

    GeodatabaseFeatureTable {

        id: featTab

        geodatabase: damageGdb.valid ? damageGdb : null

        featureServiceLayerName: "Work Assignment"

 

        onGeodatabaseFeatureTableValidChanged: {

            if (geodatabaseFeatureTableValid) {

                console.log("Work Assignment feature table is initialized ...")

            }

        }

    }

}

Outcomes