I have a series of functions that create CSVLayers, add them to the map, remove them, and refresh them. See below. However, when the refresh script is called the data is created/updated, but the .show() will not show the layers that are called. Can anyone explain this?
var csv60min;
var csv60mintextLayer;
function csv60minfunc () {
csv60min = new CSVLayer("symGSPHydroViewer/data/60query.csv",{id:"csv60min"});
csv60min.on("update-end", function(results){
csv60mintextLayer = new GraphicsLayer({id:"csv60mintextLayer"});
arrayUtils.forEach(results.target.graphics, function(feature, index){
var lid = feature.attributes.lid;
var name = feature.attributes.name;
var value = feature.attributes.value;
var ffg = feature.attributes.ffg;
var ratio = feature.attributes.ratio;
var validtime = feature.attributes.obstime;
var attr = {"Location ID":lid,"Location Name":name,"Obs Value":value,"FFG":ffg,"Ratio of FFG":ratio,"Obs Valid Time":validtime};
var geom = feature.geometry;
var displayText = feature.attributes.value;
var font = new Font("12pt",Font.STYLE_NORMAL, Font.VARIANT_NORMAL,Font.WEIGHT_BOLD,"Helvetica");
var textSymbol = new TextSymbol(displayText,font,new Color("#FF0000"));
csv60mintextLayer.add(new Graphic(geom, textSymbol, attr));});
var infoTemplate = new InfoTemplate("Attributes", "${*}");
csv60mintextLayer.setInfoTemplate(infoTemplate);
map.addLayer(csv60mintextLayer);
csv60mintextLayer.hide();
});
var blank = new Color([0, 0, 0, 0]); // hex is #ff4500
var marker = new SimpleMarkerSymbol("solid", 0, null, blank);
var renderer = new SimpleRenderer(marker);
csv60min.setRenderer(renderer);
map.addLayer(csv60min);
csv60min.hide();
}
function getVisibleCSVs(){
var visiblelayers = [];
var CSVlayers = [csv60min,csv60mintextLayer];
for (index = 0; index < CSVlayers.length; ++index) {
templayer = CSVlayers[index];
if (templayer.visible) {
console.log("VISIBLE: " + templayer.id);
visiblelayers[visiblelayers.length] = templayer
}
}
// console.log("VISIBLE Layers: " + visiblelayers);
return visiblelayers
}
function RefreshCSVLayers(){
console.log("Refreshing CSV Layers");
visiblealt = getVisibleCSVs()
console.log("VISIBLE ALT: " + visiblealt);
map.removeLayer(csv60min);
map.removeLayer(csv60mintextLayer);
if (visiblealt.indexOf(csv60min) > -1){
console.log("YES");
csv60minfunc();
csv60min.show();
csv60mintextLayer.show();
}