moveToFront/moveToBack Polygon

218
3
04-22-2019 06:22 AM
WesleyAntal1
New Contributor

Hello,

I have a problem when I try execute the method getShape().moveToFront() (or getShape().moveToBack()) JUST on polygons (other geometries work) by API. For example, I did a test in the Sandbox (ArcGIS API for JavaScript Sandbox) where I update a part of the code just to replic the problem (code below). I added a polygon, after that I drew a polyline (on the polygon), so I click in "arrow" to call the function test(), and nothing happened, but when I click in "line" to call "teste2()", it work. Could Somebody help me?

thank you.

function activateTool() {
          var tool = this.label.toUpperCase().replace(/ /g, "_");
          if(tool==="ARROW"){
            test();

            return;
          }
          
          if(tool==="LINE"){
            test2();

            return;
          }
          toolbar.activate(Draw[tool]);
          map.hideZoomSlider();
        }
        
        function test(){
          map.graphics.graphics[1].getShape().moveToFront();
        }
        
        function test2(){
          map.graphics.graphics[2].getShape().moveToBack();
        }

        function createToolbar(themap) {
          toolbar = new Draw(map);
          toolbar.on("draw-end", addToMap);
        }

        function addToMap(evt) {
          var symbol;
          toolbar.deactivate();
          map.showZoomSlider();
          switch (evt.geometry.type) {
            case "point":
            case "multipoint":
              symbol = new SimpleMarkerSymbol();
              break;
            case "polyline":
              symbol = new SimpleLineSymbol();
              break;
            default:
              symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new esri.Color([223,223,223,1]), 6), new esri.Color([223,223,223,1]));
              break;
          }

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Wesley,

  You have some issues in your code. In your activateTool method you return if the tool is an ARROW or LINE and never allow the code continue to activate the draw tool. So I commented those returns out.

        function activateTool() {
          var tool = this.label.toUpperCase().replace(/ /g, "_");
          if(tool==="ARROW"){
            test();
            //return;
          }
          
          if(tool==="LINE"){
            test2();
            //return;
          }
          toolbar.activate(Draw[tool]);
          map.hideZoomSlider();
        }

Once I draw a Polygon, then an arrow inside the polygon, then click the line tool the arrow is moved to the back behind the polygon as the code is written.

0 Kudos
WesleyAntal1
New Contributor

Hi Robert,

I think that I expressed myself poorly, I don't want draw any arrow or line, I just did this example to demonstrate my real problem. My problem is call method .getShape().moveToFront()/.getShape().moveToBack() of Graphic (JUST Polygon), because this do not work.

Thanks for your reply.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

As I mentioned I had not problem moving a Polygon to the back or front when the code was getting the correct graphic.

0 Kudos