Google maps fitBounds with padding?
This question already has an answer here:
After a while I found a solution that works.
if (this.map.getProjection()) {
var offsetx = 200;
var offsety = 0;
var point1 = this.map.getProjection().fromLatLngToPoint(bounds.getSouthWest());
this.map.fitBounds(bounds);
var point2 = new google.maps.Point(
( (typeof(offsetx) == 'number' ? offsetx : 0) / Math.pow(2, this.map.getZoom()) ) || 0,
( (typeof(offsety) == 'number' ? offsety : 0) / Math.pow(2, this.map.getZoom()) ) || 0
);
var newPoint = this.map.getProjection().fromPointToLatLng(new google.maps.Point(
point1.x - point2.x,
point1.y + point2.y
));
bounds.extend(newPoint);
this.map.fitBounds(bounds);
}
jsfiddle
链接地址: http://www.djcxy.com/p/81542.html上一篇: 适合(fitBounds)与复杂的KML
下一篇: 谷歌地图fitBounds填充?