OK, I have learned not to use the ALT-TAB inside gmail to switch windows...
Here is the clear rectangle function
*private* *function* doClearRectangle():*void*{
*if* (curpolygon != *null*){
map.removeOverlay(curpolygon);
curpolygon = *null*;
}
}
On Thu, Sep 16, 2010 at 9:50 AM, Bruce Ralston <[email protected]> wrote:
> I hit the send button by mistake before finishing the previous email. Here
> is the entire message.
>
> Sorry to hear that. It was a good site.
> Here is how I implement the selection rectangle in Flex with Google Maps.
>
> Step 1. Declare some global variables
>
> *//selection box stuff*
>
> *private* *var* selectionRectangle:Canvas;
>
> *private* *var* startlatlng:LatLng;
>
> *private* *var* endlatlng:LatLng;
>
> *private* *var* curpolygon:Polygon;
>
> *private* *var* bolBox:Boolean = *false*;
>
> *private* *var* bolAfterMouseDown:Boolean = *false*;
>
> Step 2. Import the following classes
>
> *import* com.google.maps.overlays.Polyline;
>
> *import* com.google.maps.overlays.PolylineOptions;
>
> *import* com.google.maps.overlays.Polygon;
>
> *import* com.google.maps.overlays.PolygonOptions;
>
> *import* com.google.maps.LatLngBounds;
>
>
> Step 3. Create two buttons, one for setting the rectangle, the other for
> clearing. The click event functions will be doSetRectangle and
> doClearRectangle.
>
>
> Here is the code for doSetRectangle (it depends on the other mouse event
> handler functions listed below)
>
>
> *private* *function* doSetRectangle():*void*{
>
> bolBox = !bolBox;
>
> *if* (bolBox) {
>
> *if* (curpolygon != *null*){
>
> map.removeOverlay(curpolygon);
>
> curpolygon = *null*;
>
> }
>
> map.disableDragging();
>
> map.addEventListener(MapMouseEvent.MOUSE_DOWN, onMouseDown);
>
> map.addEventListener(MapMouseEvent.MOUSE_MOVE, onMouseMove);
>
> map.addEventListener(MapMouseEvent.MOUSE_UP, onMouseUp);
>
> }
>
> *else*
>
> {
>
> map.removeEventListener(MapMouseEvent.MOUSE_DOWN,
> onMouseDown);
>
> map.removeEventListener(MapMouseEvent.MOUSE_MOVE,
> onMouseMove);
>
> map.removeEventListener(MapMouseEvent.MOUSE_UP, onMouseUp);
>
> map.enableDragging();
>
> }
>
> }
>
> *private* *function* onMouseDown(event:MapMouseEvent):*void*{
>
> *//instead of adding a canvas rectanle, add a polygon overlay*
>
> startlatlng = event.latLng;
>
> *var* polygon:Polygon = *new* Polygon([
>
> *new* LatLng(startlatlng.lat(),startlatlng.lng()),
>
> *new* LatLng(startlatlng.lat(),startlatlng.lng()),
>
> *new* LatLng(startlatlng.lat(), startlatlng.lng()),
>
> *new* LatLng(startlatlng.lat(), startlatlng.lng()),
>
> *new* LatLng(startlatlng.lat(),startlatlng.lng())
>
> ], *new* PolygonOptions({
>
> strokeStyle: *new* StrokeStyle({
>
> backgroundAlpha: 0.0,
>
> color: 0xFF0000,
>
> thickness: 2,
>
> alpha: 1.0}),
>
> fillStyle: *new* FillStyle({
>
> color: 0x067EE3,
>
> alpha: 0.5})
>
> }));
>
> curpolygon = polygon;
>
> map.addOverlay(polygon);
>
> bolAfterMouseDown = *true*;
>
> }
>
> *private* *function* onMouseMove(event:MapMouseEvent):*void*{
>
> *//as mouse moves update the extent of the polygon overlay*
>
> *if* (bolAfterMouseDown)
>
> {
>
> *var* polygon:Polygon = *new* Polygon([
>
> *new* LatLng(startlatlng.lat(),startlatlng.lng()),
>
> *new* LatLng(event.latLng.lat(),startlatlng.lng()),
>
> *new* LatLng(event.latLng.lat(), event.latLng.lng()),
>
> *new* LatLng(startlatlng.lat(), event.latLng.lng()),
>
> *new* LatLng(startlatlng.lat(),startlatlng.lng())
>
> ], *new* PolygonOptions({
>
> strokeStyle: *new* StrokeStyle({
>
> backgroundAlpha: 0.0,
>
> color: 0xFF0000,
>
> thickness: 2,
>
> alpha: 1.0}),
>
> fillStyle: *new* FillStyle({
>
> color: 0x067EE3,
>
> alpha: 0.5})
>
> }));
>
> map.removeOverlay(curpolygon);
>
> map.addOverlay(polygon);
>
> curpolygon = polygon;
>
> }
>
> }
>
> *private* *function* onMouseUp(event:MapMouseEvent):*void*{
>
> *//when finished, get extent of overlay*
>
> *var* polygon:Polygon = *new* Polygon([
>
> *new* LatLng(startlatlng.lat(),startlatlng.lng()),
>
> *new* LatLng(event.latLng.lat(),startlatlng.lng()),
>
> *new* LatLng(event.latLng.lat(), event.latLng.lng()),
>
> *new* LatLng(startlatlng.lat(), event.latLng.lng()),
>
> *new* LatLng(startlatlng.lat(),startlatlng.lng())
>
> ], *new* PolygonOptions({
>
> strokeStyle: *new* StrokeStyle({
>
> backgroundAlpha: 0.0,
>
> color: 0xFF0000,
>
> thickness: 2,
>
> alpha: 1.0}),
>
> fillStyle: *new* FillStyle({
>
> color: 0x067EE3,
>
> alpha: 0.5})
>
> }));
>
> map.removeOverlay(curpolygon);
>
> map.addOverlay(polygon);
>
> curpolygon = polygon;
>
> bolBox = *false*;
>
> bolAfterMouseDown = *false*;
>
> map.removeEventListener(MapMouseEvent.MOUSE_DOWN, onMouseDown);
>
> map.removeEventListener(MapMouseEvent.MOUSE_MOVE, onMouseMove);
>
> map.removeEventListener(MapMouseEvent.MOUSE_UP, onMouseUp);
>
> map.enableDragging();
>
> }
>
> Step 4. Finally, the clear rectangle function.
>
>
>
>
> --
> Bruce Ralston
> Professor
> Department of Geography
> University of Tennessee
> Knoxville, TN 37996-0925
> Phone: 865-974-6043
> FAX: 865-974-6025
>
>
--
Bruce Ralston
Professor
Department of Geography
University of Tennessee
Knoxville, TN 37996-0925
Phone: 865-974-6043
FAX: 865-974-6025
--
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.