EditTool - Editing PNG

903
4
03-06-2012 11:51 AM
ShaunWeston
Frequent Contributor
I've built a Flex widget to enable a user to select an icon (in PNG format) and then place it on the map using the DrawTool. What I want the user to then be able to do is change the size and placement of the icon.

I thought I could do this, but getting a little stumped as the examples I've found are all for graphics. So I'm trying to work of this example here:


           
            private function map_mouseUpHandler(event:MouseEvent):void
            {
                event.currentTarget.removeEventListener(MouseEvent.MOUSE_MOVE, map_mouseMoveHandler);
                event.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, map_mouseUpHandler);


                if (event.target is Graphic)
                {
                    graphic = Graphic(event.target);
                    if (lastEditGraphic !== graphic)
                    {
                        lastEditGraphic = graphic;
                        lastActiveEditTypes = "moveRotateScale"; // make sure move and edit vertices is the 1st mode
                    }
                    if (graphic.geometry is Polyline || graphic.geometry is Polygon)
                    {
                        if (lastActiveEditTypes == "moveEditVertices")
                        {
                            lastActiveEditTypes = "moveRotateScale";
                            myEditTool.activate(EditTool.MOVE | EditTool.SCALE | EditTool.ROTATE, [ graphic ]);
                        }
                        else
                        {
                            lastActiveEditTypes = "moveEditVertices";
                            myEditTool.activate(EditTool.MOVE | EditTool.EDIT_VERTICES, [ graphic ]);
                        }
                    }
                    else if (graphic.geometry is Extent)
                    {
                        myEditTool.activate(EditTool.MOVE | EditTool.SCALE, [ graphic ]);
                    }
                    else if (graphic.graphicsLayer == myGraphicsLayer)
                    {
                        myEditTool.activate(EditTool.MOVE | EditTool.EDIT_VERTICES, [ graphic ]);
                    }
                }
                else
                {
                    myEditTool.deactivate();
                    lastActiveEditTypes = "moveRotateScale"; // make sure move and edit vertices is the 1st mode
                }
            }


However when it gets to the first if statement (the user clicks on the PNG icon on the map as they want to move it), it returns false as it is not a Graphic it returns "[object Sprite]", which I don't really understand. And this bit here:


graphic = Graphic(event.target);

won't work either as it's not returned, so not sure how to go about doing this?
Tags (2)
0 Kudos
4 Replies
SarthakDatt
Frequent Contributor
Hey Shaun,

For PictureMarkerSymbol, which would would be using for adding your PNG on the map, you would have to do update the sample to something like:

  private function map_mouseUpHandler(event:MouseEvent):void
  {
      event.currentTarget.removeEventListener(MouseEvent.MOUSE_MOVE, map_mouseMoveHandler);
      event.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, map_mouseUpHandler);


      if (event.target is Graphic || event.target.parent is Graphic)
      {
           graphic = event.target is Graphic ? Graphic(event.target) : Graphic(event.target.parent) // takes care of PMS;
           // Your code follows
      }
  }
0 Kudos
ShaunWeston
Frequent Contributor
Thanks heaps, that's got it!

So, I can now move the image around. But now I need to change the size of it and remove it. It is a point, so I guess I need to get into the actual PictureMarkerSymbol height and width to be able to change the size of it.
0 Kudos
SarthakDatt
Frequent Contributor
Yes, that correct. You can't really scale a marker symbol using the EditTool.
0 Kudos
GeorgiaJackson
Emerging Contributor
So much...
0 Kudos