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
//using jquery to iterate over the points and test whether each
point is in current bounds
$(polyPoints.b).each(function(i, point){
if(currentBounds.contains(point)) {
inBounds = true; //set flag to true
return false; //no need to continue loop if we found one
}
});
return inBounds;
}
Thank you for any insight.
--
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 [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-js-api-v3?hl=en.