SelectFeature and OpenLayers.Feature.Vector.style["select"]: changed Control.SelectFeature to inherit properties that are not set in selectStyle from feature.style. r=tschaub (closes #1260)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@5896 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -220,11 +220,23 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
*/
|
*/
|
||||||
select: function(feature) {
|
select: function(feature) {
|
||||||
// Store feature style for restoration later
|
// Store feature style for restoration later
|
||||||
if(feature.originalStyle == null) {
|
if(feature.originalStyle != feature.style) {
|
||||||
feature.originalStyle = feature.style;
|
feature.originalStyle = feature.style;
|
||||||
}
|
}
|
||||||
this.layer.selectedFeatures.push(feature);
|
this.layer.selectedFeatures.push(feature);
|
||||||
feature.style = this.selectStyle;
|
|
||||||
|
var selectStyle = this.selectStyle;
|
||||||
|
|
||||||
|
if (feature.style.CLASS_NAME == "OpenLayers.Style") {
|
||||||
|
feature.style = feature.style.createStyle(feature);
|
||||||
|
} else {
|
||||||
|
feature.style = OpenLayers.Util.extend({}, feature.style);
|
||||||
|
}
|
||||||
|
if (selectStyle.CLASS_NAME == "OpenLayers.Style") {
|
||||||
|
selectStyle = selectStyle.createStyle(feature);
|
||||||
|
}
|
||||||
|
OpenLayers.Util.extend(feature.style, selectStyle);
|
||||||
|
|
||||||
this.layer.drawFeature(feature);
|
this.layer.drawFeature(feature);
|
||||||
this.onSelect(feature);
|
this.onSelect(feature);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_Control_SelectFeature_select(t) {
|
function test_Control_SelectFeature_select(t) {
|
||||||
t.plan(2);
|
t.plan(7);
|
||||||
var map = new OpenLayers.Map("map");
|
var map = new OpenLayers.Map("map");
|
||||||
var layer = new OpenLayers.Layer.Vector();
|
var layer = new OpenLayers.Layer.Vector();
|
||||||
map.addLayer(layer);
|
map.addLayer(layer);
|
||||||
@@ -45,6 +45,32 @@
|
|||||||
t.eq(feature.style.strokeColor, OpenLayers.Feature.Vector.style['select'].strokeColor, "feature style is set to select style");
|
t.eq(feature.style.strokeColor, OpenLayers.Feature.Vector.style['select'].strokeColor, "feature style is set to select style");
|
||||||
control.unselect(feature);
|
control.unselect(feature);
|
||||||
t.eq(feature.style.strokeColor, OpenLayers.Feature.Vector.style['default'].strokeColor, "feature style is set back to old style");
|
t.eq(feature.style.strokeColor, OpenLayers.Feature.Vector.style['default'].strokeColor, "feature style is set back to old style");
|
||||||
|
|
||||||
|
// Don't ever overwrite my feature style with undefined properties from the selectStyle
|
||||||
|
feature.style = {externalGraphic: "foo.png", pointRadius: 39};
|
||||||
|
control.selectStyle.pointRadius = undefined;
|
||||||
|
control.select(feature);
|
||||||
|
t.eq(feature.style.pointRadius, 39, "undefined style property inherited from original feature style");
|
||||||
|
control.unselect(feature);
|
||||||
|
|
||||||
|
// Ok, that one went well. But I'm sure you cannot handle OL.Style.
|
||||||
|
feature.style = new OpenLayers.Style({externalGraphic: "foo.png", pointRadius: 39});
|
||||||
|
control.select(feature);
|
||||||
|
t.eq(feature.style.pointRadius, 39, "undefined style property inherited from original feature style object");
|
||||||
|
control.unselect(feature);
|
||||||
|
|
||||||
|
// Wow, but using OL.Style as selectStyle will break you.
|
||||||
|
control.selectStyle = new OpenLayers.Style({strokeColor: "green"});
|
||||||
|
control.select(feature);
|
||||||
|
t.eq(feature.style.strokeColor, "green", "style correct if both feature.style and selectStyle are OL.Style");
|
||||||
|
control.unselect(feature);
|
||||||
|
|
||||||
|
// Not bad, not bad. And what if I set feature.style back to a style hash?
|
||||||
|
feature.style = layer.style;
|
||||||
|
control.select(feature);
|
||||||
|
t.eq(feature.style.strokeColor, "green", "style still correct with only selectStyle being OL.Style");
|
||||||
|
control.unselect(feature);
|
||||||
|
t.eq(feature.style.strokeColor, OpenLayers.Feature.Vector.style["default"].strokeColor, "style set back to original correctly");
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_Control_SelectFeature_activate(t) {
|
function test_Control_SelectFeature_activate(t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user