[OpenLayers-Commits] r5129 - in sandbox/camptocamp/text: examples lib/OpenLayers lib/OpenLayers/Renderer
commits at openlayers.org
commits at openlayers.org
Tue Nov 6 15:14:29 EST 2007
Author: pgiraud
Date: 2007-11-06 15:14:26 -0500 (Tue, 06 Nov 2007)
New Revision: 5129
Modified:
sandbox/camptocamp/text/examples/vector-features-with-text.html
sandbox/camptocamp/text/lib/OpenLayers/Renderer/SVG.js
sandbox/camptocamp/text/lib/OpenLayers/Renderer/VML.js
sandbox/camptocamp/text/lib/OpenLayers/Style.js
Log:
label style attribute now accepts literals and variables replaced by the corresponding feature's attribute values
Modified: sandbox/camptocamp/text/examples/vector-features-with-text.html
===================================================================
--- sandbox/camptocamp/text/examples/vector-features-with-text.html 2007-11-06 19:40:23 UTC (rev 5128)
+++ sandbox/camptocamp/text/examples/vector-features-with-text.html 2007-11-06 20:14:26 UTC (rev 5129)
@@ -16,35 +16,9 @@
var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
map.addLayer(layer);
-
- /*
- * Style with label
- */
- /*
- var label_style = {
- textStyle : {
- fontFamily: 'Helvetica',
- fontSize: '20',
- fontStyle: 'bold',
- fillColor: 'red'
- },
- textLayout: {
- horizontalAlignment: 'center'
- },
- label: 'City'
- }
- */
- var label_style = {
- fontFamily: 'Helvetica',
- fontSize: 20,
- fontWeight: 'bold',
- fillColor: '#FF0000',
- horizontalAlignment: 'center',
- label: 'City'
- }
-
- var style_with_label = {
+ var style_with_label = new OpenLayers.Style();
+ style_with_label.defaultStyle = {
strokeColor: "#00FF00",
strokeOpacity: 1,
strokeWidth: 3,
@@ -52,7 +26,9 @@
fillOpacity: 0.5,
pointRadius: 6,
pointerEvents: "visiblePainted",
- labelStyle : label_style
+ label : "name: {name}, age: {age}",
+ fontColor: "red",
+ fontWeight: "bold"
};
var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry");
@@ -60,6 +36,10 @@
// create a point feature
var point = new OpenLayers.Geometry.Point(-111.04, 45.68);
var pointFeature = new OpenLayers.Feature.Vector(point,null,style_with_label);
+ pointFeature.attributes = {
+ name: "toto",
+ age: 20
+ }
// create a polygon feature from a linear ring of points
var pointList = [];
@@ -67,20 +47,18 @@
var a = p * (2 * Math.PI) / 7;
var r = Math.random(1) + 1;
var newPoint = new OpenLayers.Geometry.Point(point.x + 5 + (r * Math.cos(a)),
- point.y + (r * Math.sin(a)));
+ point.y + 5 + (r * Math.sin(a)));
pointList.push(newPoint);
}
pointList.push(pointList[0]);
- var style_polygon = OpenLayers.Util.extend({}, style_with_label);
- style_polygon.labelStyle = OpenLayers.Util.extend({}, label_style);
- style_polygon.labelStyle.fillColor = "#0000FF";
- style_polygon.labelStyle.label = "Polygon with long text";
-
-
var linearRing = new OpenLayers.Geometry.LinearRing(pointList);
var polygonFeature = new OpenLayers.Feature.Vector(
- new OpenLayers.Geometry.Polygon([linearRing]),null,style_polygon);
+ new OpenLayers.Geometry.Polygon([linearRing]),null,style_with_label);
+ polygonFeature.attributes = {
+ name: "dude",
+ age: 21
+ }
map.addLayer(vectorLayer);
map.setCenter(new OpenLayers.LonLat(point.x, point.y), 5);
Modified: sandbox/camptocamp/text/lib/OpenLayers/Renderer/SVG.js
===================================================================
--- sandbox/camptocamp/text/lib/OpenLayers/Renderer/SVG.js 2007-11-06 19:40:23 UTC (rev 5128)
+++ sandbox/camptocamp/text/lib/OpenLayers/Renderer/SVG.js 2007-11-06 20:14:26 UTC (rev 5129)
@@ -248,8 +248,8 @@
node.setAttributeNS(null, "cursor", style.cursor);
}
- if (style.labelStyle) {
- this.drawText(node, style.labelStyle, geometry.getCentroid());
+ if (style.label) {
+ this.drawText(node, style, geometry.getCentroid());
}
},
@@ -535,8 +535,8 @@
label.setAttributeNS(null, "x", x);
label.setAttributeNS(null, "y", -y);
- if (style.fillColor) {
- label.setAttributeNS(null, "fill", style.fillColor);
+ if (style.fontColor) {
+ label.setAttributeNS(null, "fill", style.fontColor);
}
if (style.fontFamily) {
label.setAttributeNS(null, "font-family", style.fontFamily);
Modified: sandbox/camptocamp/text/lib/OpenLayers/Renderer/VML.js
===================================================================
--- sandbox/camptocamp/text/lib/OpenLayers/Renderer/VML.js 2007-11-06 19:40:23 UTC (rev 5128)
+++ sandbox/camptocamp/text/lib/OpenLayers/Renderer/VML.js 2007-11-06 20:14:26 UTC (rev 5129)
@@ -250,8 +250,8 @@
node.style.cursor = style.cursor;
}
- if (style.labelStyle) {
- this.drawText(node, style.labelStyle, geometry.getCentroid());
+ if (style.label) {
+ this.drawText(node, style, geometry.getCentroid());
}
},
@@ -589,8 +589,8 @@
var textbox = this.createNode("v:textbox");
var span = document.createElement('span');
- if (style.fillColor) {
- span.style.color = style.fillColor;
+ if (style.fontColor) {
+ span.style.color = style.fontColor;
}
if (style.fontFamily) {
span.style.fontFamily = style.fontFamily;
Modified: sandbox/camptocamp/text/lib/OpenLayers/Style.js
===================================================================
--- sandbox/camptocamp/text/lib/OpenLayers/Style.js 2007-11-06 19:40:23 UTC (rev 5128)
+++ sandbox/camptocamp/text/lib/OpenLayers/Style.js 2007-11-06 20:14:26 UTC (rev 5129)
@@ -142,6 +142,14 @@
OpenLayers.Util.extend(style, symbolizer);
}
}
+
+ if (style.label) {
+ var re = /\{(\w+)\}/g;
+
+ while (a = re.exec(style.label)) {
+ style.label = style.label.replace(a[0], feature.attributes[a[1]]);
+ }
+ }
style.hidden = !draw;
More information about the Commits
mailing list