Skip to content

Commit 1b03a5f

Browse files
committed
add text toggle for some cases
1 parent ee82927 commit 1b03a5f

File tree

4 files changed

+121
-13
lines changed

4 files changed

+121
-13
lines changed

cases/line-rendering/main.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ const source = new VectorSource({
1616
});
1717

1818
/**
19-
*
2019
* @type {import('ol/style/flat.js').FlatStyle}
2120
*/
22-
const style = {
21+
const baseStyle = {
2322
'stroke-width': ['get', 'width'],
2423
'stroke-color': ['get', 'color'],
2524
'stroke-line-dash': [15, 15],
25+
};
26+
27+
/**
28+
* @type {import('ol/style/flat.js').FlatStyle}
29+
*/
30+
const textStyle = {
2631
'text-value': ['get', 'label'],
2732
'text-font': 'bold 12px "Open Sans", "Arial Unicode MS", sans-serif',
2833
'text-fill-color': '#333',
@@ -44,18 +49,24 @@ function resetData(lineCount, curveComplexity, width) {
4449
function main() {
4550
createMap(
4651
(map) => {
52+
const style = getGuiParameterValue('text')
53+
? {...baseStyle, ...textStyle}
54+
: baseStyle;
4755
map.addLayer(new WebGLVectorLayer({source, properties: {style}}));
4856
},
4957
(map) => {
58+
const style = getGuiParameterValue('text')
59+
? {...baseStyle, ...textStyle}
60+
: baseStyle;
5061
map.addLayer(new VectorLayer({source, style}));
5162
},
5263
);
5364
initializeGui();
5465
registerGuiParameter(
5566
'count',
5667
'Line count',
57-
[2, 100, 10],
58-
2,
68+
[2, 10000, 10],
69+
10,
5970
(value, initial) => {
6071
if (initial) {
6172
return;
@@ -100,9 +111,21 @@ function main() {
100111
false,
101112
(value, initial) => {
102113
if (value) {
103-
style['stroke-line-dash'] = [15, 15];
114+
baseStyle['stroke-line-dash'] = [15, 15];
104115
} else {
105-
delete style['stroke-line-dash'];
116+
delete baseStyle['stroke-line-dash'];
117+
}
118+
regenerateLayer();
119+
},
120+
);
121+
registerGuiParameter(
122+
'text',
123+
'Show labels',
124+
['yes', 'no'],
125+
false,
126+
(value, initial) => {
127+
if (initial) {
128+
return;
106129
}
107130
regenerateLayer();
108131
},

cases/point-rendering/main.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
generatePoints,
88
getGuiParameterValue,
99
initializeGui,
10+
regenerateLayer,
1011
registerGuiParameter,
1112
} from '../common.js';
1213

@@ -17,12 +18,18 @@ const source = new VectorSource({
1718
/**
1819
* @type {import('ol/style/flat.js').FlatStyle}
1920
*/
20-
const style = {
21+
const baseStyle = {
2122
// This has to be fixed upstream
2223
'circle-radius': ['get', 'radius'],
2324
'circle-fill-color': ['get', 'color'],
2425
'circle-stroke-color': 'gray',
2526
'circle-stroke-width': 0.5,
27+
};
28+
29+
/**
30+
* @type {import('ol/style/flat.js').FlatStyle}
31+
*/
32+
const textStyle = {
2633
'text-value': ['get', 'label'],
2734
'text-font': 'bold 12px "Open Sans", "Arial Unicode MS", sans-serif',
2835
'text-fill-color': '#333',
@@ -43,9 +50,15 @@ function resetData(count, radius) {
4350
function main() {
4451
createMap(
4552
(map) => {
53+
const style = getGuiParameterValue('text')
54+
? {...baseStyle, ...textStyle}
55+
: baseStyle;
4656
map.addLayer(new WebGLVectorLayer({source, properties: {style}}));
4757
},
4858
(map) => {
59+
const style = getGuiParameterValue('text')
60+
? {...baseStyle, ...textStyle}
61+
: baseStyle;
4962
map.addLayer(new VectorLayer({source, style}));
5063
},
5164
);
@@ -74,6 +87,18 @@ function main() {
7487
/** @type {number} */ (value),
7588
);
7689
});
90+
registerGuiParameter(
91+
'text',
92+
'Show labels',
93+
['yes', 'no'],
94+
false,
95+
(value, initial) => {
96+
if (initial) {
97+
return;
98+
}
99+
regenerateLayer();
100+
},
101+
);
77102

78103
resetData(
79104
/** @type {number} */ (getGuiParameterValue('count')),

cases/polygon-rendering/main.js

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const source = new VectorSource({
1818
/**
1919
* @type {import('ol/style/flat.js').FlatStyle}
2020
*/
21-
const style = {
21+
const baseStyle = {
2222
'fill-color': ['get', 'color'],
2323
'text-value': ['get', 'label'],
2424
'text-font': 'bold 12px "Open Sans", "Arial Unicode MS", sans-serif',
@@ -27,6 +27,18 @@ const style = {
2727
'text-stroke-width': 2,
2828
};
2929

30+
/**
31+
* @type {import('ol/style/flat.js').FlatStyle}
32+
*/
33+
const textStyle = {
34+
'text-value': ['get', 'label'],
35+
'text-font': 'bold 12px "Open Sans", "Arial Unicode MS", sans-serif',
36+
'text-fill-color': '#333',
37+
'text-stroke-color': 'rgba(255,255,255,0.8)',
38+
'text-stroke-width': 2,
39+
'text-offset-y': -12,
40+
};
41+
3042
/**
3143
* @param {number} count The number of features to create.
3244
* @param {number} numVertices Number of vertices for polygons
@@ -38,9 +50,15 @@ function resetData(count, numVertices) {
3850
function main() {
3951
createMap(
4052
(map) => {
53+
const style = getGuiParameterValue('text')
54+
? {...baseStyle, ...textStyle}
55+
: baseStyle;
4156
map.addLayer(new WebGLVectorLayer({source, properties: {style}}));
4257
},
4358
(map) => {
59+
const style = getGuiParameterValue('text')
60+
? {...baseStyle, ...textStyle}
61+
: baseStyle;
4462
map.addLayer(new VectorLayer({source, style}));
4563
},
4664
);
@@ -82,11 +100,23 @@ function main() {
82100
true,
83101
(value, initial) => {
84102
if (value) {
85-
style['stroke-width'] = 2;
86-
style['stroke-color'] = 'gray';
103+
baseStyle['stroke-width'] = 2;
104+
baseStyle['stroke-color'] = 'gray';
87105
} else {
88-
delete style['stroke-width'];
89-
delete style['stroke-color'];
106+
delete baseStyle['stroke-width'];
107+
delete baseStyle['stroke-color'];
108+
}
109+
regenerateLayer();
110+
},
111+
);
112+
registerGuiParameter(
113+
'text',
114+
'Show labels',
115+
['yes', 'no'],
116+
false,
117+
(value, initial) => {
118+
if (initial) {
119+
return;
90120
}
91121
regenerateLayer();
92122
},

cases/vector-tiles-rendering/main.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ const format = new GeoJSON({featureProjection: 'EPSG:3857'});
2626

2727
const defaultStylesCount = 10;
2828

29+
/**
30+
* @type {Array<import('ol/style/flat.js').Rule>}
31+
*/
32+
const textStyles = [
33+
{
34+
style: {
35+
'text-value': ['get', 'label'],
36+
'text-font': 'bold 12px "Open Sans", "Arial Unicode MS", sans-serif',
37+
'text-fill-color': '#333',
38+
'text-stroke-color': 'rgba(255,255,255,0.8)',
39+
'text-stroke-width': 2,
40+
},
41+
},
42+
];
43+
2944
/**
3045
* @type {function(): Array<import('ol/style/flat.js').Rule>|import('ol/style/flat.js').FlatStyle}
3146
*/
@@ -62,7 +77,7 @@ function generateStyle() {
6277
'circle-stroke-width': 2,
6378
};
6479
}
65-
return new Array(totalStylesCount).fill(0).map((_, i) => {
80+
const colorStyles = new Array(totalStylesCount).fill(0).map((_, i) => {
6681
const color = getRandomColor();
6782
return {
6883
style: {
@@ -83,6 +98,9 @@ function generateStyle() {
8398
filter: ['==', ['get', 'propValue'], i],
8499
};
85100
});
101+
return getGuiParameterValue('text')
102+
? [...colorStyles, ...textStyles]
103+
: colorStyles;
86104
}
87105

88106
/**
@@ -322,6 +340,18 @@ function main() {
322340
source.setKey(Date.now().toString());
323341
},
324342
);
343+
registerGuiParameter(
344+
'text',
345+
'Show labels',
346+
['yes', 'no'],
347+
false,
348+
(value, initial) => {
349+
if (initial) {
350+
return;
351+
}
352+
regenerateLayer();
353+
},
354+
);
325355
}
326356

327357
main();

0 commit comments

Comments
 (0)