2

I am trying to add a graphic to my graphics layer during a map mouse event. In the javascript console, I can see that my graphic object is created and no error is thrown when I add the graphic to my graphics layer. However, when I try to add the graphics layer to the map, nothing happens. Same thing happens when I try to do a map.graphics.add(graphic) function. Has anyone else run into this? Or is there a workaround for this issue?

Here's my code:

app.map.on("mouse-drag",function(evt){

    if(evt.ctrlKey){  //control key must be pressed

        var polygonSymbol = new SimpleFillSymbol(); //create the symbol for the graphic
        var polygon = new Polygon(makeArc(evt));  //create the polygon the the returned geometry from makeArc()
        var graphic = new Graphic(polygon,polygonSymbol); //create the graphic objet
        console.log(graphic); 
        gLayer.add(graphic); //add the graphic to the graphic layer
        app.map.addLayer(gLayer); //add the graphic layer to the map
    }

});

Also, I know that it is not being added because I can't see the html inside the map div after the event occurs, which I usually can when I add a graphic or layer.

1 Answer 1

1

Give the polygonSymbol a definition in the constructor

var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,
  new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT,
  new esri.Color([255,0,0]), 2), new esri.Color([255,255,0,0.25]));

More information here on creating a fill symbol

https://developers.arcgis.com/javascript/jsapi/simplefillsymbol-amd.html#simplefillsymbol2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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