Skip to content

Commit 51b6c1f

Browse files
committed
Add labels on geometries & show them in the various examples
1 parent 55e03cf commit 51b6c1f

File tree

6 files changed

+37
-2
lines changed

6 files changed

+37
-2
lines changed

cases/common.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
trackPerformance,
77
// @ts-ignore
88
} from '@camptocamp/rendering-analyzer';
9+
import randomName from '@scaleway/random-name';
910
import lilGui from 'lil-gui';
1011
import Map from 'ol/Map.js';
1112
import View from 'ol/View.js';
@@ -164,11 +165,13 @@ export function generatePolygons(count, numVertices) {
164165
// Close the polygon by adding the first vertex at the end
165166
polygonCoordinates.push(polygonCoordinates[0]);
166167

168+
const label = `This area covers ${randomName()}`;
167169
features.push({
168170
type: 'Feature',
169171
properties: {
170172
color: getRandomPaletteColor(),
171173
ratio: Math.round(Math.random() * 100),
174+
label,
172175
},
173176
geometry: {
174177
type: 'Polygon',
@@ -197,11 +200,13 @@ export function generatePoints(count, radius) {
197200
for (let lon = -180; lon < 180 - size / 4; lon += size) {
198201
for (let lat = -90; lat < 90 - size / 4; lat += size) {
199202
const buffer = (0.3 + Math.random() * 0.2) * size * (radius / 5); // Increase the buffer for larger points
203+
const label = randomName();
200204
features.push({
201205
type: 'Feature',
202206
properties: {
203207
color: getRandomPaletteColor(),
204208
radius,
209+
label,
205210
},
206211
geometry: {
207212
type: 'Point',
@@ -254,11 +259,13 @@ export function generateLines(lineCount, curveComplexity, width) {
254259
}
255260
coordinates.push(...singleCurve);
256261
}
262+
const label = `This leads to ${randomName()}`;
257263
features.push({
258264
type: 'Feature',
259265
properties: {
260266
color: getRandomPaletteColor(), // Use deterministic color selection
261267
width,
268+
label,
262269
},
263270
geometry: {
264271
type: 'LineString',

cases/line-rendering/main.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ const style = {
2323
'stroke-width': ['get', 'width'],
2424
'stroke-color': ['get', 'color'],
2525
'stroke-line-dash': [15, 15],
26+
'text-value': ['get', 'label'],
27+
'text-font': 'bold 12px "Open Sans", "Arial Unicode MS", sans-serif',
28+
'text-fill-color': '#333',
29+
'text-stroke-color': 'rgba(255,255,255,0.8)',
30+
'text-stroke-width': 2,
31+
'text-placement': 'line',
32+
'text-repeat': 2000,
2633
};
2734

2835
/**

cases/point-rendering/main.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ const source = new VectorSource({
1919
*/
2020
const style = {
2121
// This has to be fixed upstream
22-
// @ts-ignore
2322
'circle-radius': ['get', 'radius'],
2423
'circle-fill-color': ['get', 'color'],
2524
'circle-stroke-color': 'gray',
2625
'circle-stroke-width': 0.5,
26+
'text-value': ['get', 'label'],
27+
'text-font': 'bold 12px "Open Sans", "Arial Unicode MS", sans-serif',
28+
'text-fill-color': '#333',
29+
'text-stroke-color': 'rgba(255,255,255,0.8)',
30+
'text-stroke-width': 2,
31+
'text-offset-y': -12,
2732
};
2833

2934
/**

cases/polygon-rendering/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ const source = new VectorSource({
2020
*/
2121
const style = {
2222
'fill-color': ['get', 'color'],
23+
'text-value': ['get', 'label'],
24+
'text-font': 'bold 12px "Open Sans", "Arial Unicode MS", sans-serif',
25+
'text-fill-color': '#333',
26+
'text-stroke-color': 'rgba(255,255,255,0.8)',
27+
'text-stroke-width': 2,
2328
};
2429

2530
/**

package-lock.json

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
},
2828
"dependencies": {
2929
"@camptocamp/rendering-analyzer": "^0.2.0",
30+
"@scaleway/random-name": "^5.1.2",
3031
"ol": "10.6.1"
3132
}
3233
}

0 commit comments

Comments
 (0)