Pullup r2999:3087 for RC2.
svn merge trunk/openlayers/@2999 trunk/openlayers/@HEAD branches/openlayers/2.4/ git-svn-id: http://svn.openlayers.org/branches/openlayers/2.4@3088 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -13,7 +13,17 @@ OpenLayers.Renderer.SVG.prototype =
|
||||
|
||||
/** @type String */
|
||||
xmlns: "http://www.w3.org/2000/svg",
|
||||
|
||||
// Firefox has a limitation where values larger or smaller than about
|
||||
// 15000 in an SVG document lock the browser up. This works around it.
|
||||
/** @type Integer */
|
||||
maxPixel: 15000,
|
||||
|
||||
|
||||
/** @type Float
|
||||
@private */
|
||||
localResolution: null,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
@@ -46,6 +56,7 @@ OpenLayers.Renderer.SVG.prototype =
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Bounds} extent
|
||||
* @private
|
||||
*/
|
||||
setExtent: function(extent) {
|
||||
OpenLayers.Renderer.Elements.prototype.setExtent.apply(this,
|
||||
@@ -53,8 +64,33 @@ OpenLayers.Renderer.SVG.prototype =
|
||||
|
||||
var resolution = this.getResolution();
|
||||
|
||||
var extentString = extent.left / resolution + " " + -extent.top / resolution + " " +
|
||||
|
||||
// If the resolution has changed, start over changing the corner, because
|
||||
// the features will redraw.
|
||||
if (!this.localResolution || resolution != this.localResolution) {
|
||||
this.left = -extent.left / resolution;
|
||||
this.top = extent.top / resolution;
|
||||
}
|
||||
|
||||
|
||||
var left = 0;
|
||||
var top = 0;
|
||||
|
||||
// If the resolution has not changed, we already have features, and we need
|
||||
// to adjust the viewbox to fit them.
|
||||
if (this.localResolution && resolution == this.localResolution) {
|
||||
left = (this.left) - (-extent.left / resolution);
|
||||
top = (this.top) - (extent.top / resolution);
|
||||
}
|
||||
|
||||
// Store resolution for use later.
|
||||
this.localResolution = resolution;
|
||||
|
||||
// Set the viewbox -- the left/top will be pixels-dragged-since-res change,
|
||||
// the width/height will be pixels.
|
||||
var extentString = left + " " + top + " " +
|
||||
extent.getWidth() / resolution + " " + extent.getHeight() / resolution;
|
||||
//var extentString = extent.left / resolution + " " + -extent.top / resolution + " " +
|
||||
this.rendererRoot.setAttributeNS(null, "viewBox", extentString);
|
||||
},
|
||||
|
||||
@@ -64,6 +100,7 @@ OpenLayers.Renderer.SVG.prototype =
|
||||
* sets the size of the drawing surface
|
||||
*
|
||||
* @param size {OpenLayers.Size} the size of the drawing surface
|
||||
* @private
|
||||
*/
|
||||
setSize: function(size) {
|
||||
OpenLayers.Renderer.prototype.setSize.apply(this, arguments);
|
||||
@@ -80,6 +117,7 @@ OpenLayers.Renderer.SVG.prototype =
|
||||
*
|
||||
* @returns The corresponding node type for the specified geometry
|
||||
* @type String
|
||||
* @private
|
||||
*/
|
||||
getNodeType: function(geometry) {
|
||||
var nodeType = null;
|
||||
@@ -106,14 +144,7 @@ OpenLayers.Renderer.SVG.prototype =
|
||||
}
|
||||
return nodeType;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {DOMElement} node
|
||||
*/
|
||||
reprojectNode: function(node) {
|
||||
this.drawGeometryNode(node);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Use to set all the style attributes to a SVG node.
|
||||
*
|
||||
@@ -125,12 +156,13 @@ OpenLayers.Renderer.SVG.prototype =
|
||||
* @param {Object} options
|
||||
* @option isFilled {boolean}
|
||||
* @option isStroked {boolean}
|
||||
* @private
|
||||
*/
|
||||
setStyle: function(node, style, options) {
|
||||
style = style || node.olStyle;
|
||||
options = options || node.olOptions;
|
||||
style = style || node._style;
|
||||
options = options || node._options;
|
||||
|
||||
if (node.geometry.CLASS_NAME == "OpenLayers.Geometry.Point") {
|
||||
if (node._geometryClass == "OpenLayers.Geometry.Point") {
|
||||
node.setAttributeNS(null, "r", style.pointRadius);
|
||||
}
|
||||
|
||||
@@ -152,6 +184,10 @@ OpenLayers.Renderer.SVG.prototype =
|
||||
if (style.pointerEvents) {
|
||||
node.setAttributeNS(null, "pointer-events", style.pointerEvents);
|
||||
}
|
||||
|
||||
if (style.cursor) {
|
||||
node.setAttributeNS(null, "cursor", style.cursor);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -187,6 +223,7 @@ OpenLayers.Renderer.SVG.prototype =
|
||||
/**
|
||||
* @returns The specific render engine's root element
|
||||
* @type DOMElement
|
||||
* @private
|
||||
*/
|
||||
createRenderRoot: function() {
|
||||
var id = this.container.id + "_svgRoot";
|
||||
@@ -197,6 +234,7 @@ OpenLayers.Renderer.SVG.prototype =
|
||||
/**
|
||||
* @returns The main root element to which we'll add vectors
|
||||
* @type DOMElement
|
||||
* @private
|
||||
*/
|
||||
createRoot: function() {
|
||||
var id = this.container.id + "_root";
|
||||
@@ -219,6 +257,7 @@ OpenLayers.Renderer.SVG.prototype =
|
||||
/**
|
||||
* @param {DOMElement} node
|
||||
* @param {OpenLayers.Geometry} geometry
|
||||
* @private
|
||||
*/
|
||||
drawPoint: function(node, geometry) {
|
||||
this.drawCircle(node, geometry, 1);
|
||||
@@ -228,17 +267,32 @@ OpenLayers.Renderer.SVG.prototype =
|
||||
* @param {DOMElement} node
|
||||
* @param {OpenLayers.Geometry} geometry
|
||||
* @param {float} radius
|
||||
* @private
|
||||
*/
|
||||
drawCircle: function(node, geometry, radius) {
|
||||
var resolution = this.getResolution();
|
||||
node.setAttributeNS(null, "cx", geometry.x / resolution);
|
||||
node.setAttributeNS(null, "cy", geometry.y / resolution);
|
||||
node.setAttributeNS(null, "r", radius);
|
||||
var x = (geometry.x / resolution + this.left);
|
||||
var y = (geometry.y / resolution - this.top);
|
||||
var draw = true;
|
||||
if (x < -this.maxPixel || x > this.maxPixel) { draw = false; }
|
||||
if (y < -this.maxPixel || y > this.maxPixel) { draw = false; }
|
||||
|
||||
if (draw) {
|
||||
node.setAttributeNS(null, "cx", x);
|
||||
node.setAttributeNS(null, "cy", y);
|
||||
node.setAttributeNS(null, "r", radius);
|
||||
} else {
|
||||
node.setAttributeNS(null, "cx", "");
|
||||
node.setAttributeNS(null, "cy", "");
|
||||
node.setAttributeNS(null, "r", 0);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {DOMElement} node
|
||||
* @param {OpenLayers.Geometry} geometry
|
||||
* @private
|
||||
*/
|
||||
drawLineString: function(node, geometry) {
|
||||
node.setAttributeNS(null, "points", this.getComponentsString(geometry.components));
|
||||
@@ -247,6 +301,7 @@ OpenLayers.Renderer.SVG.prototype =
|
||||
/**
|
||||
* @param {DOMElement} node
|
||||
* @param {OpenLayers.Geometry} geometry
|
||||
* @private
|
||||
*/
|
||||
drawLinearRing: function(node, geometry) {
|
||||
node.setAttributeNS(null, "points", this.getComponentsString(geometry.components));
|
||||
@@ -255,80 +310,132 @@ OpenLayers.Renderer.SVG.prototype =
|
||||
/**
|
||||
* @param {DOMElement} node
|
||||
* @param {OpenLayers.Geometry} geometry
|
||||
* @private
|
||||
*/
|
||||
drawPolygon: function(node, geometry) {
|
||||
var d = "";
|
||||
var draw = true;
|
||||
for (var j = 0; j < geometry.components.length; j++) {
|
||||
var linearRing = geometry.components[j];
|
||||
d += " M";
|
||||
for (var i = 0; i < linearRing.components.length; i++) {
|
||||
d += " " + this.getShortString(linearRing.components[i]);
|
||||
var component = this.getShortString(linearRing.components[i])
|
||||
if (component) {
|
||||
d += " " + component;
|
||||
} else {
|
||||
draw = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
d += " z";
|
||||
|
||||
node.setAttributeNS(null, "d", d);
|
||||
node.setAttributeNS(null, "fill-rule", "evenodd");
|
||||
if (draw) {
|
||||
node.setAttributeNS(null, "d", d);
|
||||
node.setAttributeNS(null, "fill-rule", "evenodd");
|
||||
} else {
|
||||
node.setAttributeNS(null, "d", "");
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {DOMElement} node
|
||||
* @param {OpenLayers.Geometry} geometry
|
||||
* @private
|
||||
*/
|
||||
drawRectangle: function(node, geometry) {
|
||||
node.setAttributeNS(null, "x", geometry.x / resolution);
|
||||
node.setAttributeNS(null, "y", geometry.y / resolution);
|
||||
node.setAttributeNS(null, "width", geometry.width);
|
||||
node.setAttributeNS(null, "height", geometry.height);
|
||||
// This needs to be reworked
|
||||
var x = (geometry.x / resolution + this.left);
|
||||
var y = (geometry.y / resolution - this.top);
|
||||
var draw = true;
|
||||
if (x < -this.maxPixel || x > this.maxPixel) { draw = false; }
|
||||
if (y < -this.maxPixel || y > this.maxPixel) { draw = false; }
|
||||
if (draw) {
|
||||
node.setAttributeNS(null, "x", x);
|
||||
node.setAttributeNS(null, "y", y);
|
||||
node.setAttributeNS(null, "width", geometry.width);
|
||||
node.setAttributeNS(null, "height", geometry.height);
|
||||
} else {
|
||||
node.setAttributeNS(null, "x", "");
|
||||
node.setAttributeNS(null, "y", "");
|
||||
node.setAttributeNS(null, "width", 0);
|
||||
node.setAttributeNS(null, "height", 0);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @param {DOMElement} node
|
||||
* @param {OpenLayers.Geometry} geometry
|
||||
* @private
|
||||
*/
|
||||
drawCurve: function(node, geometry) {
|
||||
var d = null;
|
||||
var draw = true;
|
||||
for (var i = 0; i < geometry.components.length; i++) {
|
||||
if ((i%3) == 0 && (i/3) == 0) {
|
||||
d = "M " + this.getShortString(geometry.components[i]);
|
||||
var component = this.getShortString(geometry.components[i]);
|
||||
if (!component) { draw = false; }
|
||||
d = "M " + component;
|
||||
} else if ((i%3) == 1) {
|
||||
d += " C " + this.getShortString(geometry.components[i]);
|
||||
var component = this.getShortString(geometry.components[i]);
|
||||
if (!component) { draw = false; }
|
||||
d += " C " + component;
|
||||
} else {
|
||||
d += " " + this.getShortString(geometry.components[i]);
|
||||
var component = this.getShortString(geometry.components[i]);
|
||||
if (!component) { draw = false; }
|
||||
d += " " + component;
|
||||
}
|
||||
}
|
||||
node.setAttributeNS(null, "d", d);
|
||||
if (draw) {
|
||||
node.setAttributeNS(null, "d", d);
|
||||
} else {
|
||||
node.setAttributeNS(null, "d", "");
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {DOMElement} node
|
||||
* @param {OpenLayers.Geometry} geometry
|
||||
* @private
|
||||
*/
|
||||
drawSurface: function(node, geometry) {
|
||||
|
||||
// create the svg path string representation
|
||||
var d = null;
|
||||
var draw = true;
|
||||
for (var i = 0; i < geometry.components.length; i++) {
|
||||
if ((i%3) == 0 && (i/3) == 0) {
|
||||
d = "M " + this.getShortString(geometry.components[i]);
|
||||
var component = this.getShortString(geometry.components[i]);
|
||||
if (!component) { draw = false; }
|
||||
d = "M " + component;
|
||||
} else if ((i%3) == 1) {
|
||||
d += " C " + this.getShortString(geometry.components[i]);
|
||||
var component = this.getShortString(geometry.components[i]);
|
||||
if (!component) { draw = false; }
|
||||
d += " C " + component;
|
||||
} else {
|
||||
d += " " + this.getShortString(geometry.components[i]);
|
||||
var component = this.getShortString(geometry.components[i]);
|
||||
if (!component) { draw = false; }
|
||||
d += " " + component;
|
||||
}
|
||||
}
|
||||
d += " Z";
|
||||
node.setAttributeNS(null, "d", d);
|
||||
if (draw) {
|
||||
node.setAttributeNS(null, "d", d);
|
||||
} else {
|
||||
node.setAttributeNS(null, "d", "");
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Array} components array of points
|
||||
* @private
|
||||
*/
|
||||
getComponentsString: function(components) {
|
||||
var strings = [];
|
||||
for(var i = 0; i < components.length; i++) {
|
||||
strings.push(this.getShortString(components[i]));
|
||||
var component = this.getShortString(components[i]);
|
||||
if (!component) { return false; }
|
||||
strings.push(component);
|
||||
}
|
||||
return strings.join(",");
|
||||
},
|
||||
@@ -336,10 +443,16 @@ OpenLayers.Renderer.SVG.prototype =
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Geometry.Point} point
|
||||
* @private
|
||||
*/
|
||||
getShortString: function(point) {
|
||||
var resolution = this.getResolution();
|
||||
return point.x / resolution + "," + point.y / resolution;
|
||||
var x = (point.x / resolution + this.left);
|
||||
var y = (point.y / resolution - this.top);
|
||||
if (x < -this.maxPixel || x > this.maxPixel) { return false; }
|
||||
if (y < -this.maxPixel || y > this.maxPixel) { return false; }
|
||||
var string = x + "," + y;
|
||||
return string;
|
||||
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user