[OpenLayers-Commits] r2152 - sandbox/vector/lib/OpenLayers/Renderer
commits at openlayers.org
commits at openlayers.org
Thu Jan 18 10:40:23 EST 2007
Author: fredj
Date: 2007-01-18 10:40:20 -0500 (Thu, 18 Jan 2007)
New Revision: 2152
Modified:
sandbox/vector/lib/OpenLayers/Renderer/Svg.js
Log:
clean code, coding style
Modified: sandbox/vector/lib/OpenLayers/Renderer/Svg.js
===================================================================
--- sandbox/vector/lib/OpenLayers/Renderer/Svg.js 2007-01-18 15:35:40 UTC (rev 2151)
+++ sandbox/vector/lib/OpenLayers/Renderer/Svg.js 2007-01-18 15:40:20 UTC (rev 2152)
@@ -1,10 +1,10 @@
/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
- * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt
+ * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt
* for the full text of the license. */
/**
* @class
- *
+ *
* @requires OpenLayers/Renderer.js
*/
OpenLayers.Renderer.Svg = OpenLayers.Class.create();
@@ -12,60 +12,52 @@
/**
* SVG xmlns
- */
+ */
svgns: "http://www.w3.org/2000/svg",
-
+
/**
* constructor
*/
initialize: function(element) {
- this.container = $(element);
-
- this.root = this._nodeFactory("g", this.container.id+ "_root");
- this.root.setAttributeNS(null, "transform", "scale(1, -1)");
-
- this.svgRoot = this._nodeFactory("svg", this.container.id+ "_svgRoot");
- this.svgRoot.appendChild(this.root);
-
- this.container.appendChild(this.svgRoot);
+ this.createRoot(element);
},
/**
* function
*
* Create the SVG root node.
- */
+ */
createRoot: function(element) {
if (!this.root) {
this.container = $(element);
- this.root = this._nodeFactory("g", this.container.id+ "_root");
+ this.root = this._nodeFactory("g", this.container.id + "_root");
this.root.setAttributeNS(null, "transform", "scale(1, -1)");
-
- this.svgRoot = this._nodeFactory("svg", this.container.id+ "_svgRoot");
+
+ this.svgRoot = this._nodeFactory("svg", this.container.id + "_svgRoot");
this.svgRoot.appendChild(this.root);
-
+
this.container.appendChild(this.svgRoot);
}
return this.root;
},
-
+
/**
* function
*
* Remove the svg root element from the container
*
- */
+ */
deleteRoot: function(element) {
this.container.removeChild(this.svgRoot);
},
-
+
/**
* function
*
* Remove all the elements of the root
*
- */
+ */
clearRoot: function() {
while (this.root.childNodes.length > 0) {
this.root.removeChild(this.root.firstChild);
@@ -90,11 +82,11 @@
this.extHeight = height;
this.svgRoot.setAttributeNS(null, "viewBox", x+ " " +-y+ " " +width+ " " +height);
-
+
// reset stroke and point width for each svg node
var childNodes = this.root.childNodes;
var childNodesLength = childNodes.length;
-
+
if (this.resolution != lastResolution) {
for (var i = 0; i < childNodesLength; i++) {
var node = this.root.childNodes[i];
@@ -108,7 +100,7 @@
}
}
},
-
+
/**
* function
*
@@ -123,10 +115,10 @@
this.svgRoot.setAttributeNS(null, "width", width);
this.svgRoot.setAttributeNS(null, "height", height);
},
-
+
/**
* function
- *
+ *
* returns a geometry from an event. How this
* happens is specific to the renderer.
*
@@ -139,8 +131,8 @@
var geometry = node.geometry?node.geometry:null;
return geometry;
},
-
- /**
+
+ /**
* draw a geometry.
*
* @param geometry {Geometry} a geometry to draw
@@ -148,7 +140,7 @@
drawGeometry: function(geometry, style) {
OpenLayers.Renderer.prototype.drawGeometry.apply(this, arguments);
},
-
+
/**
* function
*
@@ -159,18 +151,18 @@
eraseGeometry: function(geometry) {
element = $(geometry.id);
if (element && element.parentNode) {
-
+
// destroy the geometry reference to resolve memory leaks problem.
if (element.geometry) {
element.geometry = null;
}
-
+
element.parentNode.removeChild(element);
}
return geometry;
},
-
- /**
+
+ /**
* function
*
* draw a point geometry.
@@ -185,13 +177,13 @@
node.setAttributeNS(null, "cy", geometry.y);
node.setAttributeNS(null, "r", this._getLenthFromResolutions(style.pointRadius, 1, this.resolution));
-
+
this._setStyle(node, style, true, true);
this.root.appendChild(node);
return node;
},
-
- /**
+
+ /**
* function
*
* draw a line geometry.
@@ -203,11 +195,11 @@
var node = this._nodeFactory("polyline", geometry.id);
this._setStyle(node, style, false, true);
node.geometry = geometry;
- node.setAttributeNS(null, "points", geometry.path);
+ node.setAttributeNS(null, "points", geometry.path);
this.root.appendChild(node);
},
-
- /**
+
+ /**
* function
*
* draw a linear ring geometry.
@@ -222,8 +214,8 @@
this._setStyle(node, style, true, true);
this.root.appendChild(node);
},
-
- /**
+
+ /**
* function
*
* draw a polygon geometry.
@@ -244,15 +236,15 @@
}
}
d += " z";
-
+
node.setAttributeNS(null, "d", d);
node.setAttributeNS(null, "fill-rule", "evenodd");
-
- this._setStyle(node, style, true, true);
+
+ this._setStyle(node, style, true, true);
this.root.appendChild(node);
},
-
- /**
+
+ /**
* function
*
* draw a rectangular geometry.
@@ -270,8 +262,8 @@
this._setStyle(node, style, true, true);
this.root.appendChild(node);
},
-
- /**
+
+ /**
* function
*
* draw a cirle geometry.
@@ -288,8 +280,8 @@
this._setStyle(node, style, true, true);
this.root.appendChild(node);
},
-
- /**
+
+ /**
* function
*
* draw a Curve geometry.
@@ -314,8 +306,8 @@
this._setStyle(node, style, false, true);
this.root.appendChild(node);
},
-
- /**
+
+ /**
* function
*
* draw a surface geometry.
@@ -344,22 +336,22 @@
this.root.appendChild(node);
},
- /**
+ /**
* function
*
* Use to set all the style attributes to a SVG node.
*
* @param node {SvgDomElement} an SVG element to decorate
* @param style {Style} a style to apply
- * @param isFilled {boolean}
- * @param isStroked {boolean}
+ * @param isFilled {boolean}
+ * @param isStroked {boolean}
*/
_setStyle: function(node, style, isFilled, isStroked) {
-
+
if (!node.renderStyle) {
node.renderStyle = style;
}
-
+
if (isFilled) {
node.setAttributeNS(null, "fill", style.fillColor);
node.setAttributeNS(null, "fill-opacity", style.fillOpacity);
@@ -374,7 +366,7 @@
} else {
node.setAttributeNS(null, "stroke", "none");
}
-
+
if (style.pointerEvents) {
node.setAttributeNS(null, "pointer-events", style.pointerEvents);
}
@@ -382,21 +374,18 @@
if (!parent) {
this.root.appendChild(node);
}
-
+
return node;
},
-
+
_getLenthFromResolutions: function(length, currentResolution, newResolution) {
return newResolution * (length / currentResolution);
},
-
- /**
+
+ /**
* function
*
* Manage SVG node.
- *
- * @param geometry {Geometry} a geometry to draw
- * @param style {Style} a style to use when drawing
*/
_nodeFactory: function(type, id) {
if ($(id)) {
@@ -411,10 +400,10 @@
node.setAttributeNS(null, "id", id);
}
}
-
+
return node;
},
-
+
/** @final @type String */
CLASS_NAME: "OpenLayers.Renderer.Svg"
-});
\ No newline at end of file
+});
More information about the Commits
mailing list