Move code to be merged into src/attic
This commit is contained in:
@@ -1,198 +0,0 @@
|
||||
goog.provide('ol.geom.Collection');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.base');
|
||||
|
||||
/**
|
||||
* Creates ol.geom.Collection objects.
|
||||
*
|
||||
* @export
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {Array.<ol.geom.Geometry>} components An array of components.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.Collection = function(components) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<Function>}
|
||||
*/
|
||||
this.typeBlacklist_ = [
|
||||
ol.geom.Collection
|
||||
];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<Function>}
|
||||
*/
|
||||
this.typeWhitelist_ = [
|
||||
ol.geom.MultiPoint,
|
||||
ol.geom.MultiLineString
|
||||
// TODO uncomment when implemented
|
||||
// ,ol.geom.MultiPolygon
|
||||
];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<ol.geom.Geometry>}
|
||||
*/
|
||||
this.components_ = [];
|
||||
|
||||
if (arguments.length === 1 && goog.isDef(components)) {
|
||||
this.setComponents(components);
|
||||
}
|
||||
};
|
||||
|
||||
goog.inherits(ol.geom.Collection, ol.geom.Geometry);
|
||||
|
||||
/**
|
||||
* Sets the list of disallowed types for the collection.
|
||||
* @param {Array.<Function>} typeBlacklist Array of constructors to disallow.
|
||||
*/
|
||||
ol.geom.Collection.prototype.setTypeBlacklist = function(typeBlacklist){
|
||||
this.typeBlacklist_ = typeBlacklist;
|
||||
};
|
||||
/**
|
||||
* Gets the list of disallowed types for the collection.
|
||||
* @return {Array.<Function>} Array of constructors to disallow.
|
||||
*/
|
||||
ol.geom.Collection.prototype.getTypeBlacklist = function(){
|
||||
return this.typeBlacklist_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the list of always allowed types for the collection.
|
||||
* @param {Array.<Function>} typeWhitelist Array of constructors to allow.
|
||||
*/
|
||||
ol.geom.Collection.prototype.setTypeWhitelist = function(typeWhitelist){
|
||||
this.typeWhitelist_ = typeWhitelist;
|
||||
};
|
||||
/**
|
||||
* Gets the list of always allowed types for the collection.
|
||||
* @return {Array.<Function>} Array of constructors to allow.
|
||||
*/
|
||||
ol.geom.Collection.prototype.getTypeWhitelist = function(){
|
||||
return this.typeWhitelist_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Sets the Collection's components.
|
||||
*
|
||||
* @return {Array.<ol.geom.Geometry>} An array of components.
|
||||
*/
|
||||
ol.geom.Collection.prototype.getComponents = function() {
|
||||
return this.components_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the Collection's components.
|
||||
*
|
||||
* @param {Array.<ol.geom.Geometry>} components An array of components.
|
||||
*/
|
||||
ol.geom.Collection.prototype.setComponents = function(components) {
|
||||
var allValidTypes = goog.array.every(
|
||||
components,
|
||||
this.isAllowedComponent,
|
||||
this
|
||||
);
|
||||
if (allValidTypes) {
|
||||
this.components_ = components;
|
||||
} else {
|
||||
var msg = 'ol.geom.Collection: at least one component passed to '
|
||||
+ 'setComponents is not allowed.';
|
||||
ol.error(msg);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds the given component to the list of components at the specified index.
|
||||
*
|
||||
* @param {ol.geom.Geometry} component A component to be added.
|
||||
* @param {number} index The index where to add.
|
||||
*/
|
||||
ol.geom.Collection.prototype.addComponent = function(component, index) {
|
||||
if (this.isAllowedComponent(component)) {
|
||||
goog.array.insertAt(this.components_, component, index);
|
||||
} else {
|
||||
var msg = 'ol.geom.Collection: component is not allowed to be added.';
|
||||
ol.error(msg);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks whether the passed component is an instance of any of the constructors
|
||||
* listed in the passed list.
|
||||
*
|
||||
* @param {ol.geom.Geometry} component The component to check.
|
||||
* @param {Array.<Function>} list The List of constructors to check the
|
||||
* component against.
|
||||
*
|
||||
* @return {boolean} Whether the passed component is an instance of any of the
|
||||
* constructors listed in the passed list.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
ol.geom.Collection.prototype.isOnList = function(component, list) {
|
||||
var isOnList = !goog.array.every(list, function(listedConstr){
|
||||
if (component instanceof listedConstr) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return isOnList;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks whether the passed component is allowed according to the black and
|
||||
* whitelists.
|
||||
*
|
||||
* @param {ol.geom.Geometry} component The component to check.
|
||||
* @return {boolean} Whether the passed component is allowed as part of this
|
||||
* collection according to black- and whitelist.
|
||||
*/
|
||||
ol.geom.Collection.prototype.isAllowedComponent = function(component){
|
||||
var whitelist = this.getTypeWhitelist(),
|
||||
blacklist = this.getTypeBlacklist(),
|
||||
isOnWhitelist = this.isOnList(component, whitelist),
|
||||
isOnBlacklist = this.isOnList(component, blacklist);
|
||||
return (isOnWhitelist || !isOnBlacklist);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the given component from the list of components.
|
||||
*
|
||||
* @param {ol.geom.Geometry} component A component to be removed.
|
||||
*/
|
||||
ol.geom.Collection.prototype.removeComponent = function(component) {
|
||||
goog.array.remove(this.components_, component);
|
||||
};
|
||||
|
||||
/**
|
||||
* Compute the centroid for this geometry collection.
|
||||
*
|
||||
* @returns {ol.geom.Point} The centroid of the collection.
|
||||
*/
|
||||
ol.geom.Collection.prototype.getCentroid = function() {
|
||||
var components = this.getComponents(),
|
||||
len = components.length,
|
||||
sum_x = 0, sum_y = 0,
|
||||
centroid = null;
|
||||
if (len > 0) {
|
||||
goog.array.forEach(components, function(component){
|
||||
var singleCentroid = component.getCentroid();
|
||||
if (goog.isDefAndNotNull(singleCentroid)) {
|
||||
sum_x += singleCentroid.getX();
|
||||
sum_y += singleCentroid.getX();
|
||||
} else {
|
||||
len--;
|
||||
}
|
||||
});
|
||||
centroid = new ol.geom.Point(sum_x / len, sum_y / len);
|
||||
}
|
||||
return centroid;
|
||||
};
|
||||
@@ -1,58 +0,0 @@
|
||||
goog.provide('ol.geom.Geometry');
|
||||
|
||||
goog.require('ol.geom.IGeometry');
|
||||
goog.require('ol.Bounds');
|
||||
|
||||
/**
|
||||
* Creates ol.Geometry objects.
|
||||
*
|
||||
* @export
|
||||
* @implements {ol.geom.IGeometry}
|
||||
* @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;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the centroid of the geometry.
|
||||
*
|
||||
* @returns {ol.geom.Point} The centroid of the geometry.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.getCentroid = function() {
|
||||
// throw an error to enforce subclasses to implement it properly
|
||||
ol.error('ol.geom.Geometry: getCentroid must be implemented by subclasses');
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the area of the geometry.
|
||||
*
|
||||
* @returns {number} The area of the geometry.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.getArea = function() {
|
||||
// throw an error to enforce subclasses to implement it properly
|
||||
ol.error('ol.geom.Geometry: getArea must be implemented by subclasses');
|
||||
return 0;
|
||||
};
|
||||
@@ -1,27 +0,0 @@
|
||||
goog.provide('ol.geom.IGeometry');
|
||||
|
||||
//goog.require('ol.geom.Point');
|
||||
//goog.require('ol.Bounds');
|
||||
|
||||
/**
|
||||
* Interface for geometry classes forcing ol.geom.* classes to implement
|
||||
* expected functionality.
|
||||
*
|
||||
* @interface
|
||||
*/
|
||||
ol.geom.IGeometry = function(){};
|
||||
|
||||
/**
|
||||
* @return {ol.geom.Point} The centroid of the geometry.
|
||||
*/
|
||||
ol.geom.IGeometry.prototype.getCentroid = function(){};
|
||||
|
||||
/**
|
||||
* @return {ol.Bounds|undefined} The centroid of the geometry.
|
||||
*/
|
||||
ol.geom.IGeometry.prototype.getBounds = function(){};
|
||||
|
||||
/**
|
||||
* @return {number} The area of the geometry.
|
||||
*/
|
||||
ol.geom.IGeometry.prototype.getArea = function(){};
|
||||
@@ -1,76 +0,0 @@
|
||||
goog.provide('ol.geom.LineString');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.Collection');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.Projection');
|
||||
|
||||
/**
|
||||
* Creates ol.geom.LineString objects.
|
||||
*
|
||||
* @export
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {Array.<ol.geom.Point>} vertices An array of points building the
|
||||
* linestrings vertices.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.LineString = function(vertices) {
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<ol.geom.Point>}
|
||||
*/
|
||||
this.vertices_ = vertices;
|
||||
|
||||
};
|
||||
|
||||
goog.inherits(ol.geom.LineString, ol.geom.Geometry);
|
||||
|
||||
/**
|
||||
* Sets the LineString's points.
|
||||
*
|
||||
* @return {Array.<ol.geom.Point>} An array of points.
|
||||
*/
|
||||
ol.geom.LineString.prototype.getVertices = function() {
|
||||
return this.vertices_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the LineString's points.
|
||||
*
|
||||
* @param {Array.<ol.geom.Point>} vertices An array of points.
|
||||
*/
|
||||
ol.geom.LineString.prototype.setVertices = function(vertices) {
|
||||
this.vertices_ = vertices;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds the given vertex to the list of vertices at the specified index.
|
||||
*
|
||||
* @param {ol.geom.Point} vertex A point to be added.
|
||||
* @param {number} index The index where to add.
|
||||
*/
|
||||
ol.geom.LineString.prototype.addVertex = function(vertex, index) {
|
||||
goog.array.insertAt(this.vertices_,vertex,index);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the given vertex from the list of vertices.
|
||||
*
|
||||
* @param {ol.geom.Point} vertex A point to be removed.
|
||||
*/
|
||||
ol.geom.LineString.prototype.removeVertex = function(vertex) {
|
||||
goog.array.remove(this.vertices_, vertex);
|
||||
};
|
||||
|
||||
/**
|
||||
* Compute the centroid for this linestring.
|
||||
*
|
||||
* @returns {ol.geom.Point} The centroid of the linestring.
|
||||
*/
|
||||
ol.geom.LineString.prototype.getCentroid = function() {
|
||||
var vertices = this.getVertices(),
|
||||
collection = new ol.geom.Collection(vertices);
|
||||
return collection.getCentroid();
|
||||
};
|
||||
@@ -1,61 +0,0 @@
|
||||
goog.provide('ol.geom.MultiLineString');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('ol.geom.Collection');
|
||||
|
||||
/**
|
||||
* Creates ol.geom.MultiLineString objects.
|
||||
*
|
||||
* @export
|
||||
* @extends {ol.geom.Collection}
|
||||
* @param {Array.<ol.geom.LineString>} linestrings An array of linestrings.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.MultiLineString = function(linestrings) {
|
||||
this.setTypeWhitelist([ol.geom.LineString]);
|
||||
this.setTypeBlacklist([ol.geom.Geometry]);
|
||||
if (arguments.length === 1 && goog.isDef(linestrings)) {
|
||||
this.setLineStrings(linestrings);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
goog.inherits(ol.geom.MultiLineString, ol.geom.Collection);
|
||||
|
||||
/**
|
||||
* Gets the MultiLineString's linestrings.
|
||||
*
|
||||
* @return {Array.<ol.geom.LineString>} An array of linestrings.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.getLineStrings = function() {
|
||||
return this.getComponents();
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the MultiLineString's linestrings.
|
||||
*
|
||||
* @param {Array.<ol.geom.LineString>} linestrings An array of linestrings.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.setLineStrings = function(linestrings) {
|
||||
this.setComponents(linestrings);
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds the given linestring to the list of linestrings at the specified index.
|
||||
*
|
||||
* @param {ol.geom.LineString} linestring A linestring to be added.
|
||||
* @param {number} index The index where to add.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.addLineString = function(linestring, index) {
|
||||
this.addComponent(linestring, index);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the given linestring from the list of linestrings.
|
||||
*
|
||||
* @param {ol.geom.LineString} linestring A linestring to be removed.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.removeLineString = function(linestring) {
|
||||
this.removeComponent(linestring);
|
||||
};
|
||||
@@ -1,61 +0,0 @@
|
||||
goog.provide('ol.geom.MultiPoint');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('ol.geom.Collection');
|
||||
|
||||
/**
|
||||
* Creates ol.geom.MultiPoint objects.
|
||||
*
|
||||
* @export
|
||||
* @extends {ol.geom.Collection}
|
||||
* @param {Array.<ol.geom.Point>} points An array of points.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.MultiPoint = function(points) {
|
||||
this.setTypeWhitelist([ol.geom.Point]);
|
||||
this.setTypeBlacklist([ol.geom.Geometry]);
|
||||
if (arguments.length === 1 && goog.isDef(points)) {
|
||||
this.setPoints(points);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
goog.inherits(ol.geom.MultiPoint, ol.geom.Collection);
|
||||
|
||||
/**
|
||||
* Sets the MultiPoint's points.
|
||||
*
|
||||
* @return {Array.<ol.geom.Point>} An array of points.
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.getPoints = function() {
|
||||
return this.getComponents();
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the MultiPoint's points.
|
||||
*
|
||||
* @param {Array.<ol.geom.Point>} points An array of points.
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.setPoints = function(points) {
|
||||
this.setComponents(points);
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds the given point to the list of points at the specified index.
|
||||
*
|
||||
* @param {ol.geom.Point} point A point to be added.
|
||||
* @param {number} index The index where to add.
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.addPoint = function(point, index) {
|
||||
this.addComponent(point, index);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the given point from the list of points.
|
||||
*
|
||||
* @param {ol.geom.Point} point A point to be removed.
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.removePoint = function(point) {
|
||||
this.removeComponent(point);
|
||||
};
|
||||
@@ -1,163 +0,0 @@
|
||||
goog.provide('ol.geom.Point');
|
||||
|
||||
goog.require('ol.geom.Geometry');
|
||||
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.coord.AccessorInterface');
|
||||
goog.require('ol.base');
|
||||
|
||||
/**
|
||||
* Creates ol.geom.Point objects.
|
||||
*
|
||||
* @export
|
||||
* @extends {ol.geom.Geometry}
|
||||
* @param {number} x X.
|
||||
* @param {number} y Y.
|
||||
* @param {number=} opt_z Z.
|
||||
* @param {ol.Projection=} opt_projection Projection.
|
||||
*
|
||||
* @implements {ol.coord.AccessorInterface}
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.geom.Point = function(x, y, opt_z, opt_projection) {
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.x_ = x;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.y_ = y;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @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;
|
||||
};
|
||||
|
||||
/**
|
||||
* Transform this point to another coordinate reference system. This
|
||||
* requires that this point has a projection set already (if not, an error
|
||||
* will be thrown). Returns a new point object and does not modify this
|
||||
* point.
|
||||
*
|
||||
* @param {string|!ol.Projection} proj The destination projection. Can be
|
||||
* supplied as a projection instance of a string identifier.
|
||||
* @returns {!ol.geom.Point} A new location.
|
||||
*/
|
||||
ol.geom.Point.prototype.transform = function(proj) {
|
||||
if (goog.isString(proj)) {
|
||||
proj = new ol.Projection(proj);
|
||||
}
|
||||
return this._transform(proj);
|
||||
};
|
||||
|
||||
/**
|
||||
* Transform this point to a new location given a projection object.
|
||||
*
|
||||
* @param {!ol.Projection} proj The destination projection.
|
||||
* @returns {!ol.geom.Point}
|
||||
* @private
|
||||
*/
|
||||
ol.geom.Point.prototype._transform = function(proj) {
|
||||
var point = {'x': this.x_, 'y': this.y_};
|
||||
var sourceProj = this.projection_;
|
||||
if (!goog.isDefAndNotNull(sourceProj)) {
|
||||
var msg = 'Cannot transform a point without a source projection.';
|
||||
ol.error(msg);
|
||||
}
|
||||
ol.Projection.transform(point, sourceProj, proj);
|
||||
|
||||
return new ol.geom.Point(point['x'], point['y'], this.z_, proj);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the centroid of the point.
|
||||
*
|
||||
* @returns {ol.geom.Point} The centroid of the point.
|
||||
*/
|
||||
ol.geom.Point.prototype.getCentroid = function() {
|
||||
return new ol.geom.Point(this.x_, this.y_, this.z_, this.projection_);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the area of the geometry whcih is always 0.
|
||||
*
|
||||
* @returns {number} The area of the point (always 0).
|
||||
*/
|
||||
ol.geom.Point.prototype.getArea = function() {
|
||||
return 0;
|
||||
};
|
||||
Reference in New Issue
Block a user