Add support to the vector layer to visualize point geometries with images. This

support was added, tested, and documented by Andreas Hocevar, and I want to
thank him for the work he put into this patch. It looks pretty great. (This
is from ticket #736.)


git-svn-id: http://svn.openlayers.org/trunk/openlayers@3729 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-07-13 13:31:40 +00:00
parent 4f70df0029
commit 8e1eb78c26
4 changed files with 221 additions and 6 deletions

View File

@@ -183,7 +183,42 @@ OpenLayers.Renderer.SVG.prototype =
options = options || node._options;
if (node._geometryClass == "OpenLayers.Geometry.Point") {
node.setAttributeNS(null, "r", style.pointRadius);
if (style.externalGraphic) {
// remove old node
var id = node.getAttributeNS(null, "id");
var x = node.getAttributeNS(null, "cx");
var y = node.getAttributeNS(null, "cy");
var _featureId = node._featureId;
var _geometryClass = node._geometryClass;
var _style = node._style;
this.root.removeChild(node);
// create new image node
var node = this.createNode("image", id);
node._featureId = _featureId;
node._geometryClass = _geometryClass;
node._style = _style;
this.root.appendChild(node);
// now style the new node
if (style.graphicWidth && style.graphicHeight) {
node.setAttributeNS(null, "preserveAspectRatio", "none");
}
var width = style.graphicWidth || style.graphicHeight;
var height = style.graphicHeight || style.graphicWidth;
width = width ? width : style.pointRadius*2;
height = height ? height : style.pointRadius*2;
node.setAttributeNS(null, "x", x-(.5*width).toFixed());
node.setAttributeNS(null, "y", -y-(.5*height).toFixed());
node.setAttributeNS(null, "width", width);
node.setAttributeNS(null, "height", height);
node.setAttributeNS("http://www.w3.org/1999/xlink", "href", style.externalGraphic);
node.setAttributeNS(null, "transform", "scale(1,-1)");
node.setAttributeNS(null, "style", "opacity: "+style.fillOpacity);
} else {
node.setAttributeNS(null, "r", style.pointRadius);
}
}
if (options.isFilled) {

View File

@@ -153,7 +153,49 @@ OpenLayers.Renderer.VML.prototype =
options = options || node._options;
if (node._geometryClass == "OpenLayers.Geometry.Point") {
this.drawCircle(node, geometry, style.pointRadius);
if (style.externalGraphic) {
// remove old node
var id = node.id;
var _featureId = node._featureId;
var _geometryClass = node._geometryClass;
var _style = node._style;
this.root.removeChild(node);
// create new image node
var node = this.createNode("v:rect", id);
var fill = this.createNode("v:fill", id+"_image");
node.appendChild(fill);
node._featureId = _featureId;
node._geometryClass = _geometryClass;
node._style = _style;
this.root.appendChild(node);
fill.src = style.externalGraphic;
fill.type = "frame";
node.style.flip = "y";
if (!(style.graphicWidth && style.graphicHeight)) {
fill.aspect = "atmost";
}
// now style the new node
var width = style.graphicWidth || style.graphicHeight;
var height = style.graphicHeight || style.graphicWidth;
width = width ? width : style.pointRadius*2;
height = height ? height : style.pointRadius*2;
var resolution = this.getResolution();
node.style.left = (geometry.x/resolution-.5*width).toFixed();
node.style.top = (geometry.y/resolution-.5*height).toFixed();
node.style.width = width;
node.style.height = height;
// modify fill style for rect styling below
style.fillColor = "none";
style.strokeColor = "none";
} else {
this.drawCircle(node, geometry, style.pointRadius);
}
}
//fill
@@ -170,7 +212,9 @@ OpenLayers.Renderer.VML.prototype =
fill = this.createNode('v:fill', node.id + "_fill");
node.appendChild(fill);
}
fill.setAttribute("opacity", style.fillOpacity);
if (style.fillOpacity) {
fill.setAttribute("opacity", style.fillOpacity);
}
}