I have been pulling my hair out over this issue and am now wondering if it is a bug rather than something I am doing wrong.
The Problem: I have a vector layer that users can edit. Each feature on the vector layer has an attribute called "Status" and I am using a unique values renderer to style the features. The layer can contain point, line, and polygon geometries. I have successfully set the layer styling and features are styled according to their status attribute. However, when a user selects a feature to modify the geometry the editing handles are not displayed which means the user is unable to modify the geometry, but the style clearly changes to the edit style. Here are the relevant parts of my code to create the layer:
// Capture the styles for the default render intents of a Vector layer
var defaultSymboliser = OpenLayers.Util.applyDefaults({}, OpenLayers.Feature.Vector.style["default"]);
var selectSymboliser = OpenLayers.Util.applyDefaults({ strokeColor: "red", fillColor: "blue" }, OpenLayers.Feature.Vector.style["select"]);
var temporarySymboliser = OpenLayers.Util.applyDefaults({ strokeColor: "red", fillColor: "blue" }, OpenLayers.Feature.Vector.style["temporary"]);
var editLayerStyleMap = new OpenLayers.StyleMap(
{
'default': defaultSymboliser,
'select': selectSymboliser,
'temporary': temporarySymboliser
}
);
// Create a symboliser lookup that will be used to stye features in their default intent
var symbolisersLookup = {
'Draft': { fillColor: '#0000ff', fillOpacity: 0.4, strokeColor: '#0000ff', pointRadius: 6 },
'Submitted': { fillColor: '#00ff00', fillOpacity: 0.4, strokeColor: '#00ff00', pointRadius: 6 },
'Review': { fillColor: '#ff0000', fillOpacity: 0.4, strokeColor: '#ff0000', pointRadius: 6 },
'Processed': { fillColor: '#9900ff', fillOpacity: 0.4, strokeColor: '#9900ff', pointRadius: 6 }
};
// Add the symboliser and lookup rules to the StyleMap object, using the default intent
editLayerStyleMap.addUniqueValueRules('default', 'Status', symbolisersLookup);
editLayerRefreshStrategy = new OpenLayers.Strategy.Refresh({force: true});
editLayer = new OpenLayers.Layer.Vector("User Submitted Information", {
strategies: [new OpenLayers.Strategy.BBOX(), editLayerRefreshStrategy],
protocol: new OpenLayers.Protocol.HTTP({
url: "Services/UserSubmittedInformationHandler.ashx",
format: new OpenLayers.Format.GeoJSON()
}),
styleMap: editLayerStyleMap
});
mainMap.addLayer(editLayer);
If I comment out the line:
editLayerStyleMap.addUniqueValueRules('default', 'Status', symbolisersLookup);
Then the features are no longer styled according to their status value but the editing handles do now appear. So, is this an OpenLayers bug or have I not done something important that allows the select render intent to work correctly when a UniqueValueRules is applied?