moveToFront()/moveToBack()

4599
4
Jump to solution
01-30-2015 07:38 AM
koliterergonthe
New Contributor

Hi, I am currently in need of functions who can do the same thing as "graphic".getDojoShape().moveToFront() and "graphic".getDojoShape().moveToBack() functions. But I need to keep track of the Z-index of the graphics that are being reordered. Any ideas of how I could achieve that? Only in Javascript or jquery, no java. Is there a way I can access to the code of those two functions? Or know what do they change/reorder and where is it in the object map.graphics.

 

I need to keep track because I need to revert it back sometimes. So I need to revert it to the correct position.

 

If i know where I can make myself a function. I just can figure out what is changing. Because it doesn't reorder the graphics object.

 

 

Thank you for your time!
Koliter

0 Kudos
1 Solution

Accepted Solutions
TomSellsted
MVP Regular Contributor

Greetings Koliter,

You could build a function similar to the one below.  In this case I am reordering the drawing order of the graphics that have a textsymbol, so they will always draw on top of the other graphics.  You could set/manage an drawing hierarchy that would suite you.

function reorderGraphics() {

  // text for measurements needs to be on type all others

  var graArray = [];

  // make 2 pass through the graphics in the measure array move text to the top.

  // second pass adds text graphics

  for (var i = 0; i < drawLayer.graphics.length; i++) {

       var gra = drawLayer.graphics;

       if (gra.symbol.type == 'textsymbol') {

            graArray.push(gra);

       }

  }

  // first pass adds non text graphics

  for (var i = 0; i < drawLayer.graphics.length; i++) {

       var gra = drawLayer.graphics;

       if (gra.symbol.type != 'textsymbol') {

            graArray.push(gra);

       }

  }

  drawLayer.graphics = graArray;

  drawLayer.redraw();

}

I hope this will work for you.

Regards,

Tom

View solution in original post

4 Replies
koliterergonthe
New Contributor

I really need an answer for this question. It is totally essential to my project. Otherwise I can't save the modifications which has been done. I've been patient enough I think..  Like i said, I ABSOLUTELY need to know what it changes and where.

Thank you for your time!
Koliter

0 Kudos
TomSellsted
MVP Regular Contributor

Greetings Koliter,

You could build a function similar to the one below.  In this case I am reordering the drawing order of the graphics that have a textsymbol, so they will always draw on top of the other graphics.  You could set/manage an drawing hierarchy that would suite you.

function reorderGraphics() {

  // text for measurements needs to be on type all others

  var graArray = [];

  // make 2 pass through the graphics in the measure array move text to the top.

  // second pass adds text graphics

  for (var i = 0; i < drawLayer.graphics.length; i++) {

       var gra = drawLayer.graphics;

       if (gra.symbol.type == 'textsymbol') {

            graArray.push(gra);

       }

  }

  // first pass adds non text graphics

  for (var i = 0; i < drawLayer.graphics.length; i++) {

       var gra = drawLayer.graphics;

       if (gra.symbol.type != 'textsymbol') {

            graArray.push(gra);

       }

  }

  drawLayer.graphics = graArray;

  drawLayer.redraw();

}

I hope this will work for you.

Regards,

Tom

View solution in original post

FC_Basson
MVP Regular Contributor

I've had issues with the moveToFront / moveToBack methods - when all the graphics in the graphics layer are visible in the view extent it works fine, but when one or more of the graphics in the graphics layer are out of the view extent, calling these methods on a specific graphic returned a TypeError (definitely buggy).  With your array-build-redraw method it is solved. 

KenBuja
MVP Honored Contributor

Hi Koliter,

For future reference, you'll probably get a faster response when posting your questions in the appropriate space. By asking your Javascript question in the Javascript space‌, it will gain the attention of the Javascript experts much more quickly. And while you added many tags, you didn't include a specific Javascript tag.

0 Kudos