[OpenLayers-Commits] r2370 - sandbox/vector-2.4/lib/OpenLayers/Geometry
commits at openlayers.org
commits at openlayers.org
Mon Mar 5 21:50:04 EST 2007
Author: euzuro
Date: 2007-03-05 21:50:04 -0500 (Mon, 05 Mar 2007)
New Revision: 2370
Modified:
sandbox/vector-2.4/lib/OpenLayers/Geometry/Collection.js
sandbox/vector-2.4/lib/OpenLayers/Geometry/MultiLineString.js
sandbox/vector-2.4/lib/OpenLayers/Geometry/MultiPoint.js
sandbox/vector-2.4/lib/OpenLayers/Geometry/MultiPolygon.js
Log:
coding standards on geometry.collection and add the ability to initialize a collection with an array of components (just like all the classes that subclass off of it). add an addComponent() function to add a single component, also making sure to extend the geometry's bounds
Modified: sandbox/vector-2.4/lib/OpenLayers/Geometry/Collection.js
===================================================================
--- sandbox/vector-2.4/lib/OpenLayers/Geometry/Collection.js 2007-03-06 01:34:26 UTC (rev 2369)
+++ sandbox/vector-2.4/lib/OpenLayers/Geometry/Collection.js 2007-03-06 02:50:04 UTC (rev 2370)
@@ -8,19 +8,34 @@
* @requires OpenLayers/Geometry.js
*/
OpenLayers.Geometry.Collection = OpenLayers.Class.create();
-OpenLayers.Geometry.Collection.prototype = OpenLayers.Class.inherit( OpenLayers.Geometry, {
+OpenLayers.Geometry.Collection.prototype =
+ OpenLayers.Class.inherit( OpenLayers.Geometry, {
+
/** @type Array(OpenLayers.Geometry) */
components: null,
/**
- * @constructor
- **/
- initialize: function () {
+ * @constructor
+ *
+ * @param {Array(OpenLayers.Geometry.Point)} components
+ */
+ initialize: function (components) {
OpenLayers.Geometry.prototype.initialize.apply(this, arguments);
- this.components = [];
+ this.components = new Array();
+ if (components != null) {
+ this.addComponents(components);
+ }
},
/**
+ *
+ */
+ destroy: function () {
+ this.components.length = 0;
+ this.components = null;
+ },
+
+ /**
* @returns An exact clone of this collection
* @type OpenLayers.Geometry.Collection
*/
@@ -30,7 +45,7 @@
}
for (var i = 0; i < this.components.length; i++) {
- obj.addComponents(this.components[i].clone());
+ obj.addComponent(this.components[i].clone());
}
// catch any randomly tagged-on properties
@@ -41,11 +56,15 @@
/**
* @returns the components of the geometry
+ * @type Array(OpenLayers.Geometry)
*/
getComponents: function(){
- return this.components ? this.components : null;
+ return this.components;
},
+ /**
+ * @type OpenLayers.Bounds
+ */
getBounds: function () {
if (!this.bounds) {
for (var i = 0; i < this.components.length; i++) {
@@ -56,14 +75,27 @@
},
/**
+ * @param {Array(OpenLayers.Geometry)} components
*
*/
addComponents: function(components){
if(!(components instanceof Array)) {
components = [components];
}
- this.components = this.components.concat(components);
+ for(var i=0; i < components.length; i++) {
+ this.addComponent(components[i]);
+ }
},
+
+ /** Add a new component (geometry) to the collection. Make sure to
+ * update the bounds by calling extendBounds()
+ *
+ * @param {OpenLayers.Geometry} component
+ */
+ addComponent: function(component) {
+ this.extendBounds(component.getBounds());
+ this.components.push(component);
+ },
/**
*
@@ -74,7 +106,8 @@
}
for (var i = 0; i < components.length; i++) {
- this.components = OpenLayers.Util.removeItem(this.components, components[i]);
+ this.components =
+ OpenLayers.Util.removeItem(this.components, components[i]);
}
// reset this.bounds so that it gets recalculated on the next call
@@ -173,11 +206,6 @@
}
},
- destroy: function () {
- this.components.length = 0;
- this.components = null;
- },
-
/** @final @type String */
CLASS_NAME: "OpenLayers.Geometry.Collection"
});
Modified: sandbox/vector-2.4/lib/OpenLayers/Geometry/MultiLineString.js
===================================================================
--- sandbox/vector-2.4/lib/OpenLayers/Geometry/MultiLineString.js 2007-03-06 01:34:26 UTC (rev 2369)
+++ sandbox/vector-2.4/lib/OpenLayers/Geometry/MultiLineString.js 2007-03-06 02:50:04 UTC (rev 2370)
@@ -8,51 +8,31 @@
* @requires OpenLayers/Geometry/Collection.js
*/
OpenLayers.Geometry.MultiLineString = OpenLayers.Class.create();
-
OpenLayers.Geometry.MultiLineString.prototype =
OpenLayers.Class.inherit(OpenLayers.Geometry.Collection, {
/**
- * @constructor
- *
- * @param {Array|OpenLayers.Geometry.LineString}
- */
+ * @constructor
+ *
+ * @param {Array(OpenLayers.Geometry.LineString)} components
+ */
initialize: function(components) {
- OpenLayers.Geometry.Collection.prototype.initialize.apply(this, arguments);
- this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME+"_");
-
- if (components != null) {
- this.addComponents(components);
- }
+ OpenLayers.Geometry.Collection.prototype.initialize.apply(this,
+ arguments);
},
/**
- * adds components to the MultiPoint
+ * adds a component to the MultiPoint, checking type
*
- * @param {Array|OpenLayers.Geometry.LineString} lineString(s) to add
+ * @param {OpenLayers.Geometry.LineString} component lineString to add
*/
- addComponents: function(components) {
- if(!(components instanceof Array)) {
- components = [components];
+ addComponent: function(component) {
+ if (!(components instanceof OpenLayers.Geometry.LineString)) {
+ throw "component should be an OpenLayers.Geometry.LineString";
}
-
- for (var i = 0; i < components.length; i++) {
- if (!(components[i] instanceof OpenLayers.Geometry.LineString)) {
- throw "component should be an OpenLayers.Geometry.LineString";
- }
- }
- OpenLayers.Geometry.Collection.prototype.addComponents.apply(this, arguments);
-
+ OpenLayers.Geometry.Collection.prototype.addComponent.apply(this,
+ arguments);
},
-
- /**
- * removes components from the MultiLineString
- *
- * @param {Array|OpenLayers.Geometry.LineString} lineString(s) to add
- */
- removeComponents: function(components) {
- OpenLayers.Geometry.Collection.prototype.removeComponents.apply(this, components);
- },
/** @final @type String */
CLASS_NAME: "OpenLayers.Geometry.MultiLineString"
Modified: sandbox/vector-2.4/lib/OpenLayers/Geometry/MultiPoint.js
===================================================================
--- sandbox/vector-2.4/lib/OpenLayers/Geometry/MultiPoint.js 2007-03-06 01:34:26 UTC (rev 2369)
+++ sandbox/vector-2.4/lib/OpenLayers/Geometry/MultiPoint.js 2007-03-06 02:50:04 UTC (rev 2370)
@@ -8,50 +8,31 @@
* @requires OpenLayers/Geometry/Collection.js
*/
OpenLayers.Geometry.MultiPoint = OpenLayers.Class.create();
-
OpenLayers.Geometry.MultiPoint.prototype =
OpenLayers.Class.inherit(OpenLayers.Geometry.Collection, {
/**
- * @constructor
- *
- * @param {Array|OpenLayers.Geometry.Point}
- */
+ * @constructor
+ *
+ * @param {Array(OpenLayers.Geometry.Point)} components
+ */
initialize: function(components) {
- OpenLayers.Geometry.Collection.prototype.initialize.apply(this, arguments);
- this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME+"_");
-
- if (components != null) {
- this.addComponents(components);
- }
+ OpenLayers.Geometry.Collection.prototype.initialize.apply(this,
+ arguments);
},
/**
- * adds components to the MultiPoint
+ * adds component to the MultiPoint, checking type
*
- * @param {Array|OpenLayers.Geometry.Point} point(s) to add
+ * @param {OpenLayers.Geometry.Point} component point to add
*/
- addComponents: function(components) {
- if(!(components instanceof Array)) {
- components = [components];
+ addComponent: function(component) {
+ if (!(component instanceof OpenLayers.Geometry.Point)) {
+ throw "component should be an OpenLayers.Geometry.Point";
}
-
- for (var i = 0; i < components.length; i++) {
- if (!(components[i] instanceof OpenLayers.Geometry.Point)) {
- throw "component should be an OpenLayers.Geometry.Point";
- }
- }
- OpenLayers.Geometry.Collection.prototype.addComponents.apply(this, arguments);
+ OpenLayers.Geometry.Collection.prototype.addComponent.apply(this,
+ arguments);
},
-
- /**
- * removes components from the MultiPoint
- *
- * @param {Array|OpenLayers.Geometry.Point} point(s) to add
- */
- removeComponents: function(components) {
- OpenLayers.Geometry.Collection.prototype.removeComponents.apply(this, arguments);
- },
/** @final @type String */
CLASS_NAME: "OpenLayers.Geometry.MultiPoint"
Modified: sandbox/vector-2.4/lib/OpenLayers/Geometry/MultiPolygon.js
===================================================================
--- sandbox/vector-2.4/lib/OpenLayers/Geometry/MultiPolygon.js 2007-03-06 01:34:26 UTC (rev 2369)
+++ sandbox/vector-2.4/lib/OpenLayers/Geometry/MultiPolygon.js 2007-03-06 02:50:04 UTC (rev 2370)
@@ -8,50 +8,32 @@
* @requires OpenLayers/Geometry/Collection.js
*/
OpenLayers.Geometry.MultiPolygon = OpenLayers.Class.create();
-
OpenLayers.Geometry.MultiPolygon.prototype =
OpenLayers.Class.inherit(OpenLayers.Geometry.Collection, {
/**
* @constructor
*
- * @param {Array|OpenLayers.Geometry.Polygon}
+ * @param {Array(OpenLayers.Geometry.Polygon)} components
*/
initialize: function(components) {
- OpenLayers.Geometry.Collection.prototype.initialize.apply(this, arguments);
- this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME+"_");
-
- if (components != null) {
- this.addComponents(components);
- }
+ OpenLayers.Geometry.Collection.prototype.initialize.apply(this,
+ arguments);
},
/**
- * adds components to the MultiPolygon
+ * adds component to the MultiPolygon, checking type
*
- * @param {Array|OpenLayers.Geometry.Polygon} point(s) to add
+ * @param {OpenLayers.Geometry.Polygon} component Polygon to add
*/
- addComponents: function(components) {
- if(!(components instanceof Array)) {
- components = [components];
+ addComponent: function(component) {
+ if (!(component instanceof OpenLayers.Geometry.Polygon)) {
+ throw "component should be an OpenLayers.Geometry.Polygon but is " + components[i].CLASS_NAME;
}
- for (var i = 0; i < components.length; i++) {
- if (!(components[i] instanceof OpenLayers.Geometry.Polygon)) {
- throw "component should be an OpenLayers.Geometry.Polygon but is " + components[i].CLASS_NAME;
- }
- }
- OpenLayers.Geometry.Collection.prototype.addComponents.apply(this, arguments);
+ OpenLayers.Geometry.Collection.prototype.addComponent.apply(this,
+ arguments);
},
- /**
- * removes components from the MultiPolygon
- *
- * @param {Array|OpenLayers.Geometry.Polygon} point(s) to add
- */
- removeComponents: function(components) {
- OpenLayers.Geometry.Collection.prototype.removeComponents.apply(this, arguments);
- },
-
/** @final @type String */
CLASS_NAME: "OpenLayers.Geometry.MultiPolygon"
});
More information about the Commits
mailing list