ol.View#fit -- fix docs and add assertions
This commit is contained in:
committed by
Bart van den Eijnden
parent
e7cd691362
commit
4d3e903670
@@ -102,7 +102,7 @@ The replacement of `ol.tilegrid.Zoomify` is a plain `ol.tilegrid.TileGrid`, conf
|
|||||||
|
|
||||||
#### Replace `ol.View.fitExtent()` and `ol.View.fitGeometry()` with `ol.View.fit()`
|
#### Replace `ol.View.fitExtent()` and `ol.View.fitGeometry()` with `ol.View.fit()`
|
||||||
* This combines two previously distinct functions into one more flexible call which takes either a geometry or an extent.
|
* This combines two previously distinct functions into one more flexible call which takes either a geometry or an extent.
|
||||||
* Rename all calls to `fitExtent` and `fitGeometry` to `fit`
|
* Rename all calls to `fitExtent` and `fitGeometry` to `fit`.
|
||||||
|
|
||||||
#### `ol.tilegrid` changes
|
#### `ol.tilegrid` changes
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -436,6 +436,8 @@ ol.View.prototype.getZoom = function() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fit the given geometry or extent based on the given map size and border.
|
* Fit the given geometry or extent based on the given map size and border.
|
||||||
|
* The size is pixel deminsions of the box to fit the extent into.
|
||||||
|
* In most cases you will want to use the map size, that is `map.getSize()`.
|
||||||
* Take care on the map angle.
|
* Take care on the map angle.
|
||||||
* @param {ol.geom.SimpleGeometry|ol.Extent} geometry Geometry.
|
* @param {ol.geom.SimpleGeometry|ol.Extent} geometry Geometry.
|
||||||
* @param {ol.Size} size Box pixel size.
|
* @param {ol.Size} size Box pixel size.
|
||||||
@@ -443,8 +445,11 @@ ol.View.prototype.getZoom = function() {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.View.prototype.fit = function(geometry, size, opt_options) {
|
ol.View.prototype.fit = function(geometry, size, opt_options) {
|
||||||
|
|
||||||
if (!(geometry instanceof ol.geom.SimpleGeometry)) {
|
if (!(geometry instanceof ol.geom.SimpleGeometry)) {
|
||||||
|
goog.asserts.assert(goog.isArray(geometry),
|
||||||
|
'invalid extent or geometry');
|
||||||
|
goog.asserts.assert(!ol.extent.isEmpty(geometry),
|
||||||
|
'cannot fit empty extent');
|
||||||
geometry = ol.geom.Polygon.fromExtent(geometry);
|
geometry = ol.geom.Polygon.fromExtent(geometry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -480,6 +480,16 @@ describe('ol.View', function() {
|
|||||||
expect(view.getCenter()[0]).to.be(1500);
|
expect(view.getCenter()[0]).to.be(1500);
|
||||||
expect(view.getCenter()[1]).to.be(1500);
|
expect(view.getCenter()[1]).to.be(1500);
|
||||||
});
|
});
|
||||||
|
it('throws on invalid geometry/extent value', function() {
|
||||||
|
expect(function() {
|
||||||
|
view.fit(true, [200, 200]);
|
||||||
|
}).to.throwException();
|
||||||
|
});
|
||||||
|
it('throws on empty extent', function() {
|
||||||
|
expect(function() {
|
||||||
|
view.fit(ol.extent.createEmpty(), [200, 200]);
|
||||||
|
}).to.throwException();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('centerOn', function() {
|
describe('centerOn', function() {
|
||||||
@@ -512,5 +522,6 @@ describe('ol.View', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
goog.require('ol.View');
|
goog.require('ol.View');
|
||||||
|
goog.require('ol.extent');
|
||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
goog.require('ol.geom.Point');
|
goog.require('ol.geom.Point');
|
||||||
|
|||||||
Reference in New Issue
Block a user