//Add Latest RiverStages CSV Layers var riverCSVtemplate = new InfoTemplate(); riverCSVtemplate.setContent(getriverCSVTextContent); var LatestRiverStages = new CSVLayer("./data/riverquery.csv",{id:"LatestRiverStages",mode: FeatureLayer.MODE_SELECTION,outFields: ["*"],infoTemplate: riverCSVtemplate}); var Green = new Color([0, 255, 0, 1.0]); var labelField = "value"; var symbol = new TextSymbol(); symbol.setAlign = TextSymbol.ALIGN_MIDDLE; var font = new Font(); font.setSize("8pt"); font.setWeight(Font.WEIGHT_BOLD); symbol.setFont(font) symbol.setText("${" + labelField + "}") symbol.setColor(new Color(Green)); var renderer = new SimpleRenderer(symbol); LatestRiverStages.setRenderer(renderer); map.addLayer(LatestRiverStages); // LatestRiverStages.hide();
var map, csv; require([ "esri/map", "esri/layers/CSVLayer", "esri/Color", "esri/graphic", "esri/layers/GraphicsLayer", "esri/symbols/SimpleMarkerSymbol", "esri/renderers/SimpleRenderer", "esri/InfoTemplate", "esri/urlUtils", "esri/symbols/Font", "esri/symbols/TextSymbol", "dojo/on", "dojo/_base/array", "dojo/domReady!" ], function( Map, CSVLayer, Color, Graphic, GraphicsLayer, SimpleMarkerSymbol, SimpleRenderer, InfoTemplate, urlUtils, Font, TextSymbol, on, array ) { urlUtils.addProxyRule({ proxyUrl: "http://server1/proxy/proxy.ashx", urlPrefix: "skinner-lap" }); map = new Map("map", { basemap: "gray", center: [ -60, -10 ], zoom: 4 }); csv = new CSVLayer("http://server1/UserData/2.5_week.csv", { copyright: "USGS.gov" }); csv.on("update-end", function(results){ var textLayer = new GraphicsLayer(); array.forEach(results.target.graphics, function(feature, index){ var geom = feature.geometry; var displayText = feature.attributes.id; var font = new Font( "12pt", Font.STYLE_NORMAL, Font.VARIANT_NORMAL, Font.WEIGHT_BOLD, "Helvetica" ); var textSymbol = new TextSymbol( displayText, font, new Color("#DC143C") ); textLayer.add(new Graphic(geom, textSymbol)); }); map.addLayer(textLayer); }); var blank = new Color([0, 0, 0, 0]); // hex is #ff4500 var marker = new SimpleMarkerSymbol("solid", 0, null, blank); var renderer = new SimpleRenderer(marker); csv.setRenderer(renderer); map.addLayer(csv); });
//Add Latest RiverStages CSV Layers var riverCSVtemplate = new InfoTemplate(); riverCSVtemplate.setContent(getriverCSVTextContent); var LatestRiverStages = new CSVLayer("symGSPHydroViewer/data/riverquery.csv",{id:"LatestRiverStages",mode: FeatureLayer.MODE_SELECTION,outFields: ["*"],infoTemplate: riverCSVtemplate}); console.log("HERE1"); LatestRiverStages.on("update-end", function(results){ var textLayer = new GraphicsLayer(); console.log("HERE2"); array.forEach(results.target.graphics, function(feature, index){ console.log("HERE3"); 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("#DC143C") ); textLayer.add(new Graphic(geom, textSymbol)); }); map.addLayer(textLayer); }); console.log("HERE4"); var blank = new Color([0, 0, 0, 0]); // hex is #ff4500 var marker = new SimpleMarkerSymbol("solid", 0, null, blank); var renderer = new SimpleRenderer(marker); LatestRiverStages.setRenderer(renderer); map.addLayer(LatestRiverStages); console.log("HERE5");
Hi Charles,
Using the 'update-end' event for the CSVLayer class, I was able to obtain the feature's attributes, and then use this as a TextSymbol. Here is the code I used:var map, csv; require([ "esri/map", "esri/layers/CSVLayer", "esri/Color", "esri/graphic", "esri/layers/GraphicsLayer", "esri/symbols/SimpleMarkerSymbol", "esri/renderers/SimpleRenderer", "esri/InfoTemplate", "esri/urlUtils", "esri/symbols/Font", "esri/symbols/TextSymbol", "dojo/on", "dojo/_base/array", "dojo/domReady!" ], function( Map, CSVLayer, Color, Graphic, GraphicsLayer, SimpleMarkerSymbol, SimpleRenderer, InfoTemplate, urlUtils, Font, TextSymbol, on, array ) { urlUtils.addProxyRule({ proxyUrl: "http://server1/proxy/proxy.ashx", urlPrefix: "skinner-lap" }); map = new Map("map", { basemap: "gray", center: [ -60, -10 ], zoom: 4 }); csv = new CSVLayer("http://server1/UserData/2.5_week.csv", { copyright: "USGS.gov" }); csv.on("update-end", function(results){ var textLayer = new GraphicsLayer(); array.forEach(results.target.graphics, function(feature, index){ var geom = feature.geometry; var displayText = feature.attributes.id; var font = new Font( "12pt", Font.STYLE_NORMAL, Font.VARIANT_NORMAL, Font.WEIGHT_BOLD, "Helvetica" ); var textSymbol = new TextSymbol( displayText, font, new Color("#DC143C") ); textLayer.add(new Graphic(geom, textSymbol)); }); map.addLayer(textLayer); }); var blank = new Color([0, 0, 0, 0]); // hex is #ff4500 var marker = new SimpleMarkerSymbol("solid", 0, null, blank); var renderer = new SimpleRenderer(marker); csv.setRenderer(renderer); map.addLayer(csv); });
function getriverCSVTextContent (graphic) { var attributes = graphic.attributes; var value = "Obs Value: " + attributes.value; var validtime = "Valid Time: " + attributes.validtime; return value + "</b><br />" + validtime }
Hi Charles,
When are you calling this function? Can you post your code and possibly the CSV file you are using?
//Add Latest RiverStages CSV Layers var riverCSVtemplate = new InfoTemplate(); riverCSVtemplate.setContent(getriverCSVTextContent); var LatestRiverStages = new CSVLayer("symGSPHydroViewer/data/riverquery.csv",{id:"LatestRiverStages",mode: FeatureLayer.MODE_SELECTION,outFields: ["*"],infoTemplate: riverCSVtemplate}); console.log("HERE1"); LatestRiverStages.on("update-end", function(results){ var textLayer = new GraphicsLayer(); console.log("HERE2"); arrayUtils.forEach(results.target.graphics, function(feature, index){ console.log("HERE3"); 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("#DC143C") ); textLayer.add(new Graphic(geom, textSymbol)); }); map.addLayer(textLayer); }); console.log("HERE4"); var blank = new Color([0, 0, 0, 0]); // hex is #ff4500 var marker = new SimpleMarkerSymbol("solid", 0, null, blank); var renderer = new SimpleRenderer(marker); LatestRiverStages.setRenderer(renderer); map.addLayer(LatestRiverStages); console.log("HERE5"); function getriverCSVTextContent (graphic) { console.log("sample"); var attributes = graphic.attributes; var value = "Obs Value: " + attributes.value; var validtime = "Valid Time: " + attributes.validtime; return value + "</b><br />" + validtime }