Replace fitGeometry and fitExtent with fit
Fit accepts either a geometry or an extent. This combines two previously distinct functions into one more flexible call. Also brings the rotations support and options previously available to fitGeometry to extents
This commit is contained in:
committed by
Bart van den Eijnden
parent
3021d3a6a7
commit
74759142d9
@@ -14,6 +14,8 @@ goog.require('ol.RotationConstraintType');
|
||||
goog.require('ol.Size');
|
||||
goog.require('ol.coordinate');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.geom.SimpleGeometry');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.proj.METERS_PER_UNIT');
|
||||
goog.require('ol.proj.Projection');
|
||||
@@ -431,35 +433,19 @@ ol.View.prototype.getZoom = function() {
|
||||
|
||||
|
||||
/**
|
||||
* Fit the map view to the passed extent and size. The size is pixel dimensions
|
||||
* of the box to fit the extent into. In most cases you will want to use the map
|
||||
* size, that is `map.getSize()`.
|
||||
* @param {ol.Extent} extent Extent.
|
||||
* Fit the given geometry or extent based on the given map size and border.
|
||||
* Take care on the map angle.
|
||||
* @param {ol.geom.SimpleGeometry|ol.Extent} geometry Geometry.
|
||||
* @param {ol.Size} size Box pixel size.
|
||||
* @param {olx.view.FitOptions=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
ol.View.prototype.fitExtent = function(extent, size) {
|
||||
if (!ol.extent.isEmpty(extent)) {
|
||||
this.setCenter(ol.extent.getCenter(extent));
|
||||
var resolution = this.getResolutionForExtent(extent, size);
|
||||
var constrainedResolution = this.constrainResolution(resolution, 0, 0);
|
||||
if (constrainedResolution < resolution) {
|
||||
constrainedResolution =
|
||||
this.constrainResolution(constrainedResolution, -1, 0);
|
||||
}
|
||||
this.setResolution(constrainedResolution);
|
||||
ol.View.prototype.fit = function(geometry, size, opt_options) {
|
||||
|
||||
if (!(geometry instanceof ol.geom.SimpleGeometry)) {
|
||||
geometry = ol.geom.Polygon.fromExtent(geometry);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Fit the given geometry into the view based on the given map size and border.
|
||||
* @param {ol.geom.SimpleGeometry} geometry Geometry.
|
||||
* @param {ol.Size} size Box pixel size.
|
||||
* @param {olx.view.FitGeometryOptions=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
ol.View.prototype.fitGeometry = function(geometry, size, opt_options) {
|
||||
var options = goog.isDef(opt_options) ? opt_options : {};
|
||||
|
||||
var padding = goog.isDef(options.padding) ? options.padding : [0, 0, 0, 0];
|
||||
|
||||
Reference in New Issue
Block a user