Add more changes to the halo functionality, introduce SLD defaults for symbolizers conform the SLD spec
This commit is contained in:
committed by
Bart van den Eijnden
parent
924e9c6fce
commit
9a6c1feddc
@@ -89,6 +89,8 @@ ol.parser.ogc.SLD_v1 = function() {
|
|||||||
'TextSymbolizer': function(node, rule) {
|
'TextSymbolizer': function(node, rule) {
|
||||||
var config = {};
|
var config = {};
|
||||||
this.readChildNodes(node, config);
|
this.readChildNodes(node, config);
|
||||||
|
config.color = config.fill.fillColor;
|
||||||
|
delete config.fill;
|
||||||
config.zIndex = this.featureTypeCounter;
|
config.zIndex = this.featureTypeCounter;
|
||||||
rule.symbolizers.push(
|
rule.symbolizers.push(
|
||||||
new ol.style.Text(/** @type {ol.style.TextOptions} */(config))
|
new ol.style.Text(/** @type {ol.style.TextOptions} */(config))
|
||||||
@@ -182,18 +184,24 @@ ol.parser.ogc.SLD_v1 = function() {
|
|||||||
this.readChildNodes(node, symbolizer);
|
this.readChildNodes(node, symbolizer);
|
||||||
},
|
},
|
||||||
'Halo': function(node, symbolizer) {
|
'Halo': function(node, symbolizer) {
|
||||||
// halo has a fill, so send fresh object
|
|
||||||
var obj = {};
|
var obj = {};
|
||||||
this.readChildNodes(node, obj);
|
this.readChildNodes(node, obj);
|
||||||
symbolizer.haloRadius = obj.haloRadius;
|
symbolizer.stroke = new ol.style.Stroke({
|
||||||
symbolizer.haloColor = obj['fillColor'];
|
color: goog.isDef(obj.fill.fillColor) ? obj.fill.fillColor :
|
||||||
symbolizer.haloOpacity = obj['fillOpacity'];
|
ol.parser.ogc.SLD_v1.defaults_.haloColor,
|
||||||
|
width: goog.isDef(obj.haloRadius) ? obj.haloRadius * 2 :
|
||||||
|
ol.parser.ogc.SLD_v1.defaults_.haloRadius,
|
||||||
|
opacity: goog.isDef(obj.fill.fillOpacity) ? obj.fill.fillOpacity :
|
||||||
|
ol.parser.ogc.SLD_v1.defaults_.haloOpacity
|
||||||
|
});
|
||||||
},
|
},
|
||||||
'Radius': function(node, symbolizer) {
|
'Radius': function(node, symbolizer) {
|
||||||
var ogcreaders = this.readers['http://www.opengis.net/ogc'];
|
var ogcreaders = this.readers['http://www.opengis.net/ogc'];
|
||||||
var radius = ogcreaders._expression.call(this, node);
|
var radius = ogcreaders._expression.call(this, node);
|
||||||
|
goog.asserts.assertInstanceof(radius, ol.expr.Literal,
|
||||||
|
'radius expected to be an ol.expr.Literal');
|
||||||
if (goog.isDef(radius)) {
|
if (goog.isDef(radius)) {
|
||||||
symbolizer.haloRadius = radius;
|
symbolizer.haloRadius = radius.getValue();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'RasterSymbolizer': function(node, rule) {
|
'RasterSymbolizer': function(node, rule) {
|
||||||
@@ -238,8 +246,10 @@ ol.parser.ogc.SLD_v1 = function() {
|
|||||||
config.zIndex = this.featureTypeCounter;
|
config.zIndex = this.featureTypeCounter;
|
||||||
if (goog.isDef(config.fill)) {
|
if (goog.isDef(config.fill)) {
|
||||||
var fill = {
|
var fill = {
|
||||||
color: config.fill.fillColor,
|
color: config.fill.fillColor.getValue(),
|
||||||
opacity: config.fill.fillOpacity
|
opacity: goog.isDef(config.fill.fillOpacity) ?
|
||||||
|
config.fill.fillOpacity :
|
||||||
|
ol.parser.ogc.SLD_v1.defaults_.fillOpacity
|
||||||
};
|
};
|
||||||
rule.symbolizers.push(
|
rule.symbolizers.push(
|
||||||
new ol.style.Fill(fill)
|
new ol.style.Fill(fill)
|
||||||
@@ -248,9 +258,13 @@ ol.parser.ogc.SLD_v1 = function() {
|
|||||||
}
|
}
|
||||||
if (goog.isDef(config.stroke)) {
|
if (goog.isDef(config.stroke)) {
|
||||||
var stroke = {
|
var stroke = {
|
||||||
color: config.stroke.strokeColor,
|
color: config.stroke.strokeColor.getValue(),
|
||||||
opacity: config.stroke.strokeOpacity,
|
opacity: goog.isDef(config.stroke.strokeOpacity) ?
|
||||||
width: config.stroke.strokeWidth
|
config.stroke.strokeOpacity :
|
||||||
|
ol.parser.ogc.SLD_v1.defaults_.strokeOpacity,
|
||||||
|
width: goog.isDef(config.stroke.strokeWidth) ?
|
||||||
|
config.stroke.strokeWidth :
|
||||||
|
ol.parser.ogc.SLD_v1.defaults_.strokeWidth
|
||||||
};
|
};
|
||||||
rule.symbolizers.push(
|
rule.symbolizers.push(
|
||||||
new ol.style.Stroke(stroke)
|
new ol.style.Stroke(stroke)
|
||||||
@@ -607,7 +621,7 @@ ol.parser.ogc.SLD_v1 = function() {
|
|||||||
if (symbolizer instanceof ol.style.Icon) {
|
if (symbolizer instanceof ol.style.Icon) {
|
||||||
this.writeNode('ExternalGraphic', symbolizer, null, node);
|
this.writeNode('ExternalGraphic', symbolizer, null, node);
|
||||||
var opacity = symbolizer.getOpacity();
|
var opacity = symbolizer.getOpacity();
|
||||||
goog.asserts.assert(opacity instanceof ol.expr.Literal,
|
goog.asserts.assertInstanceof(opacity, ol.expr.Literal,
|
||||||
'Only ol.expr.Literal supported for graphicOpacity');
|
'Only ol.expr.Literal supported for graphicOpacity');
|
||||||
this.writeNode('Opacity', opacity.getValue(), null, node);
|
this.writeNode('Opacity', opacity.getValue(), null, node);
|
||||||
size = symbolizer.getWidth();
|
size = symbolizer.getWidth();
|
||||||
@@ -615,12 +629,12 @@ ol.parser.ogc.SLD_v1 = function() {
|
|||||||
this.writeNode('Mark', symbolizer, null, node);
|
this.writeNode('Mark', symbolizer, null, node);
|
||||||
size = symbolizer.getSize();
|
size = symbolizer.getSize();
|
||||||
}
|
}
|
||||||
goog.asserts.assert(size instanceof ol.expr.Literal,
|
goog.asserts.assertInstanceof(size, ol.expr.Literal,
|
||||||
'Only ol.expr.Literal supported for in Size');
|
'Only ol.expr.Literal supported for in Size');
|
||||||
this.writeNode('Size', size.getValue(), null, node);
|
this.writeNode('Size', size.getValue(), null, node);
|
||||||
if (symbolizer instanceof ol.style.Icon) {
|
if (symbolizer instanceof ol.style.Icon) {
|
||||||
var rotation = symbolizer.getRotation();
|
var rotation = symbolizer.getRotation();
|
||||||
goog.asserts.assert(rotation instanceof ol.expr.Literal,
|
goog.asserts.assertInstanceof(rotation, ol.expr.Literal,
|
||||||
'Only ol.expr.Literal supported for rotation');
|
'Only ol.expr.Literal supported for rotation');
|
||||||
this.writeNode('Rotation', rotation.getValue(), null, node);
|
this.writeNode('Rotation', rotation.getValue(), null, node);
|
||||||
}
|
}
|
||||||
@@ -635,13 +649,13 @@ ol.parser.ogc.SLD_v1 = function() {
|
|||||||
var node = this.createElementNS('sld:Fill');
|
var node = this.createElementNS('sld:Fill');
|
||||||
var fillColor = symbolizer.getColor();
|
var fillColor = symbolizer.getColor();
|
||||||
var msg = 'Only ol.expr.Literal supported for Fill properties';
|
var msg = 'Only ol.expr.Literal supported for Fill properties';
|
||||||
goog.asserts.assert(fillColor instanceof ol.expr.Literal, msg);
|
goog.asserts.assertInstanceof(fillColor, ol.expr.Literal, msg);
|
||||||
this.writeNode('CssParameter', {
|
this.writeNode('CssParameter', {
|
||||||
value: fillColor.getValue(),
|
value: fillColor.getValue(),
|
||||||
key: 'fillColor'
|
key: 'fillColor'
|
||||||
}, null, node);
|
}, null, node);
|
||||||
var fillOpacity = symbolizer.getOpacity();
|
var fillOpacity = symbolizer.getOpacity();
|
||||||
goog.asserts.assert(fillOpacity instanceof ol.expr.Literal, msg);
|
goog.asserts.assertInstanceof(fillOpacity, ol.expr.Literal, msg);
|
||||||
this.writeNode('CssParameter', {
|
this.writeNode('CssParameter', {
|
||||||
value: fillOpacity.getValue(),
|
value: fillOpacity.getValue(),
|
||||||
key: 'fillOpacity'
|
key: 'fillOpacity'
|
||||||
@@ -660,6 +674,24 @@ ol.parser.ogc.SLD_v1 = function() {
|
|||||||
if (!goog.isNull(stroke)) {
|
if (!goog.isNull(stroke)) {
|
||||||
this.writeNode('Halo', stroke, null, node);
|
this.writeNode('Halo', stroke, null, node);
|
||||||
}
|
}
|
||||||
|
var color = symbolizer.getColor();
|
||||||
|
goog.asserts.assertInstanceof(color, ol.expr.Literal,
|
||||||
|
'font color should be ol.expr.Literal');
|
||||||
|
this.writeNode('Fill', symbolizer, null, node);
|
||||||
|
return node;
|
||||||
|
},
|
||||||
|
'Halo': function(symbolizer) {
|
||||||
|
var node = this.createElementNS('sld:Halo');
|
||||||
|
goog.asserts.assertInstanceof(symbolizer.getWidth(), ol.expr.Literal,
|
||||||
|
'Only ol.expr.Literal supported for haloRadius');
|
||||||
|
this.writeNode('Radius', symbolizer.getWidth().getValue() / 2, null,
|
||||||
|
node);
|
||||||
|
this.writeNode('Fill', symbolizer, null, node);
|
||||||
|
return node;
|
||||||
|
},
|
||||||
|
'Radius': function(value) {
|
||||||
|
var node = this.createElementNS('sld:Radius');
|
||||||
|
node.appendChild(this.createTextNode(value));
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
'LineSymbolizer': function(symbolizer) {
|
'LineSymbolizer': function(symbolizer) {
|
||||||
@@ -672,19 +704,19 @@ ol.parser.ogc.SLD_v1 = function() {
|
|||||||
var strokeColor = symbolizer.getColor();
|
var strokeColor = symbolizer.getColor();
|
||||||
var msg = 'SLD writing of stroke properties only supported ' +
|
var msg = 'SLD writing of stroke properties only supported ' +
|
||||||
'for ol.expr.Literal';
|
'for ol.expr.Literal';
|
||||||
goog.asserts.assert(strokeColor instanceof ol.expr.Literal, msg);
|
goog.asserts.assertInstanceof(strokeColor, ol.expr.Literal, msg);
|
||||||
this.writeNode('CssParameter', {
|
this.writeNode('CssParameter', {
|
||||||
value: strokeColor.getValue(),
|
value: strokeColor.getValue(),
|
||||||
key: 'strokeColor'
|
key: 'strokeColor'
|
||||||
}, null, node);
|
}, null, node);
|
||||||
var strokeOpacity = symbolizer.getOpacity();
|
var strokeOpacity = symbolizer.getOpacity();
|
||||||
goog.asserts.assert(strokeOpacity instanceof ol.expr.Literal, msg);
|
goog.asserts.assertInstanceof(strokeOpacity, ol.expr.Literal, msg);
|
||||||
this.writeNode('CssParameter', {
|
this.writeNode('CssParameter', {
|
||||||
value: strokeOpacity.getValue(),
|
value: strokeOpacity.getValue(),
|
||||||
key: 'strokeOpacity'
|
key: 'strokeOpacity'
|
||||||
}, null, node);
|
}, null, node);
|
||||||
var strokeWidth = symbolizer.getWidth();
|
var strokeWidth = symbolizer.getWidth();
|
||||||
goog.asserts.assert(strokeWidth instanceof ol.expr.Literal, msg);
|
goog.asserts.assertInstanceof(strokeWidth, ol.expr.Literal, msg);
|
||||||
this.writeNode('CssParameter', {
|
this.writeNode('CssParameter', {
|
||||||
value: strokeWidth.getValue(),
|
value: strokeWidth.getValue(),
|
||||||
key: 'strokeWidth'
|
key: 'strokeWidth'
|
||||||
@@ -694,11 +726,14 @@ ol.parser.ogc.SLD_v1 = function() {
|
|||||||
},
|
},
|
||||||
'CssParameter': function(obj) {
|
'CssParameter': function(obj) {
|
||||||
// not handling ogc:expressions for now
|
// not handling ogc:expressions for now
|
||||||
var node = this.createElementNS('sld:CssParameter');
|
var name = ol.parser.ogc.SLD_v1.getCssProperty_(obj.key);
|
||||||
node.setAttribute('name',
|
if (goog.isDef(name) && obj.value !==
|
||||||
ol.parser.ogc.SLD_v1.getCssProperty_(obj.key));
|
ol.parser.ogc.SLD_v1.defaults_[obj.key]) {
|
||||||
node.appendChild(this.createTextNode(obj.value));
|
var node = this.createElementNS('sld:CssParameter');
|
||||||
return node;
|
node.setAttribute('name', name);
|
||||||
|
node.appendChild(this.createTextNode(obj.value));
|
||||||
|
return node;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'Label': function(label) {
|
'Label': function(label) {
|
||||||
var node = this.createElementNS('sld:Label');
|
var node = this.createElementNS('sld:Label');
|
||||||
@@ -777,6 +812,19 @@ ol.parser.ogc.SLD_v1.cssMap_ = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.parser.ogc.SLD_v1.defaults_ = {
|
||||||
|
fillOpacity: 1,
|
||||||
|
strokeOpacity: 1,
|
||||||
|
strokeWidth: 1,
|
||||||
|
haloColor: '#FFFFFF',
|
||||||
|
haloOpacity: 1,
|
||||||
|
haloRadius: 1
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @param {string} sym Symbolizer property.
|
* @param {string} sym Symbolizer property.
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ describe('ol.parser.ogc.SLD_v1_0_0', function() {
|
|||||||
expect(first.getSymbolizers()[0]).to.be.a(ol.style.Fill);
|
expect(first.getSymbolizers()[0]).to.be.a(ol.style.Fill);
|
||||||
expect(first.getSymbolizers()[0].getColor().getValue()).to.equal(
|
expect(first.getSymbolizers()[0].getColor().getValue()).to.equal(
|
||||||
'#ffffff');
|
'#ffffff');
|
||||||
expect(first.getSymbolizers()[0].getOpacity().getValue()).to.equal(0.4);
|
expect(first.getSymbolizers()[0].getOpacity().getValue()).to.equal(1);
|
||||||
expect(first.getSymbolizers()[1]).to.be.a(ol.style.Stroke);
|
expect(first.getSymbolizers()[1]).to.be.a(ol.style.Stroke);
|
||||||
expect(first.getSymbolizers()[1].getColor().getValue()).to.equal(
|
expect(first.getSymbolizers()[1].getColor().getValue()).to.equal(
|
||||||
'#000000');
|
'#000000');
|
||||||
@@ -47,7 +47,7 @@ describe('ol.parser.ogc.SLD_v1_0_0', function() {
|
|||||||
expect(first.getSymbolizers()[2].getText().getArgs()[2].getValue()).
|
expect(first.getSymbolizers()[2].getText().getArgs()[2].getValue()).
|
||||||
to.equal('label');
|
to.equal('label');
|
||||||
expect(first.getSymbolizers()[2].getColor().getValue()).to.equal(
|
expect(first.getSymbolizers()[2].getColor().getValue()).to.equal(
|
||||||
ol.style.TextDefaults.color);
|
'#000000');
|
||||||
expect(first.getSymbolizers()[2].getFontFamily().getValue()).to.equal(
|
expect(first.getSymbolizers()[2].getFontFamily().getValue()).to.equal(
|
||||||
'Arial');
|
'Arial');
|
||||||
// TODO add tests for haloRadius and haloColor
|
// TODO add tests for haloRadius and haloColor
|
||||||
|
|||||||
Reference in New Issue
Block a user