I have a graphics layer and I'd like to add a graphic behind the existing graphics. I've come up with this:


But I have to pan the markers off the screen and then pan them back into view before the 'unshift'-ed graphics display correctly. I've tried calling refresh without any affect:


How can this be done without introducing a second graphics layer?

2 Answers 2


Graphics in a GraphicsLayer (as well as in a FeatureLayer) are dojx.gfx objects. Each Graphic has a getDojoShape method. This is the key to changing the drawing order of your graphics.

I put up a working example on jsfiddle: http://jsfiddle.net/fKwRn/

Click the map to add a point. The newest point is always added underneath the existing points.


My goodness I hope this is not the correct "answer":

graphicsLayer.acme = {
    addFirst: function (graphic)
        graphic._graphicsLayer = graphicsLayer;
    redraw: function ()
        var graphics = dojo.filter(graphicsLayer.graphics, function (item)
            return item.visible;
        dojo.forEach(graphics, function (item)
            graphicsLayer.remove ( item );
        dojo.forEach(graphics, function (item)

I introduced an addFirst method to add the graphic to the front of the graphics array and a redraw method to remove all visible graphics from the layer and add them back to the layer. That can't be good.

  • 2
    This not recommended. Please stick to the public, documented methods. My answer explains how to add a graphic underneath/behind existing graphics. Jun 15, 2012 at 16:25

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.