@@ -8,10 +8,11 @@ import { expect, it, describe } from 'vitest';
88import point_simplepoint from '../data/styles/point_simplepoint' ;
99// @ts -ignore
1010import cdata from '../data/styles/cdata' ;
11+ import { TextSymbolizer } from 'geostyler-style' ;
1112
1213describe ( 'SldStyleParser implements StyleParser (reading from one version and writing to another version)' , ( ) => {
1314 it ( 'can read and write a SLD PointSymbolizer (from 1.0.0 version to 1.1.0 version)' , async ( ) => {
14- const styleParser = new SldStyleParser ( { sldVersion : '1.1.0' } ) ;
15+ const styleParser = new SldStyleParser ( { sldVersion : '1.1.0' } ) ;
1516
1617 const sld = fs . readFileSync ( './data/slds/1.0/point_simplepoint.sld' , 'utf8' ) ;
1718 const { output : geoStylerStyle } = await styleParser . readStyle ( sld ) ;
@@ -32,7 +33,7 @@ describe('SldStyleParser implements StyleParser (reading from one version and wr
3233 expect ( readStyle ) . toEqual ( point_simplepoint ) ;
3334 } ) ;
3435 it ( 'can read and write a SLD PointSymbolizer (from 1.1.0 version to 1.0.0 version)' , async ( ) => {
35- const styleParser = new SldStyleParser ( { sldVersion : '1.0.0' } ) ;
36+ const styleParser = new SldStyleParser ( { sldVersion : '1.0.0' } ) ;
3637
3738 const sld = fs . readFileSync ( './data/slds/1.1/point_simplepoint.sld' , 'utf8' ) ;
3839 const { output : geoStylerStyle } = await styleParser . readStyle ( sld ) ;
@@ -67,33 +68,54 @@ describe('SldStyleParser implements StyleParser (reading from one version and wr
6768
6869describe ( 'Test Anchor-Point-Conversions' , ( ) => {
6970 it ( 'transforms the sld-Anchorpoint-values to geostyler-anchors' , async ( ) => {
70- const test1 = new SldStyleParser ( ) . getAnchorFromSldAnchorPoint ( 0.0 , 0.0 ) ;
71+ const test1 = new SldStyleParser ( ) . getAnchorFromSldAnchorPoint ( 0.0 , 0.0 ) ;
7172 expect ( test1 ) . toEqual ( 'bottom-left' ) ;
72- const test2 = new SldStyleParser ( ) . getAnchorFromSldAnchorPoint ( 1.0 , 1.0 ) ;
73+ const test2 = new SldStyleParser ( ) . getAnchorFromSldAnchorPoint ( 1.0 , 1.0 ) ;
7374 expect ( test2 ) . toEqual ( 'top-right' ) ;
74- const test3 = new SldStyleParser ( ) . getAnchorFromSldAnchorPoint ( 0.5 , 1.0 ) ;
75+ const test3 = new SldStyleParser ( ) . getAnchorFromSldAnchorPoint ( 0.5 , 1.0 ) ;
7576 expect ( test3 ) . toEqual ( 'top' ) ;
76- const test4 = new SldStyleParser ( ) . getAnchorFromSldAnchorPoint ( 0.45 , 0.9 ) ;
77+ const test4 = new SldStyleParser ( ) . getAnchorFromSldAnchorPoint ( 0.45 , 0.9 ) ;
7778 expect ( test4 ) . toEqual ( 'top' ) ;
78- const test5 = new SldStyleParser ( ) . getAnchorFromSldAnchorPoint ( 0.5 , 0.5 ) ;
79+ const test5 = new SldStyleParser ( ) . getAnchorFromSldAnchorPoint ( 0.5 , 0.5 ) ;
7980 expect ( test5 ) . toBeUndefined ( ) ;
80- const test6 = new SldStyleParser ( ) . getAnchorFromSldAnchorPoint ( undefined , undefined ) ;
81+ const test6 = new SldStyleParser ( ) . getAnchorFromSldAnchorPoint ( undefined , undefined ) ;
8182 expect ( test6 ) . toBeUndefined ( ) ;
8283 } ) ;
8384 it ( 'transformes the geostyler-anchors to sld-Anchopoint-values' , async ( ) => {
84- const test1 = new SldStyleParser ( ) . getSldAnchorPointFromAnchor ( 'bottom-left' , 'x' ) ;
85+ const test1 = new SldStyleParser ( ) . getSldAnchorPointFromAnchor ( 'bottom-left' , 'x' ) ;
8586 expect ( test1 ) . toEqual ( 0.0 ) ;
86- const test2 = new SldStyleParser ( ) . getSldAnchorPointFromAnchor ( 'bottom-left' , 'y' ) ;
87+ const test2 = new SldStyleParser ( ) . getSldAnchorPointFromAnchor ( 'bottom-left' , 'y' ) ;
8788 expect ( test2 ) . toEqual ( 0.0 ) ;
88- const test3 = new SldStyleParser ( ) . getSldAnchorPointFromAnchor ( 'bottom' , 'x' ) ;
89+ const test3 = new SldStyleParser ( ) . getSldAnchorPointFromAnchor ( 'bottom' , 'x' ) ;
8990 expect ( test3 ) . toEqual ( 0.5 ) ;
90- const test4 = new SldStyleParser ( ) . getSldAnchorPointFromAnchor ( 'bottom' , 'y' ) ;
91+ const test4 = new SldStyleParser ( ) . getSldAnchorPointFromAnchor ( 'bottom' , 'y' ) ;
9192 expect ( test4 ) . toEqual ( 0.0 ) ;
92- const test5 = new SldStyleParser ( ) . getSldAnchorPointFromAnchor ( 'center' , 'x' ) ;
93+ const test5 = new SldStyleParser ( ) . getSldAnchorPointFromAnchor ( 'center' , 'x' ) ;
9394 expect ( test5 ) . toEqual ( 0.5 ) ;
94- const test6 = new SldStyleParser ( ) . getSldAnchorPointFromAnchor ( 'center' , 'y' ) ;
95+ const test6 = new SldStyleParser ( ) . getSldAnchorPointFromAnchor ( 'center' , 'y' ) ;
9596 expect ( test6 ) . toEqual ( 0.5 ) ;
96- const test7 = new SldStyleParser ( ) . getAnchorFromSldAnchorPoint ( undefined , 'x' ) ;
97+ const test7 = new SldStyleParser ( ) . getAnchorFromSldAnchorPoint ( undefined , 'x' ) ;
9798 expect ( test7 ) . toBeUndefined ( ) ;
9899 } ) ;
99100} ) ;
101+
102+ describe ( 'Diplacement parsing works with `pareTagValue: false` option' , async ( ) => {
103+ let styleParser : SldStyleParser ;
104+ it ( 'parses the displacement values as numbers' , async ( ) => {
105+ const sld = fs . readFileSync ( './data/slds/1.0/text_displacement.sld' , 'utf8' ) ;
106+ styleParser = new SldStyleParser ( {
107+ sldVersion : '1.0.0' ,
108+ parserOptions : {
109+ parseTagValue : false
110+ }
111+ } ) ;
112+ const { output : geoStylerStyle } = await styleParser . readStyle ( sld ) ;
113+ expect ( geoStylerStyle ) . toBeDefined ( ) ;
114+ const symbolizer = geoStylerStyle ?. rules ?. [ 0 ] ?. symbolizers ?. [ 0 ] as TextSymbolizer ;
115+ expect ( symbolizer ) . toBeDefined ( ) ;
116+ // beware that in SLD positive y values mean a displacement to the top,
117+ // whereas in geostyler-style positive y values mean a displacement to the bottom,
118+ // thus the y value is inverted
119+ expect ( symbolizer . offset ) . toEqual ( [ - 20 , - 10 ] ) ;
120+ } ) ;
121+ } ) ;
0 commit comments