ngalford

ajax service to add points to graphic layer

Discussion created by ngalford on Aug 16, 2013
Latest reply on Sep 27, 2013 by ballews
I'm creating graphics layer with ajax return.  I can see the graphics layer in the map, but the points don't appear on the layer, I'm adding the points but somehow something seems missing. Jen is an object that's holding most of the map elements. EDIT: I'm now getting a new error here's the reformated code: 

**Error: Problem parsing d="Z"**

    
    $.ajax({
      url: opt.url,
      type: 'GET',
      dataType: 'json',
      error: function(error) {
        console.error('error: ' + error);
        jen.ajaxData.points = {
          "points": [
            [-122.63, 45.51],
            [-122.56, 45.51],
            [-122.56, 45.55],
            [-122.62, 45.00],
            [-122.59, 45.53]
          ],
          "spatialReference": ({
            "wkid": 4326
          })
        };
      },
      success: function(data) {
        console.info('ajax is successfull');
        jen.graphicObj = {};
        jen.graphicObj.Layer = new esri.layers.GraphicsLayer();

        for (var i = 0; i < (data.length); i++) {
          jen.ajaxData.long.push(data[i].latitude);
          jen.ajaxData.lat.push(data[i].longitude);
          jen.ajaxData.num.push(data[i].number);
          jen.ajaxData.idleTime.push(data[i].idelTimeMinutes);

          jen.ajaxData.points = {
            "points": [jen.ajaxData.long, jen.ajaxData.lat],
            "spatialReference": ({
              "wkid": 4326
            })
          };

          jen.graphicObj.geometry = new esri.geometry.Multipoint(jen.ajaxData.points);
          jen.graphicObj.infoTemplate = new esri.InfoTemplate(//);
          jen.graphicObj.graphic = new esri.Graphic(jen.graphicObj.webMercator, jen.circle, '', jen.graphicObj.infoTemplate);
          jen.graphicObj.webMercator = esri.geometry.geographicToWebMercator(jen.graphicObj.geometry);
          jen.graphicObj.Layer.add(jen.graphicObj.graphic);
        }
      } //end of success function

    }).done(function(){
      //layers get added in a loop after this point
  }

Outcomes