AnsweredAssumed Answered

Having issue On Loading All JSON Data into Markers Layer With in For Loop

Question asked by BEHSEINI on Sep 4, 2015
Latest reply on Sep 4, 2015 by rscheitlin

I have a code like below which is suppose to add over 600 points into a GraphicLayer `projectsG` and eventually add the `projectsG` to `layer1` and `map` but I am not sure what I am doing wrong in

 

 

    projectsG = new esri.Graphic(project, symbol).setInfoTemplate(projectInfoTemplate);
    }
    console.log(thepoints);
    layer1 = new esri.layers.GraphicsLayer();
    for (i = 0; i < points.length; ++i) {
        layer1.add(projectsG);
    }

 

part which only adds the Last project into the map! Can you please take a look at following code and let me know what I  am doing wrong in looping?

 

      var layer1, 
      var thepoints=[];
      var projectInfoTemplate;
      var projectsG;
    
    var points = [
       {
          "ProjectID":"15260",
          "Longitude":"-118.641508",
          "Latitude":"51.949915",
       },
       {
          "ProjectID":"17043",
          "Longitude":"-125.444557",
          "Latitude":"51.097552",
       },
       ....
          {
          "ProjectID":"13009",
          "Longitude":"-130.257086",
          "Latitude":"56.882834",
       },
       {
          "ProjectID":"17088",
          "Longitude":"-124.160699",
          "Latitude":"50.897618",
       }
    ];


    function drawSeries1() {
    for (var i = 0; i < points.length; i++) {
        var projects = points[i];
        var project = new esri.geometry.Point(projects.Longitude, projects.Latitude);                  
        project = esri.geometry.geographicToWebMercator(project);
    
        var symbol = new esri.symbol.PictureMarkerSymbol("e-Chartreuse.png", 32, 32);
        projectInfoTemplate = new InfoTemplate(); 
        projectInfoTemplate.setTitle("Project Details");
        projectInfoTemplate.setContent('<div>Some Att Here</div> ');
        
        projectsG = new esri.Graphic(project, symbol).setInfoTemplate(projectInfoTemplate);
        thepoints.push(projectsG);
    }
    console.log(thepoints);
    layer1 = new esri.layers.GraphicsLayer();
    for (i = 0; i < points.length; ++i) {
        layer1.add(projectsG);
    }
    map.addLayer(layer1);           
    
    
    }

Outcomes