On Nov 15, 5:39 pm, CroNiX <cronix...@gmail.com> wrote:
> Is there a more efficient way to detect if any part of a polygon is in
> the current map bounds than to cycle through the polygons' points and
> manually test each point or is there a better way?  I did not see a
> native way to test a polygon like you can with a point using
> contains().  The docs say contains() requires a single latLng object
> as the parameter.  Its too bad it can't test whether the parameter is
> an array and do the same as below if it was, at least it doesn't seem
> so from the docs....
>
> I am currently doing this for my polygon detection, which works very
> well but looks like it can eat some horsepower if used on complex
> polygons, especially if tied to the bounds_changed event.
>
> function isPolyInBounds(map, polygon) {  //map obj, polygon obj
>     var currentBounds = map.getBounds();
>     var polyPoints = polygon.getPath();  //get path of current polygon
>     var inBounds = false;  //this will be set to true if at least 1
> point is in the current bounds
>

>
> Thank you for any insight.

I was intrigued by this:
http://code.google.com/apis/maps/documentation/javascript/reference.html#LatLngBounds
intersects(other:LatLngBounds)  boolean Returns true if this bounds
shares any points with this bounds.

I implemented it for the sidebar display here:
http://www.geocodezip.com/geoxml3_test/v3_geoxml3_us_counties01_highlight.html?lat=33.678198&lng=-114.15285124218751&zoom=8
[*** warning extremely complex KML, I don't recommend opening it in IE
***]

It seemed to do what I expected.

  -- Larry

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To post to this group, send email to google-maps-js-api...@googlegroups.com.
To unsubscribe from this group, send email to 
google-maps-js-api-v3+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to