I am trying to place a rectangle on a map that can be moved, resized
and rotated.  To do the rotation, I wanted to use flex's built-in
Matrix class.  When i do the transform on the points, the shape ends
up moving around the map instead of staying in the same place when I
drag the map.  Here is some simplified code.

Am I misunderstanding how to do matrix transformations or is the
problem with lat/lng ration being different than x/y ratio?

public class RectangleGeoZone extends OverlayBase
{
        private var map:Map;
        private var location:LatLng;
        private var latConv:Number;
        private var lngConv:Number;
        private var latlngs:Array = new Array(4);

        private var matrix:Matrix = new Matrix();

        private var rectangle:Shape;

        public function RectangleGeoZone(map:Map, location:LatLng,
width:Number, height:Number)
        {
                super();
                this.map = map;
                this.location = location;
                this.width = width;
                this.height = height;

                latConv = location.distanceFrom(new LatLng(location.lat() + 0.1,
location.lng())) * 10;
                lngConv = location.distanceFrom(new LatLng(location.lat(),
location.lng() + 0.1)) * 10;

                latlngs[0] = location;
                latlngs[1] = new LatLng(location.lat(), location.lng() + (width 
/
lngConv));
                latlngs[2] = new LatLng(location.lat() - (height / latConv),
location.lng() + (width / lngConv));
                latlngs[3] = new LatLng(location.lat() - (height / latConv),
location.lng());


                matrix.rotate(45 * (Math.PI / 180));
                //matrix.scale(2, 2);

                rectangle = new Shape();
        }

        public override function getDefaultPane(map:IMap):IPane
    {
        return map.getPaneManager().getPaneById(PaneId.PANE_OVERLAYS);
    }

        public function getLatLngs():Array {
                return latlngs;
        }

        public function getPoints():Array {
                var points:Array = new Array(latlngs.length);
                for (var i:int=0; i<latlngs.length; i++) {
                        points[i] = 
matrix.transformPoint(latlngToPoint(LatLng(latlngs
[i])));
                }
                return points;
        }

        public override function positionOverlay(zoomChanged:Boolean):void
        {
                rectangle.graphics.clear();
                rectangle.graphics.beginFill(Color.BLUE, .5);

                var points:Array = getPoints();
                var point:Point = Point(points[0]);
                rectangle.graphics.moveTo(point.x, point.y);
                for (var i:int=0; i<points.length; i++) {
                        point = Point(points[(i + 1) % points.length])
                        rectangle.graphics.lineTo(point.x, point.y);
                }
                rectangle.graphics.endFill();

                addChild(rectangle);
        }

        private function latlngToPoint(latlng:LatLng):Point {
                return pane.fromLatLngToPaneCoords(latlng);
        }

        private function pointToLatLng(point:Point):LatLng {
                return pane.fromPaneCoordsToLatLng(point);
        }
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API For Flash" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-maps-api-for-flash?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to