rexbradford

Avoid requery on feature layer?

Discussion created by rexbradford on May 24, 2012
Latest reply on May 29, 2012 by rexbradford
I have a layer of country polygons that I am color-coding based on dynamic metrics.  My problem is not one of functionality but performance - the country polygons are requeried every time I want to change the color-coding symbols (fill color) associated with them.

The layer is created with code like this:

 var countryLayer = new esri.layers.FeatureLayer(urltools.fixServerURL(layerInfo.url), { 
       id: layerID, 
       mode: esri.layers.FeatureLayer.MODE_ONDEMAND, // neither ONDEMAND nor SNAPSHOT works as I'd like
//       mode: esri.layers.FeatureLayer.MODE_SNAPSHOT, 
       opacity: 0.75,
       outFields: ["*"] });


When I want to update the map to change the color-coding of countries, after some computation I assign new symbols with code like this:

    // Go thru all countries, computing the color for each and changing its symbol    
    for (var ic = 0; ic < mapLayers.countryCodeList.length; ic++) {
        var ccode = mapLayers.countryCodeList[ic];
        var csym = csymNoData;
        var val = mapData.currDataView.cntryVals[ccode]
        var index = _getRangeIndexForData(val);
        if (index >= 0)
            csym = options.cranges[index].csym;
//        console.log("cntry: " + ccode + " val: " + cntryVals[ccode] + " color: " + csym.r + "," + csym.g + "," + csym.b);
        mapLayers.countrySymbols[ccode] = new esri.symbol.SimpleFillSymbol().setColor(csym);
        mapLayers.renderer.removeValue(ccode);
        mapLayers.renderer.addValue({value: ccode, symbol: mapLayers.countrySymbols[ccode],
            label: "Label: " + ccode, description: "Description: " + ccode});
    }


Nothing is updated unless I call refresh(), but that causes a refetch over the internet tubing:

    mapLayers.countryLayer.refresh();


Is there a way for me to dynamically update the country colors without continually refetching the same unchanging boundary data?

Thanks,

Rex Bradford
Direct Relief International

Outcomes