2

I have a geoprocessing service that returns a large amount of features (featureSet). I want to attach them in a graphics layer, but I don't want to iterate over all them. I tried using the mygraphicLayer.graphics option so as to set the features (array of graphics) to the graphic layer but it does not work.

Have you got any idea how I could do this?

 function addCityFeatureSetToMap(featureSet) {
    console.debug("featureSet    ", featureSet)
    var symbol = new esri.symbol.SimpleMarkerSymbol();
    symbol.setColor(new dojo.Color([0,0,255]));

    //Create graphics layer for cities
    var cityLayer = new esri.layers.GraphicsLayer({
        graphics: featureSet.features
    });
    map.addLayer(cityLayer);
  • How many features? Is the reason you don't want to iterate because of the number of features? – Chad Cooper Dec 15 '14 at 19:17
  • 1
    Yes @ChadCooper It could be one reason. I don't like the idea of iteration, considering the the features of a feature Set is an array of Graphics[]. An Graphics layer constructor has an attribute Graphics[], which I suppose can be set immediately. – Smalis Dec 16 '14 at 9:57
2

edit: i did a bit of fiddling and realized that my original answer is incorrect. you need to loop through individual graphics and add() them one at a time because the graphics property of GraphicsLayer is not 'settable'.

that being said, its important to note that there would be no performance benefit of the API exposing a technique to loading graphics in bulk because we would still need to loop through individual geometries internally to insert them into the DOM.



original answer: i'm not sure you're going to see a performance gain in taking this approach, but it should work just fine as long as you set an appropriate renderer for the GraphicsLayer.

var myRenderer = new SimpleRenderer(symbol);
cityLayer.renderer = myRenderer;
cityLayer.graphics = featureSet.features;
cityLayer.redraw();

right now you're passing an array of graphic objects with no symbol defined whatsoever.

  • Thans for your answer @John Gravois. However i have already set a renderer later in my code. I will correct it in my question so as to be clear – Smalis Dec 16 '14 at 7:40
0

I would extend the GraphicsLayer this way

GraphicsLayer.prototype.addGraphics = function(arrayOfGraphics){
  var that = this;
  arrayUtil.forEach(arrayOfGraphics, function(graphic){
   that.add(graphic);
  });
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.