diff --git a/src/api/geom/geometry.js b/src/api/geom/geometry.js new file mode 100644 index 0000000000..d3fbb0508d --- /dev/null +++ b/src/api/geom/geometry.js @@ -0,0 +1,12 @@ +goog.provide('ol.geom.geometry'); + +goog.require('ol.geom.Geometry'); + +/** + * @export + * @return {ol.geom.Geometry} Geometry.. + */ +ol.geom.geometry = function(){ + var g = new ol.geom.Geometry(); + return g; +}; diff --git a/src/api/geom/point.js b/src/api/geom/point.js new file mode 100644 index 0000000000..c82afd905a --- /dev/null +++ b/src/api/geom/point.js @@ -0,0 +1,43 @@ +goog.provide('ol.geom.point'); + +goog.require('ol.geom.Point'); + +/** + * @typedef {ol.PointLike|Array.|Object} point Point. + */ +ol.PointLike; + +/** + * @export + * @param {ol.PointLike} opt_arg Point. + * @return {ol.geom.Point} Point. + */ +ol.geom.point = function(opt_arg){ + + if (opt_arg instanceof ol.geom.Point) { + return opt_arg; + } + + var x = 0; + var y = 0; + var z; + + 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]; + } else if (goog.isObject(opt_arg)) { + x = opt_arg.x; + y = opt_arg.y; + z = opt_arg.z; + } else { + throw new Error('ol.geom.point'); + } + } + + + var p = new ol.geom.Point(x,y,z); + return p; +}; +goog.inherits(ol.geom.point, ol.geom.geometry); \ No newline at end of file diff --git a/src/ol.js b/src/ol.js index 93a9a92342..e3a5bdbef6 100644 --- a/src/ol.js +++ b/src/ol.js @@ -3,6 +3,7 @@ goog.require('ol.bounds'); goog.require("ol.map"); goog.require("ol.loc"); goog.require("ol.projection"); - goog.require("ol.Tile"); goog.require("ol.TileSet"); +goog.require("ol.geom.geometry"); +goog.require("ol.geom.point"); diff --git a/src/ol/geom/Geometry.js b/src/ol/geom/Geometry.js new file mode 100644 index 0000000000..bf2fe66fc1 --- /dev/null +++ b/src/ol/geom/Geometry.js @@ -0,0 +1,52 @@ +goog.provide('ol.geom.Geometry'); + +goog.require('ol.Bounds'); +goog.require('ol.mixins.coordinate'); + +/** + * Creates ol.Geometry objects. + * + * @constructor + */ +ol.geom.Geometry = function() { + + /** + * @private + * @type {ol.Bounds|undefined} + */ + this.bounds_ = undefined; +}; + + + + + +/** + * @return {ol.Bounds|undefined} The ol.Bounds. + */ +ol.geom.Geometry.prototype.getBounds = function() { + return this.bounds_; +}; + +/** + * @param {ol.Bounds} bounds The new ol.Bounds. + * @return {ol.geom.Geometry} This. + */ +ol.geom.Geometry.prototype.setBounds = function(bounds) { + this.bounds_ = bounds; + return this; +}; + +/** + * @export + * @param {ol.Bounds=} opt_arg new Bounds. + * @return {ol.geom.Geometry|ol.Bounds|undefined} either a Geometry (when used as + * setter) or a Bounds/undefined (if used as getter). + */ +ol.geom.Geometry.prototype.bounds = function(opt_arg){ + if (arguments.length == 1 && goog.isDef(opt_arg)) { + return this.setBounds(opt_arg); + } else { + return this.getBounds(); + } +}; \ No newline at end of file diff --git a/src/ol/geom/Point.js b/src/ol/geom/Point.js new file mode 100644 index 0000000000..9f2d29b79c --- /dev/null +++ b/src/ol/geom/Point.js @@ -0,0 +1,65 @@ +goog.provide('ol.geom.Point'); +goog.require('ol.geom.Geometry'); +goog.require('ol.mixins.coordinate'); +goog.require('ol.interfaces.coordinateAccessor'); + +/** + * Creates ol.geom.Point objects. + * + * @extends {ol.geom.Geometry} + * @param {number} x X. + * @param {number} y Y. + * @param {number=} opt_z Z. + * + * @implements {ol.interfaces.coordinateAccessor} + * + * @constructor + */ +ol.geom.Point = function(x, y, opt_z) { + /** + * @private + * @type {number} + */ + this.x_ = x; + + /** + * @private + * @type {number} + */ + this.y_ = y; + + /** + * @private + * @type {number|undefined} + */ + this.z_ = opt_z; +}; + +goog.inherits(ol.geom.Point, ol.geom.Geometry); + +goog.mixin(ol.geom.Point.prototype, ol.mixins.coordinate); + +///** +// * @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; diff --git a/src/ol/interfaces/coordinateAccessor.js b/src/ol/interfaces/coordinateAccessor.js new file mode 100644 index 0000000000..c9a04244d3 --- /dev/null +++ b/src/ol/interfaces/coordinateAccessor.js @@ -0,0 +1,48 @@ +goog.provide('ol.interfaces.coordinateAccessor'); + +/** + * The coordinateAccessor interface + * + * @lends {ol.geom.Point#} + * @interface + * + * @param {number} x X. + * @param {number} y Y. + * @param {number=} opt_z Z. + */ +ol.interfaces.coordinateAccessor = function(x, y, opt_z){ + +}; + +/** + * @return {number} X. + */ +ol.interfaces.coordinateAccessor.prototype.getX = function(){}; + +/** + * @return {number} Y. + */ +ol.interfaces.coordinateAccessor.prototype.getY = function(){}; + +/** + * @return {number|undefined} Z. + */ +ol.interfaces.coordinateAccessor.prototype.getZ = function(){}; + +/** + * @param {number} x X. + * @return {Object} This. + */ +ol.interfaces.coordinateAccessor.prototype.setX = function(x){}; + +/** + * @param {number} y Y. + * @return {Object} This. + */ +ol.interfaces.coordinateAccessor.prototype.setY = function(y){}; + +/** + * @param {number|undefined} z Z. + * @return {Object} This. + */ +ol.interfaces.coordinateAccessor.prototype.setZ = function(z){}; diff --git a/src/ol/mixins/coordinate.js b/src/ol/mixins/coordinate.js new file mode 100644 index 0000000000..599592302a --- /dev/null +++ b/src/ol/mixins/coordinate.js @@ -0,0 +1,31 @@ +goog.provide('ol.mixins.coordinate'); +goog.require('goog.object'); + +goog.object.extend(ol.mixins.coordinate, { + + getX : function() { + return this.x_; + }, + + getY : function() { + return this.y_; + }, + + getZ : function() { + return this.z_; + }, + + setX : function(x) { + this.x_ = x; + return this; + }, + + setY : function(y) { + this.y_ = y; + return this; + }, + setZ: function(z) { + this.z_ = z; + return this; + } +}); diff --git a/test/index.html b/test/index.html index 3f64ee9160..71f8e20341 100644 --- a/test/index.html +++ b/test/index.html @@ -18,6 +18,8 @@ + +