Skip to content

Commit

Permalink
Add fixtures and test cases for font-based mark symbolizers
Browse files Browse the repository at this point in the history
  • Loading branch information
jahow committed Jun 18, 2020
1 parent 3822963 commit a1fa4bb
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
19 changes: 19 additions & 0 deletions data/olStyles/point_fontglyph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import OlStyle from 'ol/style/Style';
import OlStyleText from 'ol/style/Text';
import OlStyleFill from 'ol/style/Fill';
import OlStyleStroke from 'ol/style/Stroke';

const olFontGlyph = new OlStyle({
text: new OlStyleText({
text: '|',
font: 'Normal 12px \'My Font Name\', geostyler-mark-symbolizer',
fill: new OlStyleFill({
color: '#FF0000'
}),
stroke: new OlStyleStroke({
color: '#112233'
})
})
});

export default olFontGlyph;
20 changes: 20 additions & 0 deletions data/styles/point_fontglyph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Style } from 'geostyler-style';

const pointFontglyph: Style = {
name: 'OL Style',
rules: [
{
name: 'OL Style Rule 0',
symbolizers: [{
kind: 'Mark',
wellKnownName: 'ttf://My Font Name#0x7c',
color: '#FF0000',
radius: 12,
rotate: 0,
strokeColor: '#112233'
}]
}
]
};

export default pointFontglyph;
32 changes: 32 additions & 0 deletions src/OlStyleParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import scaleDenomLineCircle from '../data/styles/scaleDenom_line_circle';
import scaleDenomLineCircleOverlap from '../data/styles/scaleDenom_line_circle_overlap';
import polygon_transparentpolygon from '../data/styles/polygon_transparentpolygon';
import point_styledlabel from '../data/styles/point_styledlabel';
import point_fontglyph from '../data/styles/point_fontglyph';
import ol_point_simplepoint from '../data/olStyles/point_simplepoint';
import ol_point_icon from '../data/olStyles/point_icon';
import ol_point_simplesquare from '../data/olStyles/point_simplesquare';
Expand All @@ -54,6 +55,7 @@ import ol_line_simpleline from '../data/olStyles/line_simpleline';
import ol_polygon_transparentpolygon from '../data/olStyles/polygon_transparentpolygon';
import ol_multi_simplefillSimpleline from '../data/olStyles/multi_simplefillSimpleline';
import ol_point_styledLabel_static from '../data/olStyles/point_styledLabel_static';
import ol_point_fontglyph from '../data/olStyles/point_fontglyph';
import {
LineSymbolizer,
FillSymbolizer,
Expand Down Expand Up @@ -287,6 +289,14 @@ describe('OlStyleParser implements StyleParser', () => {
// expect(geoStylerStyle).toEqual(point_simplepoint_filter);
// });
// });
it('can read a OpenLayers MarkSymbolizer based on a font glyph (WellKnownName starts with ttf://)', () => {
expect.assertions(2);
return styleParser.readStyle(ol_point_fontglyph)
.then((geoStylerStyle: Style) => {
expect(geoStylerStyle).toBeDefined();
expect(geoStylerStyle).toEqual(point_fontglyph);
});
});

describe('#olStyleToGeoStylerStyle', () => {
it('is defined', () => {
Expand Down Expand Up @@ -760,6 +770,28 @@ describe('OlStyleParser implements StyleParser', () => {
expect(olTimesFill.getColor()).toEqual(expecSymb.color);
});
});
it('can write a OpenLayers Style based on a font glyph (WellKnownName starts with ttf://)', () => {
expect.assertions(8);
return styleParser.writeStyle(point_fontglyph)
.then((olStyle: OlStyle) => {
expect(olStyle).toBeDefined();

const expecSymb = point_fontglyph.rules[0].symbolizers[0] as MarkSymbolizer;
const olText: OlStyleText = olStyle.getText();
expect(olText).toBeDefined();

expect(olText.getFont()).toBe('Normal 12px \'My Font Name\', geostyler-mark-symbolizer');
expect(olText.getText()).toBe('|');

const olTextFill: OlStyleFill = olText.getFill();
expect(olTextFill).toBeDefined();
expect(olTextFill.getColor()).toEqual(expecSymb.color);

const olTextStroke: OlStyleStroke = olText.getStroke();
expect(olTextStroke).toBeDefined();
expect(olTextStroke.getColor()).toEqual(expecSymb.strokeColor);
});
});
it('can write a OpenLayers LineSymbolizer', () => {
expect.assertions(5);
return styleParser.writeStyle(line_simpleline)
Expand Down

0 comments on commit a1fa4bb

Please sign in to comment.