[OpenLayers-Commits] r2001 - in sandbox/vector/lib/OpenLayers: Geometry Renderer
commits at openlayers.org
commits at openlayers.org
Mon Dec 4 10:18:03 EST 2006
Author: pgiraud
Date: 2006-12-04 10:18:02 -0500 (Mon, 04 Dec 2006)
New Revision: 2001
Modified:
sandbox/vector/lib/OpenLayers/Geometry/Polygon.js
sandbox/vector/lib/OpenLayers/Renderer/Svg.js
sandbox/vector/lib/OpenLayers/Renderer/Vml.js
Log:
Polygon geometries are now managed as composite (aggregate)
Modified: sandbox/vector/lib/OpenLayers/Geometry/Polygon.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Geometry/Polygon.js 2006-12-04 13:59:55 UTC (rev 2000)
+++ sandbox/vector/lib/OpenLayers/Geometry/Polygon.js 2006-12-04 15:18:02 UTC (rev 2001)
@@ -9,37 +9,47 @@
*/
OpenLayers.Geometry.Polygon = OpenLayers.Class.create();
OpenLayers.Geometry.Polygon.prototype =
- OpenLayers.Class.inherit(OpenLayers.Geometry.Surface, {
-
+ OpenLayers.Class.inherit(OpenLayers.Geometry.Aggregate, {
+
/**
* @constructor
*
- * @param {array} linearRings
+ * @param {Array|OpenLayers.Geometry.Polygon}
*/
- initialize: function(linearRings) {
- OpenLayers.Geometry.Surface.prototype.initialize.apply(this,
- arguments);
-
- this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME+"_");
- this.linearRings = [];
+ initialize: function(components) {
+ OpenLayers.Geometry.prototype.initialize.apply(this, arguments);
+ this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME+"_");
- if (linearRings instanceof Array) {
- this.linearRings = linearRings;
+ if (components != null) {
+ this.addComponents(components);
}
},
/**
- * @returns the coordinates path as a string
+ * adds components to the MultiPolygon
+ *
+ * @param {Array|OpenLayers.Geometry.Polygon} point(s) to add
*/
- toString: function() {
- // TBD this.path doesn't exist
- return "foo bar";
-
- // The following is not correct
- // Because it only takes the first linearRing into account
- // It may be sufficient though
- // return this.linearRings[0].path.toString();
+ addComponents: function(components) {
+ if(!(components instanceof Array)) {
+ components = [components];
+ }
+ for (var i = 0; i < components.length; i++) {
+ if (!(components[i] instanceof OpenLayers.Geometry.LinearRing)) {
+ throw "component should be an OpenLayers.Geometry.LinearRing";
+ }
+ }
+ OpenLayers.Geometry.Aggregate.prototype.addComponents.apply(this, arguments);
},
+
+ /**
+ * removes components from the MultiPolygon
+ *
+ * @param {Array|OpenLayers.Geometry.Polygon} point(s) to add
+ */
+ removeComponents: function(components) {
+ OpenLayers.Geometry.Aggregate.prototype.removeComponents.apply(this, arguments);
+ },
CLASS_NAME: "OpenLayers.Geometry.Polygon"
});
Modified: sandbox/vector/lib/OpenLayers/Renderer/Svg.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Renderer/Svg.js 2006-12-04 13:59:55 UTC (rev 2000)
+++ sandbox/vector/lib/OpenLayers/Renderer/Svg.js 2006-12-04 15:18:02 UTC (rev 2001)
@@ -194,8 +194,8 @@
node.geometry = geometry;
var d = '';
- for (var j = 0;j < geometry.linearRings.length; j++) {
- var linearRing = geometry.linearRings[j];
+ for (var j = 0;j < geometry.components.length; j++) {
+ var linearRing = geometry.components[j];
d += " M";
for (var i = 0; i < linearRing.path.length; i++) {
d += " " + linearRing.path[i];
Modified: sandbox/vector/lib/OpenLayers/Renderer/Vml.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Renderer/Vml.js 2006-12-04 13:59:55 UTC (rev 2000)
+++ sandbox/vector/lib/OpenLayers/Renderer/Vml.js 2006-12-04 15:18:02 UTC (rev 2001)
@@ -259,7 +259,7 @@
* @param style {Style} a style to use when drawing
*/
drawPolygon: function(geometry, style) {
- var bbox = this._getVmlBoundingBox(geometry.linearRings[0].path);
+ var bbox = this._getVmlBoundingBox(geometry.components[0].path);
var node = this._nodeFactory("v:shape", geometry.id);
if(style.pointerEvents == "visiblePainted"){node.geometry = geometry;}
@@ -272,8 +272,8 @@
node.coordsize = this._vmlParseFloat(bbox.width)+ " " +this._vmlParseFloat(bbox.height);
var path = "";
- for (var j = 0; j < geometry.linearRings.length; j++) {
- var linearRing = geometry.linearRings[j];
+ for (var j = 0; j < geometry.components.length; j++) {
+ var linearRing = geometry.components[j];
if (j != 0) {
path += " x ";
}
More information about the Commits
mailing list