Add user projections
This commit is contained in:
+116
-1
@@ -24,6 +24,7 @@ goog.require('ol.Extent');
|
|||||||
goog.require('ol.LayerRenderer');
|
goog.require('ol.LayerRenderer');
|
||||||
goog.require('ol.Object');
|
goog.require('ol.Object');
|
||||||
goog.require('ol.Projection');
|
goog.require('ol.Projection');
|
||||||
|
goog.require('ol.TransformFunction');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,7 +38,8 @@ ol.MapProperty = {
|
|||||||
LAYERS: 'layers',
|
LAYERS: 'layers',
|
||||||
PROJECTION: 'projection',
|
PROJECTION: 'projection',
|
||||||
RESOLUTION: 'resolution',
|
RESOLUTION: 'resolution',
|
||||||
SIZE: 'size'
|
SIZE: 'size',
|
||||||
|
USER_PROJECTION: 'userProjection'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -62,6 +64,18 @@ ol.Map = function(target, opt_values, opt_viewportSizeMonitor) {
|
|||||||
|
|
||||||
goog.base(this);
|
goog.base(this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {ol.TransformFunction}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.userToMapTransform_ = ol.Projection.identityTransform;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {ol.TransformFunction}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.mapToUserTransform_ = ol.Projection.cloneTransform;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {HTMLDivElement}
|
* @type {HTMLDivElement}
|
||||||
@@ -147,6 +161,10 @@ ol.Map = function(target, opt_values, opt_viewportSizeMonitor) {
|
|||||||
this, ol.Object.getChangedEventType(ol.MapProperty.LAYERS),
|
this, ol.Object.getChangedEventType(ol.MapProperty.LAYERS),
|
||||||
this.handleLayersChanged, false, this);
|
this.handleLayersChanged, false, this);
|
||||||
|
|
||||||
|
goog.events.listen(
|
||||||
|
this, ol.Object.getChangedEventType(ol.MapProperty.PROJECTION),
|
||||||
|
this.handleProjectionChanged, false, this);
|
||||||
|
|
||||||
goog.events.listen(
|
goog.events.listen(
|
||||||
this, ol.Object.getChangedEventType(ol.MapProperty.RESOLUTION),
|
this, ol.Object.getChangedEventType(ol.MapProperty.RESOLUTION),
|
||||||
this.handleResolutionChanged, false, this);
|
this.handleResolutionChanged, false, this);
|
||||||
@@ -155,6 +173,10 @@ ol.Map = function(target, opt_values, opt_viewportSizeMonitor) {
|
|||||||
this, ol.Object.getChangedEventType(ol.MapProperty.SIZE),
|
this, ol.Object.getChangedEventType(ol.MapProperty.SIZE),
|
||||||
this.handleSizeChanged, false, this);
|
this.handleSizeChanged, false, this);
|
||||||
|
|
||||||
|
goog.events.listen(
|
||||||
|
this, ol.Object.getChangedEventType(ol.MapProperty.USER_PROJECTION),
|
||||||
|
this.handleUserProjectionChanged, false, this);
|
||||||
|
|
||||||
if (goog.isDef(opt_values)) {
|
if (goog.isDef(opt_values)) {
|
||||||
this.setValues(opt_values);
|
this.setValues(opt_values);
|
||||||
}
|
}
|
||||||
@@ -210,6 +232,14 @@ ol.Map.prototype.fitExtent = function(extent) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.Extent} userExtent Extent in user projection.
|
||||||
|
*/
|
||||||
|
ol.Map.prototype.fitUserExtent = function(userExtent) {
|
||||||
|
this.fitExtent(userExtent.transform(this.userToMapTransform_));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {function(this: T, ol.Layer, ol.LayerRenderer, number)} f Function.
|
* @param {function(this: T, ol.Layer, ol.LayerRenderer, number)} f Function.
|
||||||
* @param {T=} opt_obj Object.
|
* @param {T=} opt_obj Object.
|
||||||
@@ -358,6 +388,40 @@ ol.Map.prototype.getTarget = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {goog.math.Coordinate|undefined} Center in user projection.
|
||||||
|
*/
|
||||||
|
ol.Map.prototype.getUserCenter = function() {
|
||||||
|
var center = this.getCenter();
|
||||||
|
if (goog.isDef(center)) {
|
||||||
|
return this.mapToUserTransform_(center);
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {ol.Extent|undefined} Extent in user projection.
|
||||||
|
*/
|
||||||
|
ol.Map.prototype.getUserExtent = function() {
|
||||||
|
var extent = this.getExtent();
|
||||||
|
if (goog.isDef(extent)) {
|
||||||
|
return extent.transform(this.mapToUserTransform_);
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {ol.Projection|undefined} Projection.
|
||||||
|
*/
|
||||||
|
ol.Map.prototype.getUserProjection = function() {
|
||||||
|
return /** @type {ol.Projection} */ this.get(ol.MapProperty.USER_PROJECTION);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.handleBackgroundColorChanged = goog.nullFunction;
|
ol.Map.prototype.handleBackgroundColorChanged = goog.nullFunction;
|
||||||
@@ -473,6 +537,14 @@ ol.Map.prototype.handleLayersChanged = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
ol.Map.prototype.handleProjectionChanged = function() {
|
||||||
|
this.recalculateTransforms_();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
@@ -489,6 +561,14 @@ ol.Map.prototype.handleSizeChanged = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
ol.Map.prototype.handleUserProjectionChanged = function() {
|
||||||
|
this.recalculateTransforms_();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
@@ -521,6 +601,25 @@ ol.Map.prototype.recalculateExtent_ = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.Map.prototype.recalculateTransforms_ = function() {
|
||||||
|
var projection = this.getProjection();
|
||||||
|
var userProjection = this.getUserProjection();
|
||||||
|
if (goog.isDefAndNotNull(projection) &&
|
||||||
|
goog.isDefAndNotNull(userProjection)) {
|
||||||
|
this.mapToUserTransform_ = ol.Projection.getTransform(
|
||||||
|
projection, userProjection);
|
||||||
|
this.userToMapTransform_ = ol.Projection.getTransform(
|
||||||
|
userProjection, projection);
|
||||||
|
} else {
|
||||||
|
this.mapToUserTransform_ = ol.Projection.cloneTransform;
|
||||||
|
this.userToMapTransform_ = ol.Projection.identityTransform;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.redraw = function() {
|
ol.Map.prototype.redraw = function() {
|
||||||
@@ -644,6 +743,22 @@ ol.Map.prototype.setProjection = function(projection) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {goog.math.Coordinate} userCenter Center in user projection.
|
||||||
|
*/
|
||||||
|
ol.Map.prototype.setUserCenter = function(userCenter) {
|
||||||
|
this.setCenter(this.userToMapTransform_(userCenter));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.Projection} userProjection User projection.
|
||||||
|
*/
|
||||||
|
ol.Map.prototype.setUserProjection = function(userProjection) {
|
||||||
|
this.set(ol.MapProperty.USER_PROJECTION, userProjection);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {function(this: T)} f Function.
|
* @param {function(this: T)} f Function.
|
||||||
* @param {T=} opt_obj Object.
|
* @param {T=} opt_obj Object.
|
||||||
|
|||||||
Reference in New Issue
Block a user