Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 10 down vote accepted

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:

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

share|improve this answer

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

graphicsLayer.acme = {
    addFirst: function (graphic)
        graphic._graphicsLayer = graphicsLayer;
    redraw: function ()
        var graphics = dojo.filter(, 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.

share|improve this answer
This not recommended. Please stick to the public, documented methods. My answer explains how to add a graphic underneath/behind existing graphics. – Derek Swingley Jun 15 '12 at 16:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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