Ticket #1548: 1548_r1790_A0.patch
| File 1548_r1790_A0.patch, 4.9 kB (added by pgiraud, 8 months ago) |
|---|
-
tests/Rule.html
old new 13 13 t.eq(rule.foo, "bar", "constructor sets options correctly"); 14 14 t.eq(typeof rule.evaluate, "function", "rule has an evaluate function"); 15 15 } 16 17 function test_Rule_getContext(t) { 18 t.plan(2); 19 var rule, options; 20 21 var feature = { 22 attributes: { 23 'dude': 'hello' 24 }, 25 'foobar': 'world' 26 } 27 28 rule = new OpenLayers.Rule(); 29 var context = rule.getContext(feature); 30 t.eq(context.dude, "hello", "value returned by getContext is correct" 31 + " if no context is specified"); 32 33 var options = { 34 context: function(feature){ 35 return feature; 36 } 37 }; 38 rule = new OpenLayers.Rule(options); 39 var context = rule.getContext(feature); 40 t.eq(context.foobar, "world", "value returned by getContext is correct" 41 + " if a context is given in constructor options"); 42 } 16 43 17 44 function test_Rule_destroy(t) { 18 45 t.plan(1); -
lib/OpenLayers/StyleMap.js
old new 130 130 * rules for 131 131 * symbolizers - {Object} Hash of symbolizers, keyed by the desired 132 132 * property values 133 * context - {Object} An optional object with properties that 134 * symbolizers' property values should be evaluated 135 * against. If no context is specified, feature.attributes 136 * will be used 133 137 */ 134 addUniqueValueRules: function(renderIntent, property, symbolizers ) {138 addUniqueValueRules: function(renderIntent, property, symbolizers, context) { 135 139 var rules = []; 136 140 for (var value in symbolizers) { 137 141 rules.push(new OpenLayers.Rule({ 138 142 symbolizer: symbolizers[value], 143 context: context, 139 144 filter: new OpenLayers.Filter.Comparison({ 140 145 type: OpenLayers.Filter.Comparison.EQUAL_TO, 141 146 property: property, -
lib/OpenLayers/Rule.js
old new 173 173 if (!context) { 174 174 context = feature.attributes || feature.data; 175 175 } 176 if (typeof this.context == "function") { 177 context = this.context(feature); 178 } 176 179 return context; 177 180 }, 178 181 -
examples/styles-unique.html
old new 47 47 48 48 layer.addFeatures(features); 49 49 map.addLayer(layer); 50 51 // create 20 random features with a random state property. 52 var features = new Array(20); 53 var states = [ 54 OpenLayers.State.UNKNOWN, 55 OpenLayers.State.UPDATE, 56 OpenLayers.State.DELETE, 57 OpenLayers.State.INSERT 58 ]; 59 for (var i=0; i<20; i++) { 60 features[i] = new OpenLayers.Feature.Vector( 61 new OpenLayers.Geometry.Point(Math.random()*360-180, Math.random()*180-90) 62 ); 63 features[i].state = states[parseInt(Math.random()*4)]; 64 } 65 66 var context = function(feature) { 67 return feature; 68 } 69 var styleMap = new OpenLayers.StyleMap(); 70 71 // create a lookup table with different symbolizers for the diffent 72 // state values 73 var lookup = { 74 "Unknown": {fillColor: "green"}, 75 "Update": {fillColor: "blue"}, 76 "Delete": {fillColor: "red"}, 77 "Insert": {fillColor: "orange"} 78 } 79 80 styleMap.addUniqueValueRules("default", "state", lookup, context); 81 layer = new OpenLayers.Layer.Vector('Points', { 82 styleMap: styleMap 83 }); 84 85 layer.addFeatures(features); 86 map.addLayer(layer); 50 87 } 51 88 </script> 52 89 </head> … … 56 93 <div id="tags"></div> 57 94 58 95 <p id="shortdesc"> 59 Shows how to create a style based on unique feature attribute values. 96 Shows how to create a style based : 97 <ul> 98 <li>on unique feature attribute values (markers),</li> 99 <li>on feature state values (circles).</li> 100 </ul> 60 101 </p> 61 102 62 103 <div id="map" class="smallmap"></div>
