context can now be given as argument in StyleMap.addUniqueValueRules()

this, for example, allows user to access to properties that are not part of the feature attributes.
r=elemoine (closes #1548)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@7216 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
pgiraud
2008-05-19 13:34:35 +00:00
parent 34ff282397
commit 815e55888a
4 changed files with 77 additions and 2 deletions

View File

@@ -47,6 +47,42 @@
layer.addFeatures(features);
map.addLayer(layer);
// create 20 random features with a random state property.
var features = new Array(20);
var states = [
OpenLayers.State.UNKNOWN,
OpenLayers.State.UPDATE,
OpenLayers.State.DELETE,
OpenLayers.State.INSERT
];
for (var i=0; i<20; i++) {
features[i] = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(Math.random()*360-180, Math.random()*180-90)
);
features[i].state = states[parseInt(Math.random()*4)];
}
var context = function(feature) {
return feature;
}
var styleMap = new OpenLayers.StyleMap();
// create a lookup table with different symbolizers for the diffent
// state values
var lookup = {};
lookup[OpenLayers.State.UNKNOWN] = {fillColor: "green"};
lookup[OpenLayers.State.UPDATE] = {fillColor: "green"};
lookup[OpenLayers.State.DELETE] = {fillColor: "red"};
lookup[OpenLayers.State.INSERT] = {fillColor: "orange"};
styleMap.addUniqueValueRules("default", "state", lookup, context);
layer = new OpenLayers.Layer.Vector('Points', {
styleMap: styleMap
});
layer.addFeatures(features);
map.addLayer(layer);
}
</script>
</head>
@@ -56,7 +92,11 @@
<div id="tags"></div>
<p id="shortdesc">
Shows how to create a style based on unique feature attribute values.
Shows how to create a style based :
<ul>
<li>on unique feature attribute values (markers),</li>
<li>on feature state values (circles).</li>
</ul>
</p>
<div id="map" class="smallmap"></div>