SLD maps minScaleDenominator and maxScaleDenominator to rule minScale and maxScale. r=tschaub (closes #1297)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@5964 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -28,9 +28,7 @@
|
|||||||
|
|
||||||
// create a property style that reads the externalGraphic url from
|
// create a property style that reads the externalGraphic url from
|
||||||
// the thumbail attribute of the rss item
|
// the thumbail attribute of the rss item
|
||||||
style = new OpenLayers.Style({
|
style = new OpenLayers.Style({externalGraphic: "${thumbnail}"});
|
||||||
externalGraphic: "${thumbnail}",
|
|
||||||
pointRadius: 20});
|
|
||||||
|
|
||||||
// create a rule with a point symbolizer that will make the thumbnail
|
// create a rule with a point symbolizer that will make the thumbnail
|
||||||
// larger if the title of the rss item conatins "powder"
|
// larger if the title of the rss item conatins "powder"
|
||||||
@@ -41,7 +39,11 @@
|
|||||||
symbolizer: {"Point": {pointRadius: 30}}});
|
symbolizer: {"Point": {pointRadius: 30}}});
|
||||||
rule.value2regex("*");
|
rule.value2regex("*");
|
||||||
|
|
||||||
style.addRules([rule]);
|
// If the above rule does not apply, use a smaller pointRadius.
|
||||||
|
var elseRule = new OpenLayers.Rule({
|
||||||
|
symbolizer: {"Point": {pointRadius: 20}}});
|
||||||
|
|
||||||
|
style.addRules([rule, elseRule]);
|
||||||
|
|
||||||
markerLayer = new OpenLayers.Layer.Vector("", {style: style});
|
markerLayer = new OpenLayers.Layer.Vector("", {style: style});
|
||||||
map.addLayer(markerLayer);
|
map.addLayer(markerLayer);
|
||||||
|
|||||||
@@ -51,6 +51,12 @@
|
|||||||
</sld:Stroke>
|
</sld:Stroke>
|
||||||
</sld:PolygonSymbolizer>
|
</sld:PolygonSymbolizer>
|
||||||
</sld:Rule>
|
</sld:Rule>
|
||||||
|
<sld:Rule>
|
||||||
|
<sld:Name>testRuleNameElse</sld:Name>
|
||||||
|
<sld:Title>title</sld:Title>
|
||||||
|
<sld:Abstract>Abstract</sld:Abstract>
|
||||||
|
<ogc:ElseFilter/>
|
||||||
|
</sld:Rule>
|
||||||
</sld:FeatureTypeStyle>
|
</sld:FeatureTypeStyle>
|
||||||
</sld:UserStyle>
|
</sld:UserStyle>
|
||||||
|
|
||||||
@@ -113,7 +119,12 @@
|
|||||||
</sld:Stroke>
|
</sld:Stroke>
|
||||||
</sld:PolygonSymbolizer>
|
</sld:PolygonSymbolizer>
|
||||||
</sld:Rule>
|
</sld:Rule>
|
||||||
|
<sld:Rule>
|
||||||
|
<sld:Name>testRuleNameHoverElse</sld:Name>
|
||||||
|
<sld:Title>title</sld:Title>
|
||||||
|
<sld:Abstract>Abstract</sld:Abstract>
|
||||||
|
<ogc:ElseFilter/>
|
||||||
|
</sld:Rule>
|
||||||
</sld:FeatureTypeStyle>
|
</sld:FeatureTypeStyle>
|
||||||
</sld:UserStyle>
|
</sld:UserStyle>
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ OpenLayers.Format.SLD = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
|
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options = options || {};
|
||||||
OpenLayers.Util.applyDefaults(options, {
|
OpenLayers.Util.applyDefaults(options, {
|
||||||
withNamedLayer: false,
|
withNamedLayer: false,
|
||||||
overrideDefaultStyleKey: true
|
overrideDefaultStyleKey: true
|
||||||
@@ -206,7 +207,7 @@ OpenLayers.Format.SLD = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
if (filter && filter.length > 0) {
|
if (filter && filter.length > 0) {
|
||||||
var rule = this.parseFilter(filter[0]);
|
var rule = this.parseFilter(filter[0]);
|
||||||
} else {
|
} else {
|
||||||
// rule applies to all features
|
// rule applies to all features (no filter or ElseFilter)
|
||||||
var rule = new OpenLayers.Rule();
|
var rule = new OpenLayers.Rule();
|
||||||
}
|
}
|
||||||
rule.name = name;
|
rule.name = name;
|
||||||
@@ -218,7 +219,8 @@ OpenLayers.Format.SLD = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
xmlNode, this.sldns, "MinScaleDenominator"
|
xmlNode, this.sldns, "MinScaleDenominator"
|
||||||
);
|
);
|
||||||
if (minScale && minScale.length > 0) {
|
if (minScale && minScale.length > 0) {
|
||||||
rule.minScale = parseFloat(this.getChildValue(minScale[0]));
|
rule.minScaleDenominator =
|
||||||
|
parseFloat(this.getChildValue(minScale[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaxScaleDenominator
|
// MaxScaleDenominator
|
||||||
@@ -226,7 +228,8 @@ OpenLayers.Format.SLD = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
xmlNode, this.sldns, "MaxScaleDenominator"
|
xmlNode, this.sldns, "MaxScaleDenominator"
|
||||||
);
|
);
|
||||||
if (maxScale && maxScale.length > 0) {
|
if (maxScale && maxScale.length > 0) {
|
||||||
rule.maxScale = parseFloat(this.getChildValue(maxScale[0]));
|
rule.maxScaleDenominator =
|
||||||
|
parseFloat(this.getChildValue(maxScale[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// STYLES
|
// STYLES
|
||||||
|
|||||||
@@ -28,20 +28,20 @@ OpenLayers.Rule = OpenLayers.Class({
|
|||||||
symbolizer: null,
|
symbolizer: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIProperty: minScale
|
* APIProperty: minScaleDenominator
|
||||||
* {Number} or {String} minimum scale at which to draw the feature.
|
* {Number} or {String} minimum scale at which to draw the feature.
|
||||||
* In the case of a String, this can be a combination of text and
|
* In the case of a String, this can be a combination of text and
|
||||||
* propertyNames in the form "literal ${propertyName}"
|
* propertyNames in the form "literal ${propertyName}"
|
||||||
*/
|
*/
|
||||||
minScale: null,
|
minScaleDenominator: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIProperty: maxScale
|
* APIProperty: maxScaleDenominator
|
||||||
* {Number} or {String} maximum scale at which to draw the feature.
|
* {Number} or {String} maximum scale at which to draw the feature.
|
||||||
* In the case of a String, this can be a combination of text and
|
* In the case of a String, this can be a combination of text and
|
||||||
* propertyNames in the form "literal ${propertyName}"
|
* propertyNames in the form "literal ${propertyName}"
|
||||||
*/
|
*/
|
||||||
maxScale: null,
|
maxScaleDenominator: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor: OpenLayers.Rule
|
* Constructor: OpenLayers.Rule
|
||||||
|
|||||||
+49
-21
@@ -107,47 +107,75 @@ OpenLayers.Style = OpenLayers.Class({
|
|||||||
* Returns:
|
* Returns:
|
||||||
* {<OpenLayers.Feature.Vector.style>} hash of feature styles
|
* {<OpenLayers.Feature.Vector.style>} hash of feature styles
|
||||||
*/
|
*/
|
||||||
createStyle: function(feature, baseStyle) {
|
createStyle: function(feature) {
|
||||||
if (!baseStyle) {
|
var style = OpenLayers.Util.extend({}, this.defaultStyle);
|
||||||
baseStyle = this.defaultStyle;
|
|
||||||
}
|
|
||||||
var style = OpenLayers.Util.extend({}, baseStyle);
|
|
||||||
|
|
||||||
var draw = true;
|
var rules = this.rules;
|
||||||
|
var draw = rules.length == 0 ? true : false;
|
||||||
|
|
||||||
for (var i=0; i<this.rules.length; i++) {
|
var rule;
|
||||||
|
for (var i=0; i<rules.length; i++) {
|
||||||
|
rule = rules[i];
|
||||||
// does the rule apply?
|
// does the rule apply?
|
||||||
var applies = this.rules[i].evaluate(feature);
|
var applies = rule.evaluate(feature);
|
||||||
if (applies) {
|
|
||||||
// check if within minScale/maxScale bounds
|
if (rule.minScaleDenominator || rule.maxScaleDenominator) {
|
||||||
var scale = feature.layer.map.getScale();
|
var scale = feature.layer.map.getScale();
|
||||||
if (this.rules[i].minScale) {
|
}
|
||||||
draw = scale > OpenLayers.Style.createLiteral(
|
|
||||||
this.rules[i].minScale, feature);
|
// check if within minScale/maxScale bounds
|
||||||
}
|
if (rule.minScaleDenominator) {
|
||||||
if (draw && this.rules[i].maxScale) {
|
applies = scale >= OpenLayers.Style.createLiteral(
|
||||||
draw = scale < OpenLayers.Style.createLiteral(
|
rule.minScaleDenominator, feature);
|
||||||
this.rules[i].maxScale, feature);
|
}
|
||||||
}
|
if (applies && rule.maxScaleDenominator) {
|
||||||
|
applies = scale < OpenLayers.Style.createLiteral(
|
||||||
|
rule.maxScaleDenominator, feature);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (draw && rule.CLASS_NAME == "OpenLayers.Rule") {
|
||||||
|
// apply plain rules only if no other applied (ElseFilter)
|
||||||
|
applies = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (applies) {
|
||||||
|
draw = true;
|
||||||
|
|
||||||
// determine which symbolizer (Point, Line, Polygon) to use
|
// determine which symbolizer (Point, Line, Polygon) to use
|
||||||
var symbolizerPrefix = feature.geometry ?
|
var symbolizerPrefix = feature.geometry ?
|
||||||
this.getSymbolizerPrefix(feature.geometry) :
|
this.getSymbolizerPrefix(feature.geometry) :
|
||||||
OpenLayers.Style.SYMBOLIZER_PREFIXES[0];
|
OpenLayers.Style.SYMBOLIZER_PREFIXES[0];
|
||||||
|
|
||||||
// now merge the style with the current style
|
// merge the style with the current style
|
||||||
var symbolizer = this.rules[i].symbolizer[symbolizerPrefix];
|
var symbolizer = this.rules[i].symbolizer[symbolizerPrefix];
|
||||||
OpenLayers.Util.extend(style, symbolizer);
|
OpenLayers.Util.extend(style, symbolizer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// calculate literals for all styles in the propertyStyles cache
|
||||||
|
this.createLiterals(style, feature);
|
||||||
style.display = draw ? "" : "none";
|
style.display = draw ? "" : "none";
|
||||||
|
|
||||||
// calculate literals for all styles in the propertyStyles cache
|
return style;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: createLiterals
|
||||||
|
* creates literals for all style properties that have an entry in
|
||||||
|
* <this.propertyStyles>.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* style - {Object} style to create literals for. Will be modified
|
||||||
|
* inline.
|
||||||
|
* feature - {<OpenLayers.Feature.Vector>} feature to take properties from
|
||||||
|
*
|
||||||
|
* Returns;
|
||||||
|
* {Object} the modified style
|
||||||
|
*/
|
||||||
|
createLiterals: function(style, feature) {
|
||||||
for (var i in this.propertyStyles) {
|
for (var i in this.propertyStyles) {
|
||||||
style[i] = OpenLayers.Style.createLiteral(style[i], feature);
|
style[i] = OpenLayers.Style.createLiteral(style[i], feature);
|
||||||
}
|
}
|
||||||
|
|
||||||
return style;
|
return style;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
+31
-8
@@ -15,7 +15,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_Style_create(t) {
|
function test_Style_create(t) {
|
||||||
t.plan(5);
|
t.plan(10);
|
||||||
|
|
||||||
var map = new OpenLayers.Map("map");
|
var map = new OpenLayers.Map("map");
|
||||||
|
|
||||||
@@ -27,11 +27,21 @@
|
|||||||
|
|
||||||
var style = new OpenLayers.Style(baseStyle);
|
var style = new OpenLayers.Style(baseStyle);
|
||||||
|
|
||||||
var rule = new OpenLayers.Rule.FeatureId({
|
var rule1 = new OpenLayers.Rule.FeatureId({
|
||||||
fids: ["1"],
|
fids: ["1"],
|
||||||
symbolizer: {"Point": {fillColor: "green"}},
|
symbolizer: {"Point": {fillColor: "green"}},
|
||||||
maxScale: 2000000});
|
maxScaleDenominator: 500000});
|
||||||
style.addRules([rule]);
|
var rule2 = new OpenLayers.Rule.FeatureId({
|
||||||
|
fids: ["1"],
|
||||||
|
symbolizer: {"Point": {fillColor: "yellow"}},
|
||||||
|
minScaleDenominator: 500000,
|
||||||
|
maxScaleDenominator: 1000000});
|
||||||
|
var rule3 = new OpenLayers.Rule.FeatureId({
|
||||||
|
fids: ["1"],
|
||||||
|
symbolizer: {"Point": {fillColor: "red"}},
|
||||||
|
minScaleDenominator: 1000000,
|
||||||
|
maxScaleDenominator: 2500000});
|
||||||
|
style.addRules([rule1, rule2, rule3]);
|
||||||
|
|
||||||
var feature = new OpenLayers.Feature.Vector(
|
var feature = new OpenLayers.Feature.Vector(
|
||||||
new OpenLayers.Geometry.Point(3,5),
|
new OpenLayers.Geometry.Point(3,5),
|
||||||
@@ -45,24 +55,37 @@
|
|||||||
map.addLayer(layer);
|
map.addLayer(layer);
|
||||||
map.setBaseLayer(layer);
|
map.setBaseLayer(layer);
|
||||||
|
|
||||||
map.setCenter(new OpenLayers.LonLat(3,5), 8);
|
map.setCenter(new OpenLayers.LonLat(3,5), 10);
|
||||||
// at this scale, the feature should be visible
|
|
||||||
|
// at this scale, the feature should be green
|
||||||
var createdStyle = style.createStyle(feature);
|
var createdStyle = style.createStyle(feature);
|
||||||
t.eq(createdStyle.externalGraphic, "barbar.png", "Calculated property style correctly.");
|
t.eq(createdStyle.externalGraphic, "barbar.png", "Calculated property style correctly.");
|
||||||
t.eq(createdStyle.display, "", "Feature is visible at scale "+map.getScale());
|
t.eq(createdStyle.display, "", "Feature is visible at scale "+map.getScale());
|
||||||
|
t.eq(createdStyle.fillColor, "green", "Point symbolizer from rule applied correctly.");
|
||||||
|
|
||||||
|
map.setCenter(new OpenLayers.LonLat(3,5), 9);
|
||||||
|
// at this scale, the feature should be red
|
||||||
|
createdStyle = style.createStyle(feature);
|
||||||
|
t.eq(createdStyle.display, "", "Feature is visible at scale "+map.getScale());
|
||||||
|
t.eq(createdStyle.fillColor, "yellow", "Point symbolizer from rule applied correctly.");
|
||||||
|
|
||||||
|
map.setCenter(new OpenLayers.LonLat(3,5), 8);
|
||||||
|
// at this scale, the feature should be yellow
|
||||||
|
createdStyle = style.createStyle(feature);
|
||||||
|
t.eq(createdStyle.display, "", "Feature is visible at scale "+map.getScale());
|
||||||
|
t.eq(createdStyle.fillColor, "red", "Point symbolizer from rule applied correctly.");
|
||||||
|
|
||||||
map.setCenter(new OpenLayers.LonLat(3,5), 7);
|
map.setCenter(new OpenLayers.LonLat(3,5), 7);
|
||||||
// at this scale, the feature should be invisible
|
// at this scale, the feature should be invisible
|
||||||
createdStyle = style.createStyle(feature);
|
createdStyle = style.createStyle(feature);
|
||||||
t.eq(createdStyle.display, "none", "Feature is invisible at scale "+map.getScale());
|
t.eq(createdStyle.display, "none", "Feature is invisible at scale "+map.getScale());
|
||||||
t.eq(createdStyle.fillColor, "green", "Point symbolizer from rule for fid=\"1\" applied correctly.");
|
t.eq(createdStyle.fillColor, baseStyle.fillColor, "Point symbolizer from base style applied correctly.");
|
||||||
|
|
||||||
feature.fid = "2";
|
feature.fid = "2";
|
||||||
// now the rule should not apply
|
// now the rule should not apply
|
||||||
|
|
||||||
createdStyle = style.createStyle(feature);
|
createdStyle = style.createStyle(feature);
|
||||||
t.eq(createdStyle.fillColor, baseStyle.fillColor, "Correct style for rule that does not apply to fid=\"2\".");
|
t.eq(createdStyle.fillColor, baseStyle.fillColor, "Correct style for rule that does not apply to fid=\"2\".");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_Style_destroy(t) {
|
function test_Style_destroy(t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user