From 16946446809cdf6cff55d0d97a7a359bb12f252f Mon Sep 17 00:00:00 2001 From: Johannes Weskamm Date: Thu, 4 Mar 2021 08:35:30 +0100 Subject: [PATCH] Add SymbologyEncoding / SLD 1.1 Support --- data/slds/{ => 1.0}/line_graphicFill.sld | 0 .../line_graphicFill_externalGraphic.sld | 0 data/slds/{ => 1.0}/line_graphicStroke.sld | 0 .../line_graphicStroke_externalGraphic.sld | 0 .../{ => 1.0}/line_perpendicularOffset.sld | 0 data/slds/{ => 1.0}/line_simpleline.sld | 0 data/slds/{ => 1.0}/multi_simplelineLabel.sld | 0 data/slds/{ => 1.0}/point_externalgraphic.sld | 0 .../point_externalgraphic_floatingPoint.sld | 0 .../{ => 1.0}/point_externalgraphic_svg.sld | 0 data/slds/{ => 1.0}/point_fontglyph.sld | 0 data/slds/{ => 1.0}/point_simpleLabel.sld | 0 data/slds/{ => 1.0}/point_simplecross.sld | 0 data/slds/{ => 1.0}/point_simplepoint.sld | 0 .../{ => 1.0}/point_simplepoint_filter.sld | 0 .../point_simplepoint_functionfilter.sld | 0 ...point_simplepoint_nestedLogicalFilters.sld | 0 .../{ => 1.0}/point_simplepoint_oneline.sld | 0 data/slds/{ => 1.0}/point_simpleslash.sld | 0 data/slds/{ => 1.0}/point_simplesquare.sld | 0 data/slds/{ => 1.0}/point_simplestar.sld | 0 data/slds/{ => 1.0}/point_simpletriangle.sld | 0 data/slds/{ => 1.0}/point_simplex.sld | 0 .../1.0/point_styledLabel_elementOrder.sld | 45 + .../point_styledLabel_literalPlaceholder.sld | 0 data/slds/{ => 1.0}/point_styledlabel.sld | 0 data/slds/{ => 1.0}/polygon_graphicFill.sld | 0 .../polygon_graphicFill_externalGraphic.sld | 0 .../{ => 1.0}/polygon_transparentpolygon.sld | 0 data/slds/{ => 1.0}/raster_complexRaster.sld | 0 data/slds/{ => 1.0}/raster_simpleRaster.sld | 0 data/slds/1.1/line_graphicFill.sld | 34 + .../1.1/line_graphicFill_externalGraphic.sld | 33 + data/slds/1.1/line_graphicStroke.sld | 34 + .../line_graphicStroke_externalGraphic.sld | 33 + data/slds/1.1/line_perpendicularOffset.sld | 24 + data/slds/1.1/line_simpleline.sld | 24 + data/slds/1.1/multi_simplelineLabel.sld | 43 + data/slds/1.1/point_externalgraphic.sld | 24 + .../point_externalgraphic_floatingPoint.sld | 24 + data/slds/1.1/point_externalgraphic_svg.sld | 24 + data/slds/1.1/point_fontglyph.sld | 31 + data/slds/1.1/point_simpleLabel.sld | 19 + data/slds/1.1/point_simplecross.sld | 31 + data/slds/1.1/point_simplepoint.sld | 30 + data/slds/1.1/point_simplepoint_filter.sld | 70 ++ .../1.1/point_simplepoint_functionfilter.sld | 40 + ...point_simplepoint_nestedLogicalFilters.sld | 65 ++ data/slds/1.1/point_simplepoint_oneline.sld | 1 + data/slds/1.1/point_simpleslash.sld | 30 + data/slds/1.1/point_simplesquare.sld | 30 + data/slds/1.1/point_simplestar.sld | 31 + data/slds/1.1/point_simpletriangle.sld | 31 + data/slds/1.1/point_simplex.sld | 30 + .../1.1/point_styledLabel_elementOrder.sld | 44 + .../point_styledLabel_literalPlaceholder.sld | 44 + data/slds/1.1/point_styledlabel.sld | 43 + data/slds/1.1/polygon_graphicFill.sld | 34 + .../polygon_graphicFill_externalGraphic.sld | 34 + data/slds/1.1/polygon_transparentpolygon.sld | 26 + data/slds/1.1/raster_complexRaster.sld | 42 + data/slds/1.1/raster_simpleRaster.sld | 17 + src/SldStyleParser.ts | 83 +- ...er.spec.ts => SldStyleParser.v1.0.spec.ts} | 71 +- src/SldStyleParser.v1.1.spec.ts | 898 ++++++++++++++++++ src/SymbologyEncoder.ts | 108 +++ 66 files changed, 2182 insertions(+), 43 deletions(-) rename data/slds/{ => 1.0}/line_graphicFill.sld (100%) rename data/slds/{ => 1.0}/line_graphicFill_externalGraphic.sld (100%) rename data/slds/{ => 1.0}/line_graphicStroke.sld (100%) rename data/slds/{ => 1.0}/line_graphicStroke_externalGraphic.sld (100%) rename data/slds/{ => 1.0}/line_perpendicularOffset.sld (100%) rename data/slds/{ => 1.0}/line_simpleline.sld (100%) rename data/slds/{ => 1.0}/multi_simplelineLabel.sld (100%) rename data/slds/{ => 1.0}/point_externalgraphic.sld (100%) rename data/slds/{ => 1.0}/point_externalgraphic_floatingPoint.sld (100%) rename data/slds/{ => 1.0}/point_externalgraphic_svg.sld (100%) rename data/slds/{ => 1.0}/point_fontglyph.sld (100%) rename data/slds/{ => 1.0}/point_simpleLabel.sld (100%) rename data/slds/{ => 1.0}/point_simplecross.sld (100%) rename data/slds/{ => 1.0}/point_simplepoint.sld (100%) rename data/slds/{ => 1.0}/point_simplepoint_filter.sld (100%) rename data/slds/{ => 1.0}/point_simplepoint_functionfilter.sld (100%) rename data/slds/{ => 1.0}/point_simplepoint_nestedLogicalFilters.sld (100%) rename data/slds/{ => 1.0}/point_simplepoint_oneline.sld (100%) rename data/slds/{ => 1.0}/point_simpleslash.sld (100%) rename data/slds/{ => 1.0}/point_simplesquare.sld (100%) rename data/slds/{ => 1.0}/point_simplestar.sld (100%) rename data/slds/{ => 1.0}/point_simpletriangle.sld (100%) rename data/slds/{ => 1.0}/point_simplex.sld (100%) create mode 100644 data/slds/1.0/point_styledLabel_elementOrder.sld rename data/slds/{ => 1.0}/point_styledLabel_literalPlaceholder.sld (100%) rename data/slds/{ => 1.0}/point_styledlabel.sld (100%) rename data/slds/{ => 1.0}/polygon_graphicFill.sld (100%) rename data/slds/{ => 1.0}/polygon_graphicFill_externalGraphic.sld (100%) rename data/slds/{ => 1.0}/polygon_transparentpolygon.sld (100%) rename data/slds/{ => 1.0}/raster_complexRaster.sld (100%) rename data/slds/{ => 1.0}/raster_simpleRaster.sld (100%) create mode 100644 data/slds/1.1/line_graphicFill.sld create mode 100644 data/slds/1.1/line_graphicFill_externalGraphic.sld create mode 100644 data/slds/1.1/line_graphicStroke.sld create mode 100644 data/slds/1.1/line_graphicStroke_externalGraphic.sld create mode 100644 data/slds/1.1/line_perpendicularOffset.sld create mode 100644 data/slds/1.1/line_simpleline.sld create mode 100644 data/slds/1.1/multi_simplelineLabel.sld create mode 100644 data/slds/1.1/point_externalgraphic.sld create mode 100644 data/slds/1.1/point_externalgraphic_floatingPoint.sld create mode 100644 data/slds/1.1/point_externalgraphic_svg.sld create mode 100644 data/slds/1.1/point_fontglyph.sld create mode 100644 data/slds/1.1/point_simpleLabel.sld create mode 100644 data/slds/1.1/point_simplecross.sld create mode 100644 data/slds/1.1/point_simplepoint.sld create mode 100644 data/slds/1.1/point_simplepoint_filter.sld create mode 100644 data/slds/1.1/point_simplepoint_functionfilter.sld create mode 100644 data/slds/1.1/point_simplepoint_nestedLogicalFilters.sld create mode 100644 data/slds/1.1/point_simplepoint_oneline.sld create mode 100644 data/slds/1.1/point_simpleslash.sld create mode 100644 data/slds/1.1/point_simplesquare.sld create mode 100644 data/slds/1.1/point_simplestar.sld create mode 100644 data/slds/1.1/point_simpletriangle.sld create mode 100644 data/slds/1.1/point_simplex.sld create mode 100644 data/slds/1.1/point_styledLabel_elementOrder.sld create mode 100644 data/slds/1.1/point_styledLabel_literalPlaceholder.sld create mode 100644 data/slds/1.1/point_styledlabel.sld create mode 100644 data/slds/1.1/polygon_graphicFill.sld create mode 100644 data/slds/1.1/polygon_graphicFill_externalGraphic.sld create mode 100644 data/slds/1.1/polygon_transparentpolygon.sld create mode 100644 data/slds/1.1/raster_complexRaster.sld create mode 100644 data/slds/1.1/raster_simpleRaster.sld rename src/{SldStyleParser.spec.ts => SldStyleParser.v1.0.spec.ts} (92%) create mode 100644 src/SldStyleParser.v1.1.spec.ts create mode 100644 src/SymbologyEncoder.ts diff --git a/data/slds/line_graphicFill.sld b/data/slds/1.0/line_graphicFill.sld similarity index 100% rename from data/slds/line_graphicFill.sld rename to data/slds/1.0/line_graphicFill.sld diff --git a/data/slds/line_graphicFill_externalGraphic.sld b/data/slds/1.0/line_graphicFill_externalGraphic.sld similarity index 100% rename from data/slds/line_graphicFill_externalGraphic.sld rename to data/slds/1.0/line_graphicFill_externalGraphic.sld diff --git a/data/slds/line_graphicStroke.sld b/data/slds/1.0/line_graphicStroke.sld similarity index 100% rename from data/slds/line_graphicStroke.sld rename to data/slds/1.0/line_graphicStroke.sld diff --git a/data/slds/line_graphicStroke_externalGraphic.sld b/data/slds/1.0/line_graphicStroke_externalGraphic.sld similarity index 100% rename from data/slds/line_graphicStroke_externalGraphic.sld rename to data/slds/1.0/line_graphicStroke_externalGraphic.sld diff --git a/data/slds/line_perpendicularOffset.sld b/data/slds/1.0/line_perpendicularOffset.sld similarity index 100% rename from data/slds/line_perpendicularOffset.sld rename to data/slds/1.0/line_perpendicularOffset.sld diff --git a/data/slds/line_simpleline.sld b/data/slds/1.0/line_simpleline.sld similarity index 100% rename from data/slds/line_simpleline.sld rename to data/slds/1.0/line_simpleline.sld diff --git a/data/slds/multi_simplelineLabel.sld b/data/slds/1.0/multi_simplelineLabel.sld similarity index 100% rename from data/slds/multi_simplelineLabel.sld rename to data/slds/1.0/multi_simplelineLabel.sld diff --git a/data/slds/point_externalgraphic.sld b/data/slds/1.0/point_externalgraphic.sld similarity index 100% rename from data/slds/point_externalgraphic.sld rename to data/slds/1.0/point_externalgraphic.sld diff --git a/data/slds/point_externalgraphic_floatingPoint.sld b/data/slds/1.0/point_externalgraphic_floatingPoint.sld similarity index 100% rename from data/slds/point_externalgraphic_floatingPoint.sld rename to data/slds/1.0/point_externalgraphic_floatingPoint.sld diff --git a/data/slds/point_externalgraphic_svg.sld b/data/slds/1.0/point_externalgraphic_svg.sld similarity index 100% rename from data/slds/point_externalgraphic_svg.sld rename to data/slds/1.0/point_externalgraphic_svg.sld diff --git a/data/slds/point_fontglyph.sld b/data/slds/1.0/point_fontglyph.sld similarity index 100% rename from data/slds/point_fontglyph.sld rename to data/slds/1.0/point_fontglyph.sld diff --git a/data/slds/point_simpleLabel.sld b/data/slds/1.0/point_simpleLabel.sld similarity index 100% rename from data/slds/point_simpleLabel.sld rename to data/slds/1.0/point_simpleLabel.sld diff --git a/data/slds/point_simplecross.sld b/data/slds/1.0/point_simplecross.sld similarity index 100% rename from data/slds/point_simplecross.sld rename to data/slds/1.0/point_simplecross.sld diff --git a/data/slds/point_simplepoint.sld b/data/slds/1.0/point_simplepoint.sld similarity index 100% rename from data/slds/point_simplepoint.sld rename to data/slds/1.0/point_simplepoint.sld diff --git a/data/slds/point_simplepoint_filter.sld b/data/slds/1.0/point_simplepoint_filter.sld similarity index 100% rename from data/slds/point_simplepoint_filter.sld rename to data/slds/1.0/point_simplepoint_filter.sld diff --git a/data/slds/point_simplepoint_functionfilter.sld b/data/slds/1.0/point_simplepoint_functionfilter.sld similarity index 100% rename from data/slds/point_simplepoint_functionfilter.sld rename to data/slds/1.0/point_simplepoint_functionfilter.sld diff --git a/data/slds/point_simplepoint_nestedLogicalFilters.sld b/data/slds/1.0/point_simplepoint_nestedLogicalFilters.sld similarity index 100% rename from data/slds/point_simplepoint_nestedLogicalFilters.sld rename to data/slds/1.0/point_simplepoint_nestedLogicalFilters.sld diff --git a/data/slds/point_simplepoint_oneline.sld b/data/slds/1.0/point_simplepoint_oneline.sld similarity index 100% rename from data/slds/point_simplepoint_oneline.sld rename to data/slds/1.0/point_simplepoint_oneline.sld diff --git a/data/slds/point_simpleslash.sld b/data/slds/1.0/point_simpleslash.sld similarity index 100% rename from data/slds/point_simpleslash.sld rename to data/slds/1.0/point_simpleslash.sld diff --git a/data/slds/point_simplesquare.sld b/data/slds/1.0/point_simplesquare.sld similarity index 100% rename from data/slds/point_simplesquare.sld rename to data/slds/1.0/point_simplesquare.sld diff --git a/data/slds/point_simplestar.sld b/data/slds/1.0/point_simplestar.sld similarity index 100% rename from data/slds/point_simplestar.sld rename to data/slds/1.0/point_simplestar.sld diff --git a/data/slds/point_simpletriangle.sld b/data/slds/1.0/point_simpletriangle.sld similarity index 100% rename from data/slds/point_simpletriangle.sld rename to data/slds/1.0/point_simpletriangle.sld diff --git a/data/slds/point_simplex.sld b/data/slds/1.0/point_simplex.sld similarity index 100% rename from data/slds/point_simplex.sld rename to data/slds/1.0/point_simplex.sld diff --git a/data/slds/1.0/point_styledLabel_elementOrder.sld b/data/slds/1.0/point_styledLabel_elementOrder.sld new file mode 100644 index 00000000..3bd37402 --- /dev/null +++ b/data/slds/1.0/point_styledLabel_elementOrder.sld @@ -0,0 +1,45 @@ + + + + Styled Label + + Styled Label + Styled Label + + + + + + + Arial + 12 + normal + bold + + + + + 0 + 5 + + 45 + + + + 5 + + #000000 + + + + #000000 + + + + + + + diff --git a/data/slds/point_styledLabel_literalPlaceholder.sld b/data/slds/1.0/point_styledLabel_literalPlaceholder.sld similarity index 100% rename from data/slds/point_styledLabel_literalPlaceholder.sld rename to data/slds/1.0/point_styledLabel_literalPlaceholder.sld diff --git a/data/slds/point_styledlabel.sld b/data/slds/1.0/point_styledlabel.sld similarity index 100% rename from data/slds/point_styledlabel.sld rename to data/slds/1.0/point_styledlabel.sld diff --git a/data/slds/polygon_graphicFill.sld b/data/slds/1.0/polygon_graphicFill.sld similarity index 100% rename from data/slds/polygon_graphicFill.sld rename to data/slds/1.0/polygon_graphicFill.sld diff --git a/data/slds/polygon_graphicFill_externalGraphic.sld b/data/slds/1.0/polygon_graphicFill_externalGraphic.sld similarity index 100% rename from data/slds/polygon_graphicFill_externalGraphic.sld rename to data/slds/1.0/polygon_graphicFill_externalGraphic.sld diff --git a/data/slds/polygon_transparentpolygon.sld b/data/slds/1.0/polygon_transparentpolygon.sld similarity index 100% rename from data/slds/polygon_transparentpolygon.sld rename to data/slds/1.0/polygon_transparentpolygon.sld diff --git a/data/slds/raster_complexRaster.sld b/data/slds/1.0/raster_complexRaster.sld similarity index 100% rename from data/slds/raster_complexRaster.sld rename to data/slds/1.0/raster_complexRaster.sld diff --git a/data/slds/raster_simpleRaster.sld b/data/slds/1.0/raster_simpleRaster.sld similarity index 100% rename from data/slds/raster_simpleRaster.sld rename to data/slds/1.0/raster_simpleRaster.sld diff --git a/data/slds/1.1/line_graphicFill.sld b/data/slds/1.1/line_graphicFill.sld new file mode 100644 index 00000000..570cabca --- /dev/null +++ b/data/slds/1.1/line_graphicFill.sld @@ -0,0 +1,34 @@ + + + + Simple Line + + Simple Line + + + + + + + + + circle + + #FF0000 + + + 7 + + + #000000 + 3 + 13 37 + round + mitre + + + + + + + diff --git a/data/slds/1.1/line_graphicFill_externalGraphic.sld b/data/slds/1.1/line_graphicFill_externalGraphic.sld new file mode 100644 index 00000000..a0b67d17 --- /dev/null +++ b/data/slds/1.1/line_graphicFill_externalGraphic.sld @@ -0,0 +1,33 @@ + + + + Simple Line + + Simple Line + + + + + + + + + + image/png + + 10 + 90 + + + #000000 + 3 + 13 37 + round + mitre + + + + + + + diff --git a/data/slds/1.1/line_graphicStroke.sld b/data/slds/1.1/line_graphicStroke.sld new file mode 100644 index 00000000..9c947714 --- /dev/null +++ b/data/slds/1.1/line_graphicStroke.sld @@ -0,0 +1,34 @@ + + + + Simple Line + + Simple Line + + + + + + + + + circle + + #FF0000 + + + 7 + + + #000000 + 3 + 13 37 + round + mitre + + + + + + + diff --git a/data/slds/1.1/line_graphicStroke_externalGraphic.sld b/data/slds/1.1/line_graphicStroke_externalGraphic.sld new file mode 100644 index 00000000..f9b1b0c2 --- /dev/null +++ b/data/slds/1.1/line_graphicStroke_externalGraphic.sld @@ -0,0 +1,33 @@ + + + + Simple Line + + Simple Line + + + + + + + + + + image/png + + 10 + 90 + + + #000000 + 3 + 13 37 + round + mitre + + + + + + + diff --git a/data/slds/1.1/line_perpendicularOffset.sld b/data/slds/1.1/line_perpendicularOffset.sld new file mode 100644 index 00000000..279ece32 --- /dev/null +++ b/data/slds/1.1/line_perpendicularOffset.sld @@ -0,0 +1,24 @@ + + + + Simple Line + + Simple Line + + + + + + #000000 + 3 + 13 37 + round + mitre + + 3 + + + + + + diff --git a/data/slds/1.1/line_simpleline.sld b/data/slds/1.1/line_simpleline.sld new file mode 100644 index 00000000..9cab6df4 --- /dev/null +++ b/data/slds/1.1/line_simpleline.sld @@ -0,0 +1,24 @@ + + + + Simple Line + + Simple Line + + + + + + #000000 + 3 + 13 37 + 10 + round + mitre + + + + + + + diff --git a/data/slds/1.1/multi_simplelineLabel.sld b/data/slds/1.1/multi_simplelineLabel.sld new file mode 100644 index 00000000..8246183f --- /dev/null +++ b/data/slds/1.1/multi_simplelineLabel.sld @@ -0,0 +1,43 @@ + + + + Simple Line with label + + Simple Line with label + + + + + + #000000 + 3 + 13 37 + + + + + name + + + Arial + 12 + normal + bold + + + + + 0 + 5 + + + + + #000000 + + + + + + + diff --git a/data/slds/1.1/point_externalgraphic.sld b/data/slds/1.1/point_externalgraphic.sld new file mode 100644 index 00000000..17e367c5 --- /dev/null +++ b/data/slds/1.1/point_externalgraphic.sld @@ -0,0 +1,24 @@ + + + + External Graphic + + External Graphic + + + + + + + + image/png + + 10 + 90 + + + + + + + diff --git a/data/slds/1.1/point_externalgraphic_floatingPoint.sld b/data/slds/1.1/point_externalgraphic_floatingPoint.sld new file mode 100644 index 00000000..244c2b23 --- /dev/null +++ b/data/slds/1.1/point_externalgraphic_floatingPoint.sld @@ -0,0 +1,24 @@ + + + + External Graphic + + External Graphic + + + + + + + + image/png + + 0.1 + 90.5 + + + + + + + diff --git a/data/slds/1.1/point_externalgraphic_svg.sld b/data/slds/1.1/point_externalgraphic_svg.sld new file mode 100644 index 00000000..a4fd4361 --- /dev/null +++ b/data/slds/1.1/point_externalgraphic_svg.sld @@ -0,0 +1,24 @@ + + + + External Graphic + + External Graphic + + + + + + + + image/svg+xml + + 10 + 90 + + + + + + + diff --git a/data/slds/1.1/point_fontglyph.sld b/data/slds/1.1/point_fontglyph.sld new file mode 100644 index 00000000..26755b27 --- /dev/null +++ b/data/slds/1.1/point_fontglyph.sld @@ -0,0 +1,31 @@ + + + + Font Glyph + + Font Glyph + + + Small populated New Yorks + + + + ttf://My Font Name#0x0A23 + + #FF0000 + 0.5 + + + #0000FF + 0.7 + + + 1 + 10 + + + + + + + diff --git a/data/slds/1.1/point_simpleLabel.sld b/data/slds/1.1/point_simpleLabel.sld new file mode 100644 index 00000000..9ef21542 --- /dev/null +++ b/data/slds/1.1/point_simpleLabel.sld @@ -0,0 +1,19 @@ + + + + Styled Label + + Styled Label + + + + + + myText + + + + + + + diff --git a/data/slds/1.1/point_simplecross.sld b/data/slds/1.1/point_simplecross.sld new file mode 100644 index 00000000..13190243 --- /dev/null +++ b/data/slds/1.1/point_simplecross.sld @@ -0,0 +1,31 @@ + + + + Simple Cross + + Simple Cross + + + Small populated New Yorks + + + + cross + + #FF0000 + + + #000000 + 2 + + + 1 + 10 + 45 + + + + + + + diff --git a/data/slds/1.1/point_simplepoint.sld b/data/slds/1.1/point_simplepoint.sld new file mode 100644 index 00000000..72eade15 --- /dev/null +++ b/data/slds/1.1/point_simplepoint.sld @@ -0,0 +1,30 @@ + + + + Simple Point + + Simple Point + + + + + + + circle + + #FF0000 + 0.5 + + + #0000FF + 0.7 + + + 6 + + + + + + + diff --git a/data/slds/1.1/point_simplepoint_filter.sld b/data/slds/1.1/point_simplepoint_filter.sld new file mode 100644 index 00000000..dd812853 --- /dev/null +++ b/data/slds/1.1/point_simplepoint_filter.sld @@ -0,0 +1,70 @@ + + + + Simple Point Filter + + Simple Point Filter + + + Small populated New Yorks + + + + NAME + New York + + + TEST_BOOL + true + + + TEST + + + TEST2 + *York* + + + TEST1 + *New* + + + + POPULATION + 100000 + + + + + TEST2 + 1 + + + TEST2 + 2 + + + + + 10000 + 20000 + + + + circle + + #FF0000 + + + #000000 + 2 + + + 6 + + + + + + + diff --git a/data/slds/1.1/point_simplepoint_functionfilter.sld b/data/slds/1.1/point_simplepoint_functionfilter.sld new file mode 100644 index 00000000..8e4c409d --- /dev/null +++ b/data/slds/1.1/point_simplepoint_functionfilter.sld @@ -0,0 +1,40 @@ + + + + Simple Point Filter + + Simple Point Filter + + + Small populated New Yorks + + + + year + ^( )??2019,.* + + true + + + 10000 + 20000 + + + + circle + + #FF0000 + + + #000000 + 2 + + + 6 + + + + + + + diff --git a/data/slds/1.1/point_simplepoint_nestedLogicalFilters.sld b/data/slds/1.1/point_simplepoint_nestedLogicalFilters.sld new file mode 100644 index 00000000..c4925241 --- /dev/null +++ b/data/slds/1.1/point_simplepoint_nestedLogicalFilters.sld @@ -0,0 +1,65 @@ + + + + Simple Point Filter + + Simple Point Filter + + + Test + + + + + ID + 1 + + + ID + 2 + + + + + STREET + Main + + + STREET + Time square + + + + HOUSENO + 1909 + + + HOUSENO + 19909 + + + + + + 10000 + 20000 + + + + circle + + #FF0000 + + + #000000 + 2 + + + 6 + + + + + + + diff --git a/data/slds/1.1/point_simplepoint_oneline.sld b/data/slds/1.1/point_simplepoint_oneline.sld new file mode 100644 index 00000000..689deba8 --- /dev/null +++ b/data/slds/1.1/point_simplepoint_oneline.sld @@ -0,0 +1 @@ +Simple PointSimple Pointcircle#FF00000.5#0000FF0.76 diff --git a/data/slds/1.1/point_simpleslash.sld b/data/slds/1.1/point_simpleslash.sld new file mode 100644 index 00000000..73970132 --- /dev/null +++ b/data/slds/1.1/point_simpleslash.sld @@ -0,0 +1,30 @@ + + + + Simple Slash + + Simple Slash + + + Small populated New Yorks + + + + shape://slash + + #FF0000 + + + #000000 + 2 + + + 1 + 10 + + + + + + + diff --git a/data/slds/1.1/point_simplesquare.sld b/data/slds/1.1/point_simplesquare.sld new file mode 100644 index 00000000..ae63f8d5 --- /dev/null +++ b/data/slds/1.1/point_simplesquare.sld @@ -0,0 +1,30 @@ + + + + Simple Square + + Simple Square + + + Small populated New Yorks + + + + square + + #FF0000 + + + #000000 + 2 + + + 1 + 10 + + + + + + + diff --git a/data/slds/1.1/point_simplestar.sld b/data/slds/1.1/point_simplestar.sld new file mode 100644 index 00000000..a39b0bb4 --- /dev/null +++ b/data/slds/1.1/point_simplestar.sld @@ -0,0 +1,31 @@ + + + + Simple Star + + Simple Star + + + Small populated New Yorks + + + + star + + #FF0000 + + + #000000 + 2 + + + 1 + 10 + 45 + + + + + + + diff --git a/data/slds/1.1/point_simpletriangle.sld b/data/slds/1.1/point_simpletriangle.sld new file mode 100644 index 00000000..e0d81d3b --- /dev/null +++ b/data/slds/1.1/point_simpletriangle.sld @@ -0,0 +1,31 @@ + + + + Simple Triangle + + Simple Triangle + + + Small populated New Yorks + + + + triangle + + #FF0000 + + + #000000 + 2 + + + 1 + 10 + 45 + + + + + + + diff --git a/data/slds/1.1/point_simplex.sld b/data/slds/1.1/point_simplex.sld new file mode 100644 index 00000000..9fb8282e --- /dev/null +++ b/data/slds/1.1/point_simplex.sld @@ -0,0 +1,30 @@ + + + + Simple X + + Simple X + + + Small populated New Yorks + + + + x + + #FF0000 + + + #000000 + 2 + + + 1 + 10 + + + + + + + diff --git a/data/slds/1.1/point_styledLabel_elementOrder.sld b/data/slds/1.1/point_styledLabel_elementOrder.sld new file mode 100644 index 00000000..cc4ecb18 --- /dev/null +++ b/data/slds/1.1/point_styledLabel_elementOrder.sld @@ -0,0 +1,44 @@ + + + + Styled Label + + Styled Label + + + + + + name + entity + + + Arial + 12 + normal + bold + + + + + 0 + 5 + + 45 + + + + 5 + + #000000 + + + + #000000 + + + + + + + diff --git a/data/slds/1.1/point_styledLabel_literalPlaceholder.sld b/data/slds/1.1/point_styledLabel_literalPlaceholder.sld new file mode 100644 index 00000000..cc4ecb18 --- /dev/null +++ b/data/slds/1.1/point_styledLabel_literalPlaceholder.sld @@ -0,0 +1,44 @@ + + + + Styled Label + + Styled Label + + + + + + name + entity + + + Arial + 12 + normal + bold + + + + + 0 + 5 + + 45 + + + + 5 + + #000000 + + + + #000000 + + + + + + + diff --git a/data/slds/1.1/point_styledlabel.sld b/data/slds/1.1/point_styledlabel.sld new file mode 100644 index 00000000..7e4837e4 --- /dev/null +++ b/data/slds/1.1/point_styledlabel.sld @@ -0,0 +1,43 @@ + + + + Styled Label + + Styled Label + + + + + + name + + + Arial + 12 + normal + bold + + + + + 0 + 5 + + 45 + + + + 5 + + #000000 + + + + #000000 + + + + + + + diff --git a/data/slds/1.1/polygon_graphicFill.sld b/data/slds/1.1/polygon_graphicFill.sld new file mode 100644 index 00000000..eff0170e --- /dev/null +++ b/data/slds/1.1/polygon_graphicFill.sld @@ -0,0 +1,34 @@ + + + + Polygon Graphic Fill + + Polygon Graphic Fill + + + + + + + + + circle + + #FF0000 + + + + + #000080 + + + #FFFFFF + 2 + 1 0 + + + + + + + diff --git a/data/slds/1.1/polygon_graphicFill_externalGraphic.sld b/data/slds/1.1/polygon_graphicFill_externalGraphic.sld new file mode 100644 index 00000000..b15c61f3 --- /dev/null +++ b/data/slds/1.1/polygon_graphicFill_externalGraphic.sld @@ -0,0 +1,34 @@ + + + + Polygon Graphic Fill + + Polygon Graphic Fill + + + + + + + + + + image/png + + 10 + 90 + + + #000080 + + + #FFFFFF + 2 + 1 0 + + + + + + + diff --git a/data/slds/1.1/polygon_transparentpolygon.sld b/data/slds/1.1/polygon_transparentpolygon.sld new file mode 100644 index 00000000..6a66531a --- /dev/null +++ b/data/slds/1.1/polygon_transparentpolygon.sld @@ -0,0 +1,26 @@ + + + + Transparent Polygon + + Transparent Polygon + + + + + + #000080 + 0.5 + + + #FFFFFF + 2 + 1 0 + 0.9 + + + + + + + diff --git a/data/slds/1.1/raster_complexRaster.sld b/data/slds/1.1/raster_complexRaster.sld new file mode 100644 index 00000000..39899996 --- /dev/null +++ b/data/slds/1.1/raster_complexRaster.sld @@ -0,0 +1,42 @@ + + + + Complex Raster + + Complex Raster + + + Small populated New Yorks + + 0.5 + + + + + + + 1 + + + 2 + + + 2 + + + + 3 + + + + + + + + + + + + + + diff --git a/data/slds/1.1/raster_simpleRaster.sld b/data/slds/1.1/raster_simpleRaster.sld new file mode 100644 index 00000000..9daa5eaf --- /dev/null +++ b/data/slds/1.1/raster_simpleRaster.sld @@ -0,0 +1,17 @@ + + + + Simple Raster + + Simple Raster + + + Small populated New Yorks + + 0.5 + + + + + + diff --git a/src/SldStyleParser.ts b/src/SldStyleParser.ts index 87f19eed..6483799d 100644 --- a/src/SldStyleParser.ts +++ b/src/SldStyleParser.ts @@ -31,6 +31,8 @@ import { OptionsV2 } from 'xml2js'; +import SymbologyEncoder from './SymbologyEncoder'; + const _isString = require('lodash/isString'); const _isNumber = require('lodash/isNumber'); const _get = require('lodash/get'); @@ -42,6 +44,8 @@ export type ConstructorParams = { numericFilterFields?: string[]; boolFilterFields?: string[]; prettyOutput?: boolean; + sldVersion?: string; + symbolizerUnits?: string; }; const WELLKNOWNNAME_TTF_REGEXP = /^ttf:\/\/(.+)#(.+)$/; @@ -167,6 +171,50 @@ export class SldStyleParser implements StyleParser { this._prettyOutput = prettyOutput; } + /** + * String indicating the SLD version to use. 1.1.0 will make use of + * Symbology Encoding. Default ist to use SLD 1.0.0 + */ + private _sldVersion: string = '1.0.0'; + + /** + * Getter for _sldVersion + * @return {boolean} + */ + get sldVersion(): string { + return this._sldVersion; + } + + /** + * Setter for _sldVersion + * @param {string} sldVersion The _sldVersion value to set + */ + set sldVersion(sldVersion: string) { + this._sldVersion = sldVersion; + } + + /** + * Used to add a `uom` attribute to the symbolizer tag. Can be one of + * `metre`, `foot` or `pixel`. Defaults to pixel. + */ + private _symbolizerUnits: string = 'pixel'; + + /** + * Getter for _symbolizerUnits + * @return {string} + */ + get symbolizerUnits(): string { + return this._symbolizerUnits; + } + + /** + * Setter for _symbolizerUnits + * @param {string} symbolizerUnits The _symbolizerUnits value to set + */ + set symbolizerUnits(symbolizerUnits: string) { + this._symbolizerUnits = symbolizerUnits; + } + /** * Returns the keys of an object where the value is equal to the passed in * value. @@ -397,9 +445,12 @@ export class SldStyleParser implements StyleParser { const fillOpacityIdx: number = fillParams.findIndex((cssParam: any) => { return cssParam.$.name === 'fill-opacity'; }); - const fillOpacity: string = _get(sldSymbolizer, + let fillOpacity: string = _get(sldSymbolizer, 'Graphic[0].Mark[0].Fill[0].CssParameter[' + fillOpacityIdx + ']._'); - + if (!fillOpacity) { + fillOpacity = _get(sldSymbolizer, + 'Graphic[0].Mark[0].Fill[0].SvgParameter[' + fillOpacityIdx + ']._'); + } const markSymbolizer: MarkSymbolizer = { kind: 'Mark', } as MarkSymbolizer; @@ -1207,6 +1258,11 @@ export class SldStyleParser implements StyleParser { rule.Filter.$ = { 'xmlns': 'http://www.opengis.net/ogc' }; } }); + + if (this.sldVersion !== '1.0.0') { + return SymbologyEncoder.getSymbologyEncoding( + geoStylerStyle, rules, this.symbolizerUnits); + } return { StyledLayerDescriptor: { '$': { @@ -1481,17 +1537,6 @@ export class SldStyleParser implements StyleParser { }]; } - if (textSymbolizer.color) { - sldTextSymbolizer[0].Fill = [{ - 'CssParameter': [{ - '_': textSymbolizer.color, - '$': { - 'name': 'fill' - } - }] - }]; - } - if (textSymbolizer.haloWidth || textSymbolizer.haloColor) { const halo: any = {}; const haloCssParameter = []; @@ -1513,6 +1558,18 @@ export class SldStyleParser implements StyleParser { } sldTextSymbolizer[0].Halo = [halo]; } + + if (textSymbolizer.color) { + sldTextSymbolizer[0].Fill = [{ + 'CssParameter': [{ + '_': textSymbolizer.color, + '$': { + 'name': 'fill' + } + }] + }]; + } + return { 'TextSymbolizer': sldTextSymbolizer }; diff --git a/src/SldStyleParser.spec.ts b/src/SldStyleParser.v1.0.spec.ts similarity index 92% rename from src/SldStyleParser.spec.ts rename to src/SldStyleParser.v1.0.spec.ts index 640632c3..ce62d260 100644 --- a/src/SldStyleParser.spec.ts +++ b/src/SldStyleParser.v1.0.spec.ts @@ -66,7 +66,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD PointSymbolizer', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/point_simplepoint.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/point_simplepoint.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -75,7 +75,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD PointSymbolizer with ExternalGraphic', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/point_externalgraphic.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/point_externalgraphic.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -84,7 +84,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD PointSymbolizer with ExternalGraphic with floating-point values', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/point_externalgraphic_floatingPoint.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/point_externalgraphic_floatingPoint.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -93,7 +93,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD PointSymbolizer with ExternalGraphic svg', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/point_externalgraphic_svg.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/point_externalgraphic_svg.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -102,7 +102,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD PointSymbolizer with wellKnownName square', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/point_simplesquare.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/point_simplesquare.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -111,7 +111,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD PointSymbolizer with wellKnownName triangle', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/point_simpletriangle.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/point_simpletriangle.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -120,7 +120,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD PointSymbolizer with wellKnownName star', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/point_simplestar.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/point_simplestar.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -129,7 +129,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD PointSymbolizer with wellKnownName cross', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/point_simplecross.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/point_simplecross.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -138,7 +138,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD PointSymbolizer with wellKnownName x', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/point_simplex.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/point_simplex.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -147,7 +147,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD PointSymbolizer with wellKnownName shape://slash', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/point_simpleslash.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/point_simpleslash.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -156,7 +156,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD PointSymbolizer with wellKnownName using a font glyph (starting with ttf://)', () => { expect.assertions(2); - const sld = fs.readFileSync( './data/slds/point_fontglyph.sld', 'utf8'); + const sld = fs.readFileSync( './data/slds/1.0/point_fontglyph.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -165,7 +165,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD LineSymbolizer', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/line_simpleline.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/line_simpleline.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -174,7 +174,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD LineSymbolizer with Perpendicular Offset', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/line_perpendicularOffset.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/line_perpendicularOffset.sld', 'utf8'); return styleParser.readStyle(sld) .then((geostylerStyle: Style) => { expect(geostylerStyle).toBeDefined(); @@ -183,7 +183,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD LineSymbolizer with GraphicStroke', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/line_graphicStroke.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/line_graphicStroke.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -192,7 +192,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD LineSymbolizer with GraphicStroke and ExternalGraphic', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/line_graphicStroke_externalGraphic.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/line_graphicStroke_externalGraphic.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -201,7 +201,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD LineSymbolizer with GraphicFill', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/line_graphicFill.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/line_graphicFill.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -210,7 +210,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD LineSymbolizer with GraphicFill and ExternalGraphic', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/line_graphicFill_externalGraphic.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/line_graphicFill_externalGraphic.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -219,7 +219,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD PolygonSymbolizer', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/polygon_transparentpolygon.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/polygon_transparentpolygon.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -228,7 +228,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD PolygonSymbolizer with GraphicFill', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/polygon_graphicFill.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/polygon_graphicFill.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -237,7 +237,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD PolygonSymbolizer with GraphicFill and ExternalGraphic', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/polygon_graphicFill_externalGraphic.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/polygon_graphicFill_externalGraphic.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -246,7 +246,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD TextSymbolizer', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/point_styledlabel.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/point_styledlabel.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -255,7 +255,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD TextSymbolizer with a static label', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/point_simpleLabel.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/point_simpleLabel.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -264,7 +264,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a simple SLD RasterSymbolizer', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/raster_simpleRaster.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/raster_simpleRaster.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -273,7 +273,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a complex SLD RasterSymbolizer', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/raster_complexRaster.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/raster_complexRaster.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -282,7 +282,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD style with a filter', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/point_simplepoint_filter.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/point_simplepoint_filter.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -291,7 +291,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD style with nested logical filters', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/point_simplepoint_nestedLogicalFilters.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/point_simplepoint_nestedLogicalFilters.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -300,7 +300,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD style with functionfilters', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/point_simplepoint_functionfilter.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/point_simplepoint_functionfilter.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -309,7 +309,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD style with multiple symbolizers in one Rule', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/multi_simplelineLabel.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/multi_simplelineLabel.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -318,7 +318,7 @@ describe('SldStyleParser implements StyleParser', () => { }); it('can read a SLD style with a styled label containing a PropertyName and a Literal', () => { expect.assertions(2); - const sld = fs.readFileSync('./data/slds/point_styledLabel_literalPlaceholder.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/point_styledLabel_literalPlaceholder.sld', 'utf8'); return styleParser.readStyle(sld) .then((geoStylerStyle: Style) => { expect(geoStylerStyle).toBeDefined(); @@ -820,7 +820,18 @@ describe('SldStyleParser implements StyleParser', () => { return styleParserPrettyFalse.writeStyle(point_simplepoint) .then((sldString: string) => { expect(sldString).toBeDefined(); - const sld = fs.readFileSync('./data/slds/point_simplepoint_oneline.sld', 'utf8'); + const sld = fs.readFileSync('./data/slds/1.0/point_simplepoint_oneline.sld', 'utf8'); + expect(sldString).toEqual(sld.trim()); + }); + }); + + it('creates the correct order in a text symbolizer', () => { + expect.assertions(2); + const styleParserOrder = new SldStyleParser(); + return styleParserOrder.writeStyle(point_styledLabel_literalPlaceholder) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + const sld = fs.readFileSync('./data/slds/1.0/point_styledLabel_elementOrder.sld', 'utf8'); expect(sldString).toEqual(sld.trim()); }); }); diff --git a/src/SldStyleParser.v1.1.spec.ts b/src/SldStyleParser.v1.1.spec.ts new file mode 100644 index 00000000..a1871fa4 --- /dev/null +++ b/src/SldStyleParser.v1.1.spec.ts @@ -0,0 +1,898 @@ +/* eslint camelcase: 0 */ + +import * as fs from 'fs'; +import SldStyleParser from './SldStyleParser'; +import { Style } from 'geostyler-style'; + +import point_simplepoint from '../data/styles/point_simplepoint'; +import line_simpleline from '../data/styles/line_simpleline'; +import line_perpendicularOffset from '../data/styles/line_perpendicularOffset'; +import line_graphicStroke from '../data/styles/line_graphicStroke'; +import line_graphicStroke_externalGraphic from '../data/styles/line_graphicStroke_externalGraphic'; +import line_graphicFill from '../data/styles/line_graphicFill'; +import line_graphicFill_externalGraphic from '../data/styles/line_graphicFill_externalGraphic'; +import polygon_transparentpolygon from '../data/styles/polygon_transparentpolygon'; +import polygon_graphicFill from '../data/styles/polygon_graphicFill'; +import polygon_graphicFill_externalGraphic from '../data/styles/polygon_graphicFill_externalGraphic'; +import point_styledlabel from '../data/styles/point_styledlabel'; +import point_simpleLabel from '../data/styles/point_simpleLabel'; +import point_simplepoint_filter from '../data/styles/point_simplepoint_filter'; +import point_simplepoint_filter_forceBools from '../data/styles/point_simplepoint_filter_forceBools'; +import point_simplepoint_filter_forceNumerics from '../data/styles/point_simplepoint_filter_forceNumerics'; +import point_simplepoint_functionfilter from '../data/styles/point_simplepoint_functionfilter'; +import point_simplepoint_nestedLogicalFilters from '../data/styles/point_simplepoint_nestedLogicalFilters'; +import point_externalgraphic from '../data/styles/point_externalgraphic'; +import point_externalgraphic_floatingPoint from '../data/styles/point_externalgraphic_floatingPoint'; +import point_externalgraphic_svg from '../data/styles/point_externalgraphic_svg'; +import multi_simplelineLabel from '../data/styles/multi_simplelineLabel'; +import point_simplesquare from '../data/styles/point_simplesquare'; +import point_simpletriangle from '../data/styles/point_simpletriangle'; +import point_simplestar from '../data/styles/point_simplestar'; +import point_simplecross from '../data/styles/point_simplecross'; +import point_simplex from '../data/styles/point_simplex'; +import point_simpleslash from '../data/styles/point_simpleslash'; +import point_fontglyph from '../data/styles/point_fontglyph'; +import point_styledLabel_literalPlaceholder from '../data/styles/point_styledLabel_literalPlaceholder'; +import raster_simpleraster from '../data/styles/raster_simpleRaster'; +import raster_complexraster from '../data/styles/raster_complexRaster'; + +it('SldStyleParser is defined', () => { + expect(SldStyleParser).toBeDefined(); +}); + +describe('SldStyleParser with Symbology Encoding implements StyleParser', () => { + let styleParser: SldStyleParser; + + beforeEach(() => { + styleParser = new SldStyleParser({ + sldVersion: '1.1.0' + }); + }); + + describe('#readStyle', () => { + it('is defined', () => { + expect(styleParser.readStyle).toBeDefined(); + }); + it('can read a SLD 1.1 PointSymbolizer', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/point_simplepoint.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(point_simplepoint); + }); + }); + it('can read a SLD 1.1 PointSymbolizer with ExternalGraphic', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/point_externalgraphic.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(point_externalgraphic); + }); + }); + it('can read a SLD 1.1 PointSymbolizer with ExternalGraphic with floating-point values', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/point_externalgraphic_floatingPoint.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(point_externalgraphic_floatingPoint); + }); + }); + it('can read a SLD 1.1 PointSymbolizer with ExternalGraphic svg', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/point_externalgraphic_svg.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(point_externalgraphic_svg); + }); + }); + it('can read a SLD 1.1 PointSymbolizer with wellKnownName square', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/point_simplesquare.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(point_simplesquare); + }); + }); + it('can read a SLD 1.1 PointSymbolizer with wellKnownName triangle', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/point_simpletriangle.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(point_simpletriangle); + }); + }); + it('can read a SLD 1.1 PointSymbolizer with wellKnownName star', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/point_simplestar.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(point_simplestar); + }); + }); + it('can read a SLD 1.1 PointSymbolizer with wellKnownName cross', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/point_simplecross.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(point_simplecross); + }); + }); + it('can read a SLD 1.1 PointSymbolizer with wellKnownName x', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/point_simplex.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(point_simplex); + }); + }); + it('can read a SLD 1.1 PointSymbolizer with wellKnownName shape://slash', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/point_simpleslash.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(point_simpleslash); + }); + }); + it('can read a SLD 1.1 PointSymbolizer with wellKnownName using a font glyph (starting with ttf://)', () => { + expect.assertions(2); + const sld = fs.readFileSync( './data/slds/1.1/point_fontglyph.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(point_fontglyph); + }); + }); + it('can read a SLD 1.1 LineSymbolizer', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/line_simpleline.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(line_simpleline); + }); + }); + it('can read a SLD 1.1 LineSymbolizer with Perpendicular Offset', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/line_perpendicularOffset.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geostylerStyle: Style) => { + expect(geostylerStyle).toBeDefined(); + expect(geostylerStyle).toEqual(line_perpendicularOffset); + }); + }); + it('can read a SLD 1.1 LineSymbolizer with GraphicStroke', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/line_graphicStroke.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(line_graphicStroke); + }); + }); + it('can read a SLD 1.1 LineSymbolizer with GraphicStroke and ExternalGraphic', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/line_graphicStroke_externalGraphic.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(line_graphicStroke_externalGraphic); + }); + }); + it('can read a SLD 1.1 LineSymbolizer with GraphicFill', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/line_graphicFill.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(line_graphicFill); + }); + }); + it('can read a SLD 1.1 LineSymbolizer with GraphicFill and ExternalGraphic', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/line_graphicFill_externalGraphic.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(line_graphicFill_externalGraphic); + }); + }); + it('can read a SLD 1.1 PolygonSymbolizer', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/polygon_transparentpolygon.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(polygon_transparentpolygon); + }); + }); + it('can read a SLD 1.1 PolygonSymbolizer with GraphicFill', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/polygon_graphicFill.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(polygon_graphicFill); + }); + }); + it('can read a SLD 1.1 PolygonSymbolizer with GraphicFill and ExternalGraphic', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/polygon_graphicFill_externalGraphic.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(polygon_graphicFill_externalGraphic); + }); + }); + it('can read a SLD 1.1 TextSymbolizer', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/point_styledlabel.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(point_styledlabel); + }); + }); + it('can read a SLD 1.1 TextSymbolizer with a static label', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/point_simpleLabel.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(point_simpleLabel); + }); + }); + it('can read a simple SLD 1.1 RasterSymbolizer', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/raster_simpleRaster.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(raster_simpleraster); + }); + }); + it('can read a complex SLD 1.1 RasterSymbolizer', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/raster_complexRaster.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(raster_complexraster); + }); + }); + it('can read a SLD 1.1 style with a filter', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/point_simplepoint_filter.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(point_simplepoint_filter); + }); + }); + it('can read a SLD 1.1 style with nested logical filters', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/point_simplepoint_nestedLogicalFilters.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(point_simplepoint_nestedLogicalFilters); + }); + }); + it('can read a SLD 1.1 style with functionfilters', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/point_simplepoint_functionfilter.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(point_simplepoint_functionfilter); + }); + }); + it('can read a SLD 1.1 style with multiple symbolizers in one Rule', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/multi_simplelineLabel.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(multi_simplelineLabel); + }); + }); + it('can read a SLD 1.1 style with a styled label containing a PropertyName and a Literal', () => { + expect.assertions(2); + const sld = fs.readFileSync('./data/slds/1.1/point_styledLabel_literalPlaceholder.sld', 'utf8'); + return styleParser.readStyle(sld) + .then((geoStylerStyle: Style) => { + expect(geoStylerStyle).toBeDefined(); + expect(geoStylerStyle).toEqual(point_styledLabel_literalPlaceholder); + }); + }); + + describe('#getFilterFromOperatorAndComparison', () => { + it('is defined', () => { + expect(styleParser.getFilterFromOperatorAndComparison).toBeDefined(); + }); + }); + + describe('#getFilterFromRule', () => { + it('is defined', () => { + expect(styleParser.getFilterFromRule).toBeDefined(); + }); + }); + + describe('#getScaleDenominatorFromRule', () => { + it('is defined', () => { + expect(styleParser.getScaleDenominatorFromRule).toBeDefined(); + }); + }); + + describe('#getPointSymbolizerFromSldSymbolizer', () => { + it('is defined', () => { + expect(styleParser.getPointSymbolizerFromSldSymbolizer).toBeDefined(); + }); + }); + + describe('#getLineSymbolizerFromSldSymbolizer', () => { + it('is defined', () => { + expect(styleParser.getLineSymbolizerFromSldSymbolizer).toBeDefined(); + }); + }); + + describe('#getFillSymbolizerFromSldSymbolizer', () => { + it('is defined', () => { + expect(styleParser.getFillSymbolizerFromSldSymbolizer).toBeDefined(); + }); + }); + + describe('#getTextSymbolizerFromSldSymbolizer', () => { + it('is defined', () => { + expect(styleParser.getTextSymbolizerFromSldSymbolizer).toBeDefined(); + }); + }); + + describe('#getRasterSymbolizerFromSldSymbolizer', () => { + it('is defined', () => { + expect(styleParser.getRasterSymbolizerFromSldSymbolizer).toBeDefined(); + }); + }); + + describe('#getSymbolizersFromRule', () => { + it('is defined', () => { + expect(styleParser.getSymbolizersFromRule).toBeDefined(); + }); + }); + + describe('#getRulesFromSldObject', () => { + it('is defined', () => { + expect(styleParser.getRulesFromSldObject).toBeDefined(); + }); + }); + + describe('#sldObjectToGeoStylerStyle', () => { + it('is defined', () => { + expect(styleParser.sldObjectToGeoStylerStyle).toBeDefined(); + }); + }); + + describe('#getTextSymbolizerLabelFromSldSymbolizer', () => { + it('is defined', () => { + expect(styleParser.getTextSymbolizerLabelFromSldSymbolizer).toBeDefined(); + }); + }); + }); + + describe('#writeStyle', () => { + it('is defined', () => { + expect(styleParser.writeStyle).toBeDefined(); + }); + it('can write a SLD 1.1 PointSymbolizer', () => { + expect.assertions(2); + return styleParser.writeStyle(point_simplepoint) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_simplepoint); + }); + }); + }); + it('can write a SLD 1.1 PointSymbolizer with ExternalGraphic', () => { + expect.assertions(2); + return styleParser.writeStyle(point_externalgraphic) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_externalgraphic); + }); + }); + }); + it('can write a SLD 1.1 PointSymbolizer with ExternalGraphic svg', () => { + expect.assertions(2); + return styleParser.writeStyle(point_externalgraphic_svg) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_externalgraphic_svg); + }); + }); + }); + it('can write a SLD 1.1 PointSymbolizer with wellKnownName square', () => { + expect.assertions(2); + return styleParser.writeStyle(point_simplesquare) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_simplesquare); + }); + }); + }); + it('can write a SLD 1.1 PointSymbolizer with wellKnownName triangle', () => { + expect.assertions(2); + return styleParser.writeStyle(point_simpletriangle) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_simpletriangle); + }); + }); + }); + it('can write a SLD 1.1 PointSymbolizer with wellKnownName star', () => { + expect.assertions(2); + return styleParser.writeStyle(point_simplestar) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_simplestar); + }); + }); + }); + it('can write a SLD 1.1 PointSymbolizer with wellKnownName cross', () => { + expect.assertions(2); + return styleParser.writeStyle(point_simplecross) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_simplecross); + }); + }); + }); + it('can write a SLD 1.1 PointSymbolizer with wellKnownName x', () => { + expect.assertions(2); + return styleParser.writeStyle(point_simplex) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_simplex); + }); + }); + }); + it('can write a SLD 1.1 PointSymbolizer with wellKnownName shape://slash', () => { + expect.assertions(2); + return styleParser.writeStyle(point_simpleslash) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_simpleslash); + }); + }); + }); + it('can write a SLD 1.1 PointSymbolizer with wellKnownName using a font glyph (starting with ttf://)', () => { + expect.assertions(2); + return styleParser.writeStyle(point_fontglyph) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_fontglyph); + }); + }); + }); + it('can write a SLD 1.1 LineSymbolizer', () => { + expect.assertions(2); + return styleParser.writeStyle(line_simpleline) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(line_simpleline); + }); + }); + }); + it('can write a SLD 1.1 LineSymbolizer with PerpendicularOffset', () => { + expect.assertions(2); + return styleParser.writeStyle(line_perpendicularOffset) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(line_perpendicularOffset); + }); + }); + }); + it('can write a SLD 1.1 LineSymbolizer with GraphicStroke', () => { + expect.assertions(2); + return styleParser.writeStyle(line_graphicStroke) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(line_graphicStroke); + }); + }); + }); + it('can write a SLD 1.1 LineSymbolizer with GraphicStroke and ExternalGraphic', () => { + expect.assertions(2); + return styleParser.writeStyle(line_graphicStroke_externalGraphic) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(line_graphicStroke_externalGraphic); + }); + }); + }); + it('can write a SLD 1.1 LineSymbolizer with GraphicFill', () => { + expect.assertions(2); + return styleParser.writeStyle(line_graphicFill) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(line_graphicFill); + }); + }); + }); + it('can write a SLD 1.1 LineSymbolizer with GraphicFill and ExternalGraphic', () => { + expect.assertions(2); + return styleParser.writeStyle(line_graphicFill_externalGraphic) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(line_graphicFill_externalGraphic); + }); + }); + }); + it('can write a SLD 1.1 PolygonSymbolizer', () => { + expect.assertions(2); + return styleParser.writeStyle(polygon_transparentpolygon) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(polygon_transparentpolygon); + }); + }); + }); + it('can write a SLD 1.1 PolygonSymbolizer with GraphicFill', () => { + expect.assertions(2); + return styleParser.writeStyle(polygon_graphicFill) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(polygon_graphicFill); + }); + }); + }); + it('can write a SLD 1.1 PolygonSymbolizer with GraphicFill and ExternalGraphic', () => { + expect.assertions(2); + return styleParser.writeStyle(polygon_graphicFill_externalGraphic) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(polygon_graphicFill_externalGraphic); + }); + }); + }); + it('can write a SLD 1.1 TextSymbolizer', () => { + expect.assertions(2); + return styleParser.writeStyle(point_styledlabel) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_styledlabel); + }); + }); + }); + it('can write a simple SLD RasterSymbolizer', () => { + expect.assertions(2); + return styleParser.writeStyle(raster_simpleraster) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(raster_simpleraster); + }); + }); + }); + it('can write a complex SLD RasterSymbolizer', () => { + expect.assertions(2); + return styleParser.writeStyle(raster_complexraster) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(raster_complexraster); + }); + }); + }); + it('can write a SLD 1.1 style with a filter', () => { + expect.assertions(2); + return styleParser.writeStyle(point_simplepoint_filter) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_simplepoint_filter); + }); + }); + }); + it('can write a SLD 1.1 style with a filter and force cast of numeric fields', () => { + expect.assertions(2); + // force fields beeing casted to numeric data type + styleParser.numericFilterFields = ['POPULATION', 'TEST1', 'TEST2']; + return styleParser.writeStyle(point_simplepoint_filter_forceNumerics) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_simplepoint_filter_forceNumerics); + }); + }); + }); + it('can write a SLD 1.1 style with a filter and force cast of numeric fields (forceCasting)', () => { + expect.assertions(2); + styleParser.forceCasting = true; + return styleParser.writeStyle(point_simplepoint_filter_forceNumerics) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_simplepoint_filter_forceNumerics); + }); + }); + }); + it('can write a SLD 1.1 style with a filter and force cast of boolean fields', () => { + expect.assertions(2); + // force fields beeing casted to boolean data type + styleParser.boolFilterFields = ['TEST', 'TEST2']; + return styleParser.writeStyle(point_simplepoint_filter_forceBools) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_simplepoint_filter_forceBools); + }); + }); + }); + it('can write a SLD 1.1 style with a filter and force cast of boolean fields (forceCasting)', () => { + expect.assertions(2); + // force fields beeing casted to boolean data type + styleParser.forceCasting = true; + return styleParser.writeStyle(point_simplepoint_filter_forceBools) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_simplepoint_filter_forceBools); + }); + }); + }); + it('can write a SLD 1.1 style with nested logical filters', () => { + expect.assertions(2); + return styleParser.writeStyle(point_simplepoint_nestedLogicalFilters) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_simplepoint_nestedLogicalFilters); + }); + }); + }); + it('can write a SLD 1.1 style with functionfilters', () => { + expect.assertions(2); + return styleParser.writeStyle(point_simplepoint_functionfilter) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_simplepoint_functionfilter); + }); + }); + }); + it('can write a SLD 1.1 style with multiple symbolizers in one Rule', () => { + expect.assertions(2); + return styleParser.writeStyle(multi_simplelineLabel) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(multi_simplelineLabel); + }); + }); + }); + it('can write a SLD 1.1 style with a styled label containing a placeholder and static text', () => { + expect.assertions(2); + return styleParser.writeStyle(point_styledLabel_literalPlaceholder) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + // As string comparison between two XML-Strings is awkward and nonsens + // we read it again and compare the json input with the parser output + return styleParser.readStyle(sldString) + .then(readStyle => { + expect(readStyle).toEqual(point_styledLabel_literalPlaceholder); + }); + }); + }); + + it('can write a non-prettified SLD 1.1 by setting flag "prettyOutput" to false', () => { + expect.assertions(2); + const styleParserPrettyFalse = new SldStyleParser({ + sldVersion: '1.1.0', + prettyOutput: false + }); + return styleParserPrettyFalse.writeStyle(point_simplepoint) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + const sld = fs.readFileSync('./data/slds/1.1/point_simplepoint_oneline.sld', 'utf8'); + expect(sldString).toEqual(sld.trim()); + }); + }); + + it('creates the correct order in a text symbolizer', () => { + expect.assertions(2); + const styleParserOrder = new SldStyleParser({ sldVersion: '1.1.0' }); + return styleParserOrder.writeStyle(point_styledLabel_literalPlaceholder) + .then((sldString: string) => { + expect(sldString).toBeDefined(); + const sld = fs.readFileSync('./data/slds/1.1/point_styledLabel_elementOrder.sld', 'utf8'); + expect(sldString).toEqual(sld.trim()); + }); + }); + + describe('#geoStylerStyleToSldObject', () => { + it('is defined', () => { + expect(styleParser.geoStylerStyleToSldObject).toBeDefined(); + }); + }); + + describe('#getSldRulesFromRules', () => { + it('is defined', () => { + expect(styleParser.getSldRulesFromRules).toBeDefined(); + }); + }); + + describe('#getSldSymbolizersFromSymbolizers', () => { + it('is defined', () => { + expect(styleParser.getSldSymbolizersFromSymbolizers).toBeDefined(); + }); + }); + + describe('#getSldTextSymbolizerFromTextSymbolizer', () => { + it('is defined', () => { + expect(styleParser.getSldTextSymbolizerFromTextSymbolizer).toBeDefined(); + }); + }); + + describe('#getSldPolygonSymbolizerFromFillSymbolizer', () => { + it('is defined', () => { + expect(styleParser.getSldPolygonSymbolizerFromFillSymbolizer).toBeDefined(); + }); + }); + + describe('#getSldLineSymbolizerFromLineSymbolizer', () => { + it('is defined', () => { + expect(styleParser.getSldLineSymbolizerFromLineSymbolizer).toBeDefined(); + }); + }); + + describe('#getSldPointSymbolizerFromMarkSymbolizer', () => { + it('is defined', () => { + expect(styleParser.getSldPointSymbolizerFromMarkSymbolizer).toBeDefined(); + }); + }); + + describe('#getSldRasterSymbolizerFromRasterSymbolizer', () => { + it('is defined', () => { + expect(styleParser.getSldRasterSymbolizerFromRasterSymbolizer).toBeDefined(); + }); + }); + + describe('#getSldComparisonFilterFromComparisonFilte', () => { + it('is defined', () => { + expect(styleParser.getSldComparisonFilterFromComparisonFilter).toBeDefined(); + }); + }); + + describe('#getSldFilterFromFilter', () => { + it('is defined', () => { + expect(styleParser.getSldFilterFromFilter).toBeDefined(); + }); + }); + + describe('#getSldLabelFromTextSymbolizer', () => { + it('is defined', () => { + expect(styleParser.getSldLabelFromTextSymbolizer).toBeDefined(); + }); + }); + }); + +}); diff --git a/src/SymbologyEncoder.ts b/src/SymbologyEncoder.ts new file mode 100644 index 00000000..5a305655 --- /dev/null +++ b/src/SymbologyEncoder.ts @@ -0,0 +1,108 @@ +import { + Style +} from 'geostyler-style'; + +/** + * Class helping to transform from SLD 1.0.0 to SLD 1.1.0 / Synbology Encoding + * + * @class SymbologyEncoder + */ +export class SymbologyEncoder { + + /** + * Methods returns Symbology Encoding / SLD 1.1.0 from given GeoStyler + * style Object + * @param {Style} geoStylerStyle A GeoStyler-Style Style. + * @param {Rule[]} rules The array of rules + * @param {string} symbolizerUnits The units to use for symbolizers + * @returns {object} The object representation of a SLD 1.1 Style + * (readable with xml2js) + */ + static getSymbologyEncoding(geoStylerStyle: Style, rules: any[], + symbolizerUnits: string): any { + const setTags = (rulez: any[], isFilterElement: boolean) => { + if (!(rulez instanceof Array)) { + rulez = [rulez]; + } + rulez.forEach((rule: any) => { + const keys = Object.keys(rule); + for (const key of keys) { + const val = rule[key][0]; + // handle renaming of ogc filter attributes + if (key.toLowerCase() === 'filter') { + delete Object.assign(rule, {['ogc:' + key]: rule[key]})[key]; + setTags(rule['ogc:' + key], true); + continue; + } + if (isFilterElement) { + if (key.toLowerCase().indexOf('property') > -1) { + rule[key].forEach((el: any) => { + if (el.$ && el.$.escape) { + // rename escape attribute + el.$.escapeChar = el.$.escape; + delete el.$.escape; + } + }); + } + } + // do not change special attribute handlers or ogc namespaces + if (key === '$' || key === '_' || + key.toLowerCase().indexOf('ogc:') > -1 || + (rule[key].$ && rule[key].$.xmlns)) { + if (val instanceof Object) { + setTags([rule[key]], isFilterElement); + } + continue; + } + // add uom attribute to symbolizers + if (key.toLowerCase().indexOf('symbolizer') > -1) { + val.$ = { + uom: 'http://www.opengeospatial.org/se/units/' + + symbolizerUnits + }; + } + + if (key.toLowerCase() === 'cssparameter') { + // change naming of css and svg parameters + delete Object.assign(rule, {['se:SvgParameter']: rule[key]})[key]; + continue; + } else if (!isFilterElement) { + // rename all other tags to include the "se" namespace + delete Object.assign(rule, {['se:' + key]: rule[key]})[key]; + } + // recursive call ourselves + if (val instanceof Object) { + setTags([val], isFilterElement); + } + } + }); + }; + + setTags(rules, false); + + return { + StyledLayerDescriptor: { + '$': { + 'version': '1.1.0', + 'xsi:schemaLocation': 'http://www.opengis.net/sld StyledLayerDescriptor.xsd', + 'xmlns': 'http://www.opengis.net/sld', + 'xmlns:ogc': 'http://www.opengis.net/ogc', + 'xmlns:xlink': 'http://www.w3.org/1999/xlink', + 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance', + 'xmlns:se': 'http://www.opengis.net/se' + }, + 'NamedLayer': [{ + 'se:Name': [geoStylerStyle.name || ''], + 'UserStyle': [{ + 'se:Name': [geoStylerStyle.name || ''], + 'se:FeatureTypeStyle': [{ + 'se:Rule': rules + }] + }] + }] + } + }; + } +} + +export default SymbologyEncoder;