"users should be able to customize the select style per feature": Created a !StyleMap class which stores all styles that are needed for a layer. Controls that need to render features differently can now just give a render intent (e.g. "default", "select" or "temporary") to the layer's drawFeature method, instead of having extra style informations like Control.!SelectFeature.selectStyle. Existing application that set layer.style or feature.style are still supported, but both of these style properties are now null by default. r=crschmidt,elemoine,tschaub (closes #1120)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@6240 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2008-02-12 23:05:47 +00:00
parent dd1f4d1fa9
commit c5dd8ada2c
19 changed files with 257 additions and 142 deletions

44
tests/test_StyleMap.html Normal file
View File

@@ -0,0 +1,44 @@
<html>
<head>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_StyleMap_constructor(t) {
t.plan(6);
var options = {'foo': 'bar'};
var styleMap = new OpenLayers.StyleMap(null, options);
t.ok(styleMap instanceof OpenLayers.StyleMap,
"new OpenLayers.StyleMap returns object" );
t.eq(styleMap.foo, "bar", "constructor sets options correctly");
var style = new OpenLayers.Style();
var styleMap = new OpenLayers.StyleMap(style);
t.eq(styleMap.styles["default"].defaultStyle.strokeColor, style.defaultStyle.strokeColor, "default style set correctly from style object");
var style = {strokeColor: "blue"};
var styleMap = new OpenLayers.StyleMap(style);
t.eq(styleMap.styles["default"].defaultStyle.strokeColor, "blue", "default style set correctly from style hash");
var style = {
"default": new OpenLayers.Style({strokeColor: "yellow"}),
"select": {strokeColor: "blue"}};
var styleMap = new OpenLayers.StyleMap(style);
t.eq(styleMap.styles["default"].defaultStyle.strokeColor, "yellow", "default style set correctly from a mixed hash of renderIntents");
t.eq(styleMap.styles["select"].defaultStyle.strokeColor, "blue", "select style set correctly from a mixed hash of renderIntents");
}
function test_StyleMap_destroy(t) {
t.plan(2);
var styleMap = new OpenLayers.StyleMap();
t.ok(styleMap.styles["default"], "Got a default style after initialisation");
styleMap.destroy();
t.ok(!styleMap.styles, "StyleMap styles successfully destroyed");
}
</script>
</head>
<body>
<div id="map" style="width:500px;height:500px"></div>
</body>
</html>