added new graphicName symbolizer property, which allows to render well-known graphic symbols named "square", "cross", "x" and "triangle", in addition to the existing "circle". Thanks Tim for the tweaks and the example. r=tschaub,elemoine (closes #1398)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@7634 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -25,6 +25,13 @@ OpenLayers.Renderer.VML = OpenLayers.Class(OpenLayers.Renderer.Elements, {
|
||||
* {String} XML Namespace URN
|
||||
*/
|
||||
xmlns: "urn:schemas-microsoft-com:vml",
|
||||
|
||||
/**
|
||||
* Property: symbolCache
|
||||
* {DOMElement} node holding symbols. This hash is keyed by symbol name,
|
||||
* and each value is a hash with a "path" and an "extent" property.
|
||||
*/
|
||||
symbolCache: {},
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Renderer.VML
|
||||
@@ -123,7 +130,13 @@ OpenLayers.Renderer.VML = OpenLayers.Class(OpenLayers.Renderer.Elements, {
|
||||
var nodeType = null;
|
||||
switch (geometry.CLASS_NAME) {
|
||||
case "OpenLayers.Geometry.Point":
|
||||
nodeType = style.externalGraphic ? "olv:rect" : "olv:oval";
|
||||
if (style.externalGraphic) {
|
||||
nodeType = "olv:rect";
|
||||
} else if (this.isComplexSymbol(style.graphicName)) {
|
||||
nodeType = "olv:shape";
|
||||
} else {
|
||||
nodeType = "olv:oval";
|
||||
}
|
||||
break;
|
||||
case "OpenLayers.Geometry.Rectangle":
|
||||
nodeType = "olv:rect";
|
||||
@@ -156,6 +169,7 @@ OpenLayers.Renderer.VML = OpenLayers.Class(OpenLayers.Renderer.Elements, {
|
||||
setStyle: function(node, style, options, geometry) {
|
||||
style = style || node._style;
|
||||
options = options || node._options;
|
||||
var widthFactor = 1;
|
||||
|
||||
if (node._geometryClass == "OpenLayers.Geometry.Point") {
|
||||
if (style.externalGraphic) {
|
||||
@@ -179,7 +193,22 @@ OpenLayers.Renderer.VML = OpenLayers.Class(OpenLayers.Renderer.Elements, {
|
||||
// modify style/options for fill and stroke styling below
|
||||
style.fillColor = "none";
|
||||
options.isStroked = false;
|
||||
|
||||
} else if (this.isComplexSymbol(style.graphicName)) {
|
||||
var cache = this.importSymbol(style.graphicName);
|
||||
var symbolExtent = cache.extent;
|
||||
var width = symbolExtent.getWidth();
|
||||
var height = symbolExtent.getHeight();
|
||||
node.setAttribute("path", cache.path);
|
||||
node.setAttribute("coordorigin", symbolExtent.left + "," +
|
||||
symbolExtent.bottom);
|
||||
node.setAttribute("coordsize", width + "," + height);
|
||||
node.style.left = symbolExtent.left + "px";
|
||||
node.style.top = symbolExtent.bottom + "px";
|
||||
node.style.width = width + "px";
|
||||
node.style.height = height + "px";
|
||||
|
||||
this.drawCircle(node, geometry, style.pointRadius);
|
||||
node.style.flip = "y";
|
||||
} else {
|
||||
this.drawCircle(node, geometry, style.pointRadius);
|
||||
}
|
||||
@@ -217,22 +246,25 @@ OpenLayers.Renderer.VML = OpenLayers.Class(OpenLayers.Renderer.Elements, {
|
||||
if (!(style.graphicWidth && style.graphicHeight)) {
|
||||
fill.aspect = "atmost";
|
||||
}
|
||||
|
||||
// additional rendering for rotated graphics
|
||||
if (style.rotation) {
|
||||
this.graphicRotate(node, xOffset, yOffset);
|
||||
// make the fill fully transparent, because we now have
|
||||
// the graphic as imagedata element. We cannot just remove
|
||||
// the fill, because this is part of the hack described
|
||||
// in graphicRotate
|
||||
fill.setAttribute("opacity", 0);
|
||||
}
|
||||
}
|
||||
if (fill.parentNode != node) {
|
||||
node.appendChild(fill);
|
||||
}
|
||||
}
|
||||
|
||||
// additional rendering for rotated graphics or symbols
|
||||
if (style.rotation) {
|
||||
if (style.externalGraphic) {
|
||||
this.graphicRotate(node, xOffset, yOffset);
|
||||
// make the fill fully transparent, because we now have
|
||||
// the graphic as imagedata element. We cannot just remove
|
||||
// the fill, because this is part of the hack described
|
||||
// in graphicRotate
|
||||
fill.setAttribute("opacity", 0);
|
||||
} else {
|
||||
node.style.rotation = style.rotation;
|
||||
}
|
||||
}
|
||||
|
||||
// stroke
|
||||
if (options.isStroked) {
|
||||
@@ -694,6 +726,61 @@ OpenLayers.Renderer.VML = OpenLayers.Class(OpenLayers.Renderer.Elements, {
|
||||
|
||||
node.path = path.join("");
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: importSymbol
|
||||
* add a new symbol definition from the rendererer's symbol hash
|
||||
*
|
||||
* Parameters:
|
||||
* graphicName - {String} name of the symbol to import
|
||||
*
|
||||
* Returns:
|
||||
* {Object} - hash of {DOMElement} "symbol" and {Number} "size"
|
||||
*/
|
||||
importSymbol: function (graphicName) {
|
||||
var id = this.container.id + "-" + graphicName;
|
||||
|
||||
// check if symbol already exists in the cache
|
||||
var cache = this.symbolCache[id];
|
||||
if (cache) {
|
||||
return cache;
|
||||
}
|
||||
|
||||
var symbol = OpenLayers.Renderer.symbol[graphicName];
|
||||
if (!symbol) {
|
||||
throw new Error(graphicName + ' is not a valid symbol name');
|
||||
return;
|
||||
}
|
||||
|
||||
var symbolExtent = new OpenLayers.Bounds(
|
||||
Number.MAX_VALUE, Number.MAX_VALUE, 0, 0);
|
||||
|
||||
var pathitems = ["m"];
|
||||
for (var i=0; i<symbol.length; i=i+2) {
|
||||
x = symbol[i];
|
||||
y = symbol[i+1];
|
||||
symbolExtent.left = Math.min(symbolExtent.left, x);
|
||||
symbolExtent.bottom = Math.min(symbolExtent.bottom, y);
|
||||
symbolExtent.right = Math.max(symbolExtent.right, x);
|
||||
symbolExtent.top = Math.max(symbolExtent.top, y);
|
||||
|
||||
pathitems.push(x);
|
||||
pathitems.push(y);
|
||||
if (i == 0) {
|
||||
pathitems.push("l");
|
||||
}
|
||||
}
|
||||
pathitems.push("x e");
|
||||
var path = pathitems.join(" ");
|
||||
|
||||
cache = {
|
||||
path: path,
|
||||
extent: symbolExtent
|
||||
};
|
||||
this.symbolCache[id] = cache;
|
||||
|
||||
return cache;
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Renderer.VML"
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user