New pixel conversion and zoom/center related methods.
This commit is contained in:
@@ -9,6 +9,8 @@ goog.require('ol.control.Control');
|
||||
goog.require('ol.renderer.MapRenderer');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.math');
|
||||
|
||||
|
||||
/**
|
||||
* @export
|
||||
@@ -259,6 +261,23 @@ ol.Map.prototype.getResolutionForZoom = function(zoom) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {goog.math.Coordinate|{x: number, y: number}} pixel
|
||||
* @return {ol.Loc}
|
||||
*/
|
||||
ol.Map.prototype.getLocForPixel = function(pixel) {
|
||||
return this.renderer_.getLocForPixel(pixel);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {goog.math.Size} The currently rendered map size in pixels.
|
||||
*/
|
||||
ol.Map.prototype.getSize = function() {
|
||||
return this.renderer_.getSize();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Loc} center Center in map projection.
|
||||
*/
|
||||
@@ -268,6 +287,17 @@ ol.Map.prototype.setCenter = function(center) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} zoom
|
||||
* @param {ol.Loc} center
|
||||
*/
|
||||
ol.Map.prototype.zoomTo = function(zoom, center) {
|
||||
this.zoom_ = this.limitZoom(zoom);
|
||||
this.center_ = center;
|
||||
this.conditionallyRender();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Projection} projection Projection.
|
||||
*/
|
||||
@@ -288,13 +318,23 @@ ol.Map.prototype.setUserProjection = function(userProjection) {
|
||||
* @param {number} zoom Zoom.
|
||||
*/
|
||||
ol.Map.prototype.setZoom = function(zoom) {
|
||||
if (zoom !== this.zoom_ && zoom >= 0 && zoom < this.getNumZoomLevels()) {
|
||||
zoom = this.limitZoom(zoom);
|
||||
if (zoom !== this.zoom_) {
|
||||
this.zoom_ = zoom;
|
||||
this.conditionallyRender();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} zoom
|
||||
* @return {number} zoom clamped to the range of available zoom levels.
|
||||
*/
|
||||
ol.Map.prototype.limitZoom = function(zoom) {
|
||||
return goog.math.clamp(zoom, 0, this.getNumZoomLevels()-1);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} nZoom Zoom.
|
||||
*/
|
||||
|
||||
@@ -49,6 +49,8 @@ ol.renderer.Composite.prototype.draw = function(layers, center, resolution, anim
|
||||
for (var i=0, ii=layers.length; i<ii; ++i) {
|
||||
this.getOrCreateRenderer(layers[i], i).draw(center, resolution);
|
||||
}
|
||||
this.renderedCenter_ = center;
|
||||
this.renderedResolution_ = resolution;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
goog.provide('ol.renderer.MapRenderer');
|
||||
|
||||
goog.require('goog.style');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {!Element} container
|
||||
@@ -12,6 +14,18 @@ ol.renderer.MapRenderer = function(container) {
|
||||
*/
|
||||
this.container_ = container;
|
||||
|
||||
/**
|
||||
* @type {ol.Loc}
|
||||
* @protected
|
||||
*/
|
||||
this.renderedCenter_;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
* @protected
|
||||
*/
|
||||
this.renderedResolution_;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -67,3 +81,23 @@ ol.renderer.MapRenderer.pickRendererType = function(preferences) {
|
||||
return Renderer || Candidates[0] || null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {goog.math.Coordinate|{x: number, y: number}} pixel
|
||||
* @return {ol.Loc}
|
||||
*/
|
||||
ol.renderer.MapRenderer.prototype.getLocForPixel = function(pixel) {
|
||||
var center = this.renderedCenter_,
|
||||
resolution = this.renderedResolution_,
|
||||
size = goog.style.getSize(this.container_);
|
||||
return new ol.Loc(
|
||||
center.getX() - (size.width/2 - pixel.x) * resolution,
|
||||
center.getY() + (size.height/2 - pixel.y) * resolution
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {goog.math.Size} The currently rendered map size in pixels.
|
||||
*/
|
||||
ol.renderer.MapRenderer.prototype.getSize = function() {
|
||||
return goog.style.getSize(this.container_);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user