Reputation: 26538
Given I already have a polygon instance, and I am panning the map to bounds, I want to move the polygon to the centre of the map as well.
Is there a built-in way to convert bounds to polygon paths?
Ideally I want to be able to do something like:
polygon.setPaths(bounds.getBounds());
Upvotes: 0
Views: 1891
Reputation: 26538
Just worked it out the plain old way:
var polygon_paths_from_bounds = function(bounds){
var paths =new google.maps.MVCArray();
var path = new google.maps.MVCArray();
var ne = bounds.getNorthEast();
var sw = bounds.getSouthWest();
path.push(ne);
path.push(new google.maps.LatLng(sw.lat(), ne.lng()));
path.push(sw);
path.push(new google.maps.LatLng(ne.lat(), sw.lng()));
paths.push(path);
return paths;
}
Upvotes: 3