Hey everyone, me again :)

I have my zoom levels restricted and my polygon drawn for the
boundary, and that all works great. Now what I'd like to do is
restrict the user from dragging past that boundary. I found an example
in Javascript that I tried to follow, and I seem to have it now. My
main issue is that it runs extremely slow, and debugging in Flex shows
that the event running the function loops until it crashes. The
example I followed was fast enough that I never noticed it going
beyond the bounds and snapping back.
So I'd like to "check my math" as it were and see what I can do to
improve it.

Here's the event listener:

this.map.addEventListener(MapMoveEvent.MOVE_END, stopDragging);

The function it calls:

private function stopDragging(e:Event):void {
        checkBoundsFunc();
}

And the actual code:

private function checkBoundsFunc():void {
        trace("******** CHECK BOUNDS ********");
        // Perform the check and return if OK
        var currentBounds:LatLngBounds = this.map.getLatLngBounds();
        var allowedBounds:LatLngBounds = new LatLngBounds(_southWest,
_northEast);
        var north:Number = currentBounds.getNorth();
        var south:Number = currentBounds.getSouth();
        var east:Number = currentBounds.getEast()
        var west:Number = currentBounds.getWest();
        var AmaxX:Number = allowedBounds.getNorthEast().lng();
        var AmaxY:Number = allowedBounds.getNorthEast().lat();
        var AminX:Number = allowedBounds.getSouthWest().lng();
        var AminY:Number = allowedBounds.getSouthWest().lat();

        // now check if the current rectangle in the allowed area
        var checkSW:LatLng = new LatLng(south, west);
        var checkNE:LatLng = new LatLng(north, east);

        if (allowedBounds.containsLatLng(checkSW) &&
allowedBounds.containsLatLng(checkNE)) {
                trace("nothing to do");
                return;
        }else{
                if (west < AminX) {
                        west = AminX;
                }
                if (east > AmaxX) {
                        east = AmaxX;
                }
                if (south < AminY) {
                        south = AminY;
                }
                if (north > AmaxY) {
                        north = AmaxY;
                }
                checkSW = new LatLng(south, west);
                checkNE = new LatLng(north, east);
                currentBounds = new LatLngBounds(checkSW, checkNE);

                this.map.setCenter(currentBounds.getCenter());
                return;
        }
}



_southWest and _northEast are the respective corners of
this.map.getLatLngBounds(). I've seen it mentioned somewhere that
setting the center in this function can cause an infinite loop, but
I'm not sure where else I could put it and call it when appropriate
without it happening in a loop.

Any help or insight is appreciated!

-- 
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