If your search area is rectangular and you are searching points, this is
pretty easy.  If the search area is irregular and/or you are looking for
polygon intersections, that would be more of a challenge.

To set a search rectangle, you can use the following code. This code is
based on the following website:
http://blog.jeethukarthik.com/flex-selection-rectangle/

At the start of your script section, declare the following

*//selection box stuff*

*private* *var* selectionRectangle:Canvas;

*private* *var* startlatlng:LatLng;

*private* *var* endlatlng:LatLng;

*private* *var* curpolygon:Polygon; *//a polygon that stores the current
search area*

*private* *var* bolBox:Boolean = *false*;

*private* *var* bolAfterMouseDown:Boolean = *false*;

In the ActionScript section, add these functions to get the search
rectangle.

   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();
     }
     if (ckbExtent.selected == false)
     ckbExtent.selected = true;
  }
  private function onMouseDown(event:MapMouseEvent):void{
     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();
}

Hope this helps.

Bruce Ralston


On Mon, Jun 21, 2010 at 8:57 AM, J_Mo <[email protected]> wrote:

> Hi,
>
> I have created a Google Map API in Flash CS3 with some overlays & a
> search facility. My problem is that I would like to put some
> parameters on the search so it only searches a specific area....is
> this possible??
>
> I am not the best in AS3 so the simpler the explanation the better!
>
> Thanks
> Phil
>
> --
> 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]<google-maps-api-for-flash%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-maps-api-for-flash?hl=en.
>
>


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

Reply via email to