Select to view content in your preferred language

Graphics Layer from MySQL Data

465
0
07-25-2013 08:28 AM
OttoBorden
New Contributor
Hello,

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"
                                                    }).then(
                                                         function(response) {
                                                             var gfx, attr, t;
                                                               //console.log(response);
                                                               // 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)] = response.value;
                                                               }
                                                               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);
                                                               
                                                               //console.log(gfx);
                                                               rtn.push(gfx);
                                                               },
                                                         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";
  else
    return "Statione Name Unknown: " + stationID;
}
0 Kudos
0 Replies