Changeset 5896
- Timestamp:
- 01/25/08 18:13:57 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Control/SelectFeature.js
r5614 r5896 221 221 select: function(feature) { 222 222 // Store feature style for restoration later 223 if(feature.originalStyle == null) {223 if(feature.originalStyle != feature.style) { 224 224 feature.originalStyle = feature.style; 225 225 } 226 226 this.layer.selectedFeatures.push(feature); 227 feature.style = this.selectStyle; 227 228 var selectStyle = this.selectStyle; 229 230 if (feature.style.CLASS_NAME == "OpenLayers.Style") { 231 feature.style = feature.style.createStyle(feature); 232 } else { 233 feature.style = OpenLayers.Util.extend({}, feature.style); 234 } 235 if (selectStyle.CLASS_NAME == "OpenLayers.Style") { 236 selectStyle = selectStyle.createStyle(feature); 237 } 238 OpenLayers.Util.extend(feature.style, selectStyle); 239 228 240 this.layer.drawFeature(feature); 229 241 this.onSelect(feature); trunk/openlayers/tests/Control/test_SelectFeature.html
r4232 r5896 34 34 35 35 function test_Control_SelectFeature_select(t) { 36 t.plan( 2);36 t.plan(7); 37 37 var map = new OpenLayers.Map("map"); 38 38 var layer = new OpenLayers.Layer.Vector(); … … 46 46 control.unselect(feature); 47 47 t.eq(feature.style.strokeColor, OpenLayers.Feature.Vector.style['default'].strokeColor, "feature style is set back to old style"); 48 49 // Don't ever overwrite my feature style with undefined properties from the selectStyle 50 feature.style = {externalGraphic: "foo.png", pointRadius: 39}; 51 control.selectStyle.pointRadius = undefined; 52 control.select(feature); 53 t.eq(feature.style.pointRadius, 39, "undefined style property inherited from original feature style"); 54 control.unselect(feature); 55 56 // Ok, that one went well. But I'm sure you cannot handle OL.Style. 57 feature.style = new OpenLayers.Style({externalGraphic: "foo.png", pointRadius: 39}); 58 control.select(feature); 59 t.eq(feature.style.pointRadius, 39, "undefined style property inherited from original feature style object"); 60 control.unselect(feature); 61 62 // Wow, but using OL.Style as selectStyle will break you. 63 control.selectStyle = new OpenLayers.Style({strokeColor: "green"}); 64 control.select(feature); 65 t.eq(feature.style.strokeColor, "green", "style correct if both feature.style and selectStyle are OL.Style"); 66 control.unselect(feature); 67 68 // Not bad, not bad. And what if I set feature.style back to a style hash? 69 feature.style = layer.style; 70 control.select(feature); 71 t.eq(feature.style.strokeColor, "green", "style still correct with only selectStyle being OL.Style"); 72 control.unselect(feature); 73 t.eq(feature.style.strokeColor, OpenLayers.Feature.Vector.style["default"].strokeColor, "style set back to original correctly"); 48 74 } 49 75
