Remove the mixin approach and give the Point class a projection.

This commit is contained in:
Marc Jansen
2012-06-20 11:18:07 +02:00
parent 073c636cb2
commit aec8f953e5
5 changed files with 119 additions and 55 deletions
+9 -2
View File
@@ -1,6 +1,7 @@
goog.provide('ol.geom.point');
goog.require('ol.geom.Point');
goog.require('ol.projection');
/**
* @typedef {ol.PointLike|Array.<number>|Object} point Point.
@@ -21,23 +22,29 @@ ol.geom.point = function(opt_arg){
var x = 0;
var y = 0;
var z;
var projection;
if (arguments.length == 1 && goog.isDef(opt_arg)) {
if (goog.isArray(opt_arg)) {
x = opt_arg[0];
y = opt_arg[1];
z = opt_arg[2];
projection = opt_arg[3];
} else if (goog.isObject(opt_arg)) {
x = opt_arg.x;
y = opt_arg.y;
z = opt_arg.z;
projection = opt_arg.projection;
} else {
throw new Error('ol.geom.point');
}
}
if (goog.isDef(projection)) {
projection = ol.projection(projection);
}
var p = new ol.geom.Point(x,y,z);
var p = new ol.geom.Point(x,y,z,projection);
return p;
};
goog.inherits(ol.geom.point, ol.geom.geometry);
-1
View File
@@ -1,7 +1,6 @@
goog.provide('ol.geom.Geometry');
goog.require('ol.Bounds');
goog.require('ol.mixins.coordinate');
/**
* Creates ol.Geometry objects.
+73 -30
View File
@@ -1,7 +1,9 @@
goog.provide('ol.geom.Point');
goog.provide('ol.geom.Point');
goog.require('ol.geom.Geometry');
goog.require('ol.mixins.coordinate');
goog.require('ol.interfaces.coordinateAccessor');
goog.require('ol.Projection');
goog.require('ol.coord.AccessorInterface');
/**
* Creates ol.geom.Point objects.
@@ -10,12 +12,13 @@ goog.require('ol.interfaces.coordinateAccessor');
* @param {number} x X.
* @param {number} y Y.
* @param {number=} opt_z Z.
* @param {ol.Projection=} opt_projection Projection.
*
* @implements {ol.interfaces.coordinateAccessor}
* @implements {ol.coord.AccessorInterface}
*
* @constructor
*/
ol.geom.Point = function(x, y, opt_z) {
ol.geom.Point = function(x, y, opt_z, opt_projection) {
/**
* @private
* @type {number}
@@ -33,33 +36,73 @@ ol.geom.Point = function(x, y, opt_z) {
* @type {number|undefined}
*/
this.z_ = opt_z;
/**
* @private
* @type {ol.Projection}
*/
this.projection_ = goog.isDef(opt_projection) ? opt_projection : null;
};
goog.inherits(ol.geom.Point, ol.geom.Geometry);
goog.mixin(ol.geom.Point.prototype, ol.mixins.coordinate);
/**
* @return {number} X.
*/
ol.geom.Point.prototype.getX = function() {
return this.x_;
};
/**
* @return {number} Y.
*/
ol.geom.Point.prototype.getY = function() {
return this.y_;
};
/**
* @return {number|undefined} Z.
*/
ol.geom.Point.prototype.getZ = function() {
return this.z_;
};
/**
* @return {ol.Projection|undefined} Projection.
*/
ol.geom.Point.prototype.getProjection = function() {
return this.projection_;
};
/**
* @param {ol.Projection} projection Projection.
*/
ol.geom.Point.prototype.setProjection = function(projection) {
this.projection_ = projection;
};
/**
* @param {number} x X.
*/
ol.geom.Point.prototype.setX = function(x) {
this.x_ = x;
};
/**
* @param {number} y Y.
*/
ol.geom.Point.prototype.setY = function(y) {
this.y_ = y;
};
/**
* @param {number|undefined} z Z.
*/
ol.geom.Point.prototype.setZ = function(z) {
this.z_ = z;
};
///**
// * @override
// */
//ol.geom.Point.prototype.getX = ol.geom.Point.prototype.getX;
///**
// * @override
// */
//ol.geom.Point.prototype.setX = ol.geom.Point.prototype.setX;
///**
// * @override
// */
//ol.geom.Point.prototype.getY = ol.geom.Point.prototype.getY;
///**
// * @override
// */
//ol.geom.Point.prototype.setY = ol.geom.Point.prototype.setY;
///**
// * @override
// */
//ol.geom.Point.prototype.getZ = ol.geom.Point.prototype.getZ;
///**
// * @override
// */
//ol.geom.Point.prototype.setZ = ol.geom.Point.prototype.setZ;