Setting Graphic Attibutes from a list or array..  JSON with variables?

504
0
12-19-2012 03:39 AM
AndrewDavis
New Contributor
Hi,
The workflow I am working on assumes a user would upload a file (csv/dbf) with x/y coordinates to a web page (server php) which displays the results on a table on a client page.  The structure of the file is not concrete, so everything has to be flexible (variables and no hard coded values).

I have a function which consumes a list of coordinate pairs and generates a set of point graphics on my web map.  Now I am trying to populate the graphic attribute information as well from a sepparate list.

At first I thought that I could do this via JSON (I will state for the record I do not fullly understand JSON).  I found a post which says that JSON is a "string literal" and I think that means you can't construct JSON with variables, easily anyway.

JSON or from a list?

Thoughts are welcome...

Andy..

function drawGraphics(coordPair){         
        var myGeom = new esri.geometry.Point( {"x": coordPair[1], "y": coordPair[0]," spatialReference": {" wkid": 4326 } });
        myGeom = esri.geometry.geographicToWebMercator(myGeom);                
        var myPoint = new esri.geometry.Point();
        var infoTemplate = new esri.InfoTemplate("Attributes", "${*}");
        myPoint.geometry = myGeom; 
        myPoint.spatialReference = map.spatialReference;
        var symbol = new esri.symbol.SimpleMarkerSymbol().setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND);
        var graphic = new esri.Graphic(myPoint, symbol);
        
        //Unsure if I can do this or not.
        var myObject = {};
        myObject[graphicAttrib[0]] = graphicAttrib[1];  
        //The object created does not look like the below example I found on the API reference..                
        //graphic.setAttributes( {"XCoord":000,"YCoord":000,"Plant":"Mesa Mint"});

        map.graphics.add(new esri.Graphic(myGeom, symbol, infoTemplate));

      }
0 Kudos
0 Replies