Graphics Layer from MySQL Data

Discussion created by oborden2 on Jul 25, 2013

So I have a bunch of data in a MySQL DB that I'm accessing via JSONRPC. I have a AMD module that pulls the data in and creates a custom Graphic object with it. Then I store all the Graphic objects in an array that I return to the calling script. The calling script then adds these graphic objects to a GraphicsLayer that had already been added to the map. I'll attach both files but I wanted to know first of all if this flow makes sense.

All the tutorials and samples I've found use FeatureSet.feature or something similar to create the Graphic object. I'm really out of ideas and I'm not sure how to do this. ANY help at all would be greatly appreciated. Thank you.

EDIT: Small mistake in cbibsGfxModule.js, I missed a comma. Should be:

define(["dojo/_base/declare", "dojo/_base/array", "dojo/request", "esri/graphic", "esri/geometry/Geometry"],
         function (declare, array, request, Graphic, Geometry) {
                  return declare(null, {
                           getAllCurrentReadings: function (_map) {
                                    var rtn = [];
                                    var stations = ["S", "SN", "AN", "UP", "GR", "PL", "SR", "J", "N", "FL"];
                                    array.forEach(stations, function(item, i) {
                                             request.post("includes/buoybay_proxy.php", {
                                                      data: {
                                                                "method": "RetrieveCurrentReadings", "params": "CBIBS," + item + ",113f8ba8f286ad0c21284601b7279b5f27e0a0bb" // NOTE: id: 1 is necessary as well but is added manually by jsonRPCClient
                                                      sync: true,
                                                      handleAs: "json"
                                                         function(response) {
                                                             var gfx, attr, t;
                                                               // Now build the Graphic Object and push it into rtn
                                                               gfx = new Graphic();
                                                               gfx.spatialReference = {
                                                                        wkid: 102100
                                                               // Define attribute object
                                                               attr = {};
                                                               attr["station"] = response.station;
                                                               attr["title"] = translateStationID(response.station);
                                                               for(var j = 0; j < response.measurement.length; j++) {
                                                                        attr[String(response.measurement[j])] = response.value[j];
                                                               gfx.attributes = attr;
                                                               // Define geometry object
                                                               gfx.geometry = new Geometry(gfx.spatialReference, "point");
                                                               gfx.geometry.spatialReference = {
                                                                        wkid: 102100
                                                               gfx.geometry.type = "point";
                                                               t = esri.geometry.geographicToWebMercator(new esri.geometry.Point(attr["longitude"], attr["latitude"], gfx.spatialReference));
                                                               gfx.geometry.x = t.x;
                                                               gfx.geometry.y = t.y;
                                                               // Define infoTemplate object
                                                               gfx.infoTemplate = new esri.InfoTemplate(attr);
                                                               // Define symbol
                                                               gfx.symbol = new esri.symbol.PictureMarkerSymbol("../CC/images/marker.png",15,15);
                                                         function(error) {
                                                                console.log("Error: " + error + "\n");
                                    return rtn;
// This translates the station ID to its full name
function translateStationID (stationID) {
  if(stationID === "S")
    return "Susquehanna";
  else if(stationID === "SN")
    return "Patapsco";
  else if(stationID === "AN")
    return "Annapolis";
  else if(stationID === "UP")
    return "Upper Potomac";
  else if(stationID === "GR")
    return "Gooses Reef";
  else if(stationID === "PL")
    return "Potomac";
  else if(stationID === "SR")
    return "Stingray Point";
  else if(stationID === "J")
    return "Jamestown";
  else if(stationID === "N")
    return "Norfolk";
  else if(stationID === "FL")
    return "First Landing";
    return "Statione Name Unknown: " + stationID;