Add extent handling to ol.Map
This commit is contained in:
@@ -9,6 +9,7 @@ goog.require('goog.object');
|
||||
goog.require('ol.Array');
|
||||
goog.require('ol.Camera');
|
||||
goog.require('ol.CameraProperty');
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.LayerRenderer');
|
||||
goog.require('ol.Object');
|
||||
goog.require('ol.Projection');
|
||||
@@ -47,6 +48,12 @@ ol.Map = function(target, opt_values) {
|
||||
*/
|
||||
this.size_ = new goog.math.Size(target.clientWidth, target.clientHeight);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Extent}
|
||||
*/
|
||||
this.extent_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<number>}
|
||||
@@ -118,6 +125,14 @@ ol.Map.prototype.getCamera = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.Extent} Extent.
|
||||
*/
|
||||
ol.Map.prototype.getExtent = function() {
|
||||
return this.extent_.clone();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.Array} Layers.
|
||||
*/
|
||||
@@ -134,6 +149,19 @@ ol.Map.prototype.getProjection = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Extent} extent Extent.
|
||||
* @return {number} Resolution.
|
||||
*/
|
||||
ol.Map.prototype.getResolutionForExtent = function(extent) {
|
||||
var size = this.size_;
|
||||
var xResolution = (extent.right - extent.left) / size.width;
|
||||
var yResolution = (extent.top - extent.bottom) / size.height;
|
||||
// FIXME support discrete resolutions
|
||||
return Math.max(xResolution, yResolution);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @return {goog.math.Size} Size.
|
||||
@@ -276,6 +304,18 @@ ol.Map.prototype.setCamera = function(camera) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Extent} extent Extent.
|
||||
*/
|
||||
ol.Map.prototype.setExtent = function(extent) {
|
||||
var camera = this.getCamera();
|
||||
var position = extent.getCenter();
|
||||
camera.setPosition(position);
|
||||
var resolution = this.getResolutionForExtent(extent);
|
||||
camera.setResolution(resolution);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Array} layers Layers.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user