"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:
@@ -31,6 +31,9 @@
|
||||
// the thumbail attribute of the rss item
|
||||
style = new OpenLayers.Style({externalGraphic: "${thumbnail}"});
|
||||
|
||||
// make the thumbnails larger when we select them
|
||||
selectStyle = new OpenLayers.Style({pointRadius: 35});
|
||||
|
||||
// create a rule with a point symbolizer that will make the thumbnail
|
||||
// larger if the title of the rss item conatins "powder"
|
||||
var rule = new OpenLayers.Rule.Comparison({
|
||||
@@ -47,12 +50,13 @@
|
||||
|
||||
style.addRules([rule, elseRule]);
|
||||
|
||||
markerLayer = new OpenLayers.Layer.Vector("", {style: style});
|
||||
markerLayer = new OpenLayers.Layer.Vector("", {styleMap: new OpenLayers.StyleMap({
|
||||
"default": style,
|
||||
"select": selectStyle})});
|
||||
map.addLayer(markerLayer);
|
||||
|
||||
// control that will show a popup when clicking on a thumbnail
|
||||
var popupControl = new OpenLayers.Control.SelectFeature(markerLayer, {
|
||||
selectStyle: style,
|
||||
onSelect: function(feature) {
|
||||
var pos = feature.geometry;
|
||||
if (popup) {
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
map.addLayer(wms);
|
||||
|
||||
wfs = new OpenLayers.Layer.WFS("Minnesota Streams (WFS)", wfs_url, {'typename':'streams'}, {ratio:1.25, minZoomLevel:4});
|
||||
wfs = new OpenLayers.Layer.WFS("Minnesota Streams (WFS)", wfs_url, {'typename':'streams'}, {ratio:1.25, minZoomLevel:4, style: OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default'])});
|
||||
|
||||
// preFeatureInsert can be used to set style before the feature is drawn
|
||||
wfs.preFeatureInsert= function(feature) { feature.style.strokeWidth="3"; feature.style.strokeColor="blue";
|
||||
@@ -57,7 +57,7 @@
|
||||
map.addLayer(pwfs);
|
||||
|
||||
rstyle = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
|
||||
OpenLayers.Util.extend(rstyle, {'strokeColor': 'white', strokeWIdth: "4"});
|
||||
OpenLayers.Util.extend(rstyle, {'strokeColor': 'white', strokeWidth: "4"});
|
||||
rwfs = new OpenLayers.Layer.WFS("Minnesota Roads (WFS)", wfs_url, {'typename':'roads'},
|
||||
{ratio:1.25, minZoomLevel:7, extractAttributes: true, style:rstyle});
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
gml.loadGML();
|
||||
}
|
||||
function style_osm_feature(feature) {
|
||||
feature.style.fill = "black";
|
||||
feature.style = OpenLayers.Util.extend({'fill':'black'}, OpenLayers.Feature.Vector.style['default']);
|
||||
if (feature.attributes.highway == "motorway") {
|
||||
feature.style.strokeColor = "blue";
|
||||
feature.style.strokeWidth = 5;
|
||||
|
||||
@@ -32,41 +32,33 @@
|
||||
|
||||
styles = sld[1];
|
||||
|
||||
waterStyle = styles["WaterBodies"];
|
||||
// for the hover style, we do not want to use the SLD default as
|
||||
// base style
|
||||
styles["WaterBodies"]["Hover Styler"].defaultStyle = OpenLayers.Util.extend({},
|
||||
OpenLayers.Feature.Vector.style["select"]);
|
||||
|
||||
gmlLayers = [
|
||||
// use the sld UserStyle named "Default Styler"
|
||||
new OpenLayers.Layer.GML("StateBoundaries",
|
||||
"tasmania/TasmaniaStateBoundaries.xml", {
|
||||
style: waterStyle["default"]}),
|
||||
styleMap: new OpenLayers.StyleMap(styles["WaterBodies"])}),
|
||||
new OpenLayers.Layer.GML("Roads",
|
||||
"tasmania/TasmaniaRoads.xml", {
|
||||
style: waterStyle["default"]}),
|
||||
styleMap: new OpenLayers.StyleMap(styles["Roads"])}),
|
||||
new OpenLayers.Layer.GML("WaterBodies",
|
||||
"tasmania/TasmaniaWaterBodies.xml", {
|
||||
style: waterStyle["default"]}),
|
||||
styleMap: new OpenLayers.StyleMap(styles["WaterBodies"])}),
|
||||
new OpenLayers.Layer.GML("Cities",
|
||||
"tasmania/TasmaniaCities.xml", {
|
||||
style: waterStyle["default"]})];
|
||||
styleMap: new OpenLayers.StyleMap(styles["Cities"])})];
|
||||
|
||||
// add the first layer with the style passed to the constructor
|
||||
map.addLayer(gmlLayers[0]);
|
||||
// add the other layers after setting the style using the
|
||||
// setStyle() method, which will pick the correct default style
|
||||
// from the styles hash we got back from
|
||||
// OpenLayers.Format.SLD.read()
|
||||
for (var i=1; i<gmlLayers.length; i++) {
|
||||
gmlLayers[i].style = styles[gmlLayers[i].name]["default"];
|
||||
map.addLayer(gmlLayers[i]);
|
||||
gmlLayers[i].redraw();
|
||||
for (var i=0; i<gmlLayers.length; i++) {
|
||||
map.addLayer(gmlLayers[i]);
|
||||
}
|
||||
|
||||
// SLD can also be used for the SelectFeature control
|
||||
waterStyle["Hover Styler"].defaultStyle =
|
||||
OpenLayers.Feature.Vector.style["select"];
|
||||
hover = new OpenLayers.Control.SelectFeature(gmlLayers[2], {
|
||||
selectStyle: waterStyle["Hover Styler"],
|
||||
hover: true
|
||||
hover: true,
|
||||
renderIntent: "Hover Styler"
|
||||
});
|
||||
map.addControl(hover);
|
||||
hover.activate();
|
||||
@@ -74,11 +66,8 @@
|
||||
|
||||
// set a new style when the radio button changes
|
||||
function setStyle(styleName) {
|
||||
gmlLayers[2].styleMap.styles["default"] = styles["WaterBodies"][styleName];
|
||||
// change the style of the features of the WaterBodies layer
|
||||
var features = gmlLayers[2].features;
|
||||
for (var i=0; i<features.length; i++) {
|
||||
features[i].style = waterStyle[styleName];
|
||||
}
|
||||
gmlLayers[2].redraw();
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
df = new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path, {handlerOptions: {'freehand': false}, 'displayClass': 'olControlDrawFeaturePath'});
|
||||
df.featureAdded = function(feature) {
|
||||
feature.state = OpenLayers.State.INSERT;
|
||||
feature.style['strokeColor'] = "#ff0000";
|
||||
feature.style = OpenLayers.Util.extend({'strokeColor': '#ff0000'}, OpenLayers.Feature.Vector.style['default']);
|
||||
feature.layer.drawFeature(feature);
|
||||
}
|
||||
p.addControls([ new OpenLayers.Control.Navigation(), df ]);
|
||||
|
||||
Reference in New Issue
Block a user