forked from geosolutions-it/MapStore2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStyleParserUtils-test.js
More file actions
215 lines (197 loc) · 8.82 KB
/
StyleParserUtils-test.js
File metadata and controls
215 lines (197 loc) · 8.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
* Copyright 2019, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import expect from 'expect';
import {
getImageIdFromSymbolizer,
geoStylerStyleFilter,
getWellKnownNameImageFromSymbolizer,
parseSymbolizerExpressions,
getCachedImageById,
geoStylerScaleDenominatorFilter
} from '../StyleParserUtils';
describe("StyleParserUtils ", () => {
it('should create an image id based on Icon or Mark symbolizers', () => {
expect(getImageIdFromSymbolizer({
kind: 'Mark',
wellKnownName: 'Circle',
color: '#ff0000',
fillOpacity: 0.5,
strokeColor: '#00ff00',
strokeOpacity: 0.25,
strokeWidth: 3,
radius: 16,
rotate: 90
})).toBe('Circle:#ff0000:0.5:#00ff00:0.25::3:16');
expect(getImageIdFromSymbolizer({
kind: 'Icon',
image: 'path/to/image',
opacity: 0.5,
size: 32,
rotate: 90
})).toBe('path/to/image');
const parsedSymbolizer = {"symbolizerId": "df2715d2-8ecb-11ee-909e-8bd5d708e385", "kind": "Icon", "image": "data:image/png;base64,iVBORcmGtfaAAAAABJRU5ErkJggg==", "opacity": 1, "size": 46, "rotate": 0, "msBringToFront": false, "anchor": "bottom", "msHeightReference": "none"};
const originalSymbolizer = {"symbolizerId": "df2715d2-8ecb-11ee-909e-8bd5d708e385", "kind": "Icon", "image": {"name": "msMarkerIcon", "args": [{"glyph": "power-off", "color": "purple", "shape": "square"}]}, "opacity": 1, "size": 46, "rotate": 0, "msBringToFront": false, "anchor": "bottom", "msHeightReference": "none"};
expect(getImageIdFromSymbolizer(parsedSymbolizer, originalSymbolizer)).toEqual("msMarkerIcon:purple:square:power-off");
});
it('should read filter expression applied to a feature properties using geoStylerStyleFilter', () => {
const feature = { properties: { count: 10, name: 'Abc' } };
expect(geoStylerStyleFilter(feature, ['==', 'count', 10])).toBe(true);
expect(geoStylerStyleFilter(feature, ['!=', 'count', 10])).toBe(false);
expect(geoStylerStyleFilter(feature, ['>=', 'count', 10])).toBe(true);
expect(geoStylerStyleFilter(feature, ['<=', 'count', 10])).toBe(true);
expect(geoStylerStyleFilter(feature, ['<', 'count', 10])).toBe(false);
expect(geoStylerStyleFilter(feature, ['>', 'count', 10])).toBe(false);
expect(geoStylerStyleFilter(feature, ['*=', 'name', 'A'])).toBe(true);
expect(geoStylerStyleFilter(feature, ['*=', 'name', 'd'])).toBe(false);
expect(geoStylerStyleFilter(feature, ['||', ['*=', 'name', 'd'], ['<', 'count', 10]])).toBe(false);
expect(geoStylerStyleFilter(feature, ['||', ['*=', 'name', 'd'], ['<=', 'count', 10]])).toBe(true);
expect(geoStylerStyleFilter(feature, ['&&', ['*=', 'name', 'd'], ['<=', 'count', 10]])).toBe(false);
expect(geoStylerStyleFilter(feature, ['&&', ['*=', 'name', 'A'], ['<=', 'count', 10]])).toBe(true);
});
it('should render an image if a mark symbolizer use an svg as wellKnownName property', (done) => {
getWellKnownNameImageFromSymbolizer({
"kind": "Mark",
"wellKnownName": "base/web/client/test-resources/symbols/stop-hexagonal-signal.svg",
"color": "#ff1887",
"fillOpacity": 1,
"strokeColor": "#1329ff",
"strokeOpacity": 1,
"strokeWidth": 4,
"radius": 32,
"rotate": 0,
"msBringToFront": true,
"msHeightReference": "none",
"strokeDasharray": [8, 8]
})
.then(({ id, image, src, width, height }) => {
expect(id).toBeTruthy();
expect(width).toBe(68);
expect(height).toBe(68);
expect(image).toBeTruthy();
expect(src).toBeTruthy();
done();
})
.catch(done);
});
it('parse symbolizers using expressions', () => {
expect(parseSymbolizerExpressions({
kind: 'Icon',
image: {
name: 'msMarkerIcon',
args: [
{
color: 'blue'
}
]
}
}, { properties: {} }).image.includes('data:image/png;base64')).toBe(true);
expect(parseSymbolizerExpressions(
{
kind: 'Circle',
color: '#ff0000',
opacity: 0.5,
outlineColor: '#00ff00',
outlineWidth: 2,
radius: {
name: 'property',
args: [
'radius'
]
},
geodesic: {
name: 'property',
args: [
'geodesic'
]
},
outlineOpacity: 0.25,
outlineDasharray: [10, 10]
},
{
properties: {
geodesic: true,
radius: 1000000
}
}
))
.toEqual({
kind: 'Circle',
color: '#ff0000',
opacity: 0.5,
outlineColor: '#00ff00',
outlineWidth: 2,
radius: 1000000,
geodesic: true,
outlineOpacity: 0.25,
outlineDasharray: [ 10, 10 ]
});
});
it('test getCachedImageById method for Icon annotationSymbolizer to return width, height = size in case of returning undefined from getCachedImageById', () => {
const annotationSymbolizer = {
"symbolizerId": "5ba7eae188a0",
"kind": "Icon",
"image": {
"name": "msMarkerIcon",
"args": [
{
"color": "blue",
"shape": "circle",
"glyph": "comment"
}
]
},
"opacity": 1,
"size": 46,
"rotate": 0,
"msBringToFront": false,
"anchor": "bottom",
"msHeightReference": "none"
};
const { width = annotationSymbolizer.size, height = annotationSymbolizer.size } = getCachedImageById(annotationSymbolizer);
expect(width).toBe(annotationSymbolizer.size);
expect(height).toBe(annotationSymbolizer.size);
});
// tests for geoStylerScaleDenominatorFilter
describe('geoStylerScaleDenominatorFilter', () => {
it('returns true when scale is within [min, max] range -> max excluded and min included', () => {
const rule = { scaleDenominator: { min: 1000, max: 10000 } };
expect(geoStylerScaleDenominatorFilter(rule, 1000)).toBe(true); // min included
expect(geoStylerScaleDenominatorFilter(rule, 5000)).toBe(true);
expect(geoStylerScaleDenominatorFilter(rule, 10000)).toBe(false); // max is excluded
});
it('returns false when scale is outside [min, max] range', () => {
const rule = { scaleDenominator: { min: 1000, max: 10000 } };
expect(geoStylerScaleDenominatorFilter(rule, 500)).toBe(false);
expect(geoStylerScaleDenominatorFilter(rule, 50000)).toBe(false);
});
it('works with only min or only max defined', () => {
const minOnly = { scaleDenominator: { min: 5000 } };
const maxOnly = { scaleDenominator: { max: 5000 } };
expect(geoStylerScaleDenominatorFilter(minOnly, 10000)).toBe(true);
expect(geoStylerScaleDenominatorFilter(minOnly, 1000)).toBe(false);
expect(geoStylerScaleDenominatorFilter(maxOnly, 1000)).toBe(true);
expect(geoStylerScaleDenominatorFilter(maxOnly, 10000)).toBe(false);
});
it('returns true when no scale filter or no mapViewScale provided', () => {
expect(geoStylerScaleDenominatorFilter({}, 5000)).toBe(true);
expect(geoStylerScaleDenominatorFilter({ scaleDenominator: {} }, 5000)).toBe(true);
expect(geoStylerScaleDenominatorFilter({ scaleDenominator: { min: 1000 } }, undefined)).toBe(true);
});
it('works with real-world rule structure', () => {
const rule = {
symbolizerId: "rule-001",
kind: "Fill",
color: "#3388FF",
scaleDenominator: { min: 2500, max: 25000 }
};
expect(geoStylerScaleDenominatorFilter(rule, 1000)).toBe(false);
expect(geoStylerScaleDenominatorFilter(rule, 10000)).toBe(true);
expect(geoStylerScaleDenominatorFilter(rule, 50000)).toBe(false);
});
});
});