Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion cases/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
trackPerformance,
// @ts-ignore
} from '@camptocamp/rendering-analyzer';
import randomName from '@scaleway/random-name';
import lilGui from 'lil-gui';
import Map from 'ol/Map.js';
import View from 'ol/View.js';
Expand Down Expand Up @@ -164,11 +165,13 @@ export function generatePolygons(count, numVertices) {
// Close the polygon by adding the first vertex at the end
polygonCoordinates.push(polygonCoordinates[0]);

const label = `This area covers ${randomName()}`;
features.push({
type: 'Feature',
properties: {
color: getRandomPaletteColor(),
ratio: Math.round(Math.random() * 100),
label,
},
geometry: {
type: 'Polygon',
Expand Down Expand Up @@ -197,11 +200,13 @@ export function generatePoints(count, radius) {
for (let lon = -180; lon < 180 - size / 4; lon += size) {
for (let lat = -90; lat < 90 - size / 4; lat += size) {
const buffer = (0.3 + Math.random() * 0.2) * size * (radius / 5); // Increase the buffer for larger points
const label = randomName();
features.push({
type: 'Feature',
properties: {
color: getRandomPaletteColor(),
radius,
label,
},
geometry: {
type: 'Point',
Expand Down Expand Up @@ -254,11 +259,13 @@ export function generateLines(lineCount, curveComplexity, width) {
}
coordinates.push(...singleCurve);
}
const label = `This leads to ${randomName()}`;
features.push({
type: 'Feature',
properties: {
color: getRandomPaletteColor(), // Use deterministic color selection
width,
label,
},
geometry: {
type: 'LineString',
Expand All @@ -285,7 +292,7 @@ const guiParams = {};
* The `id` and `values` will show up in the url
* @param {string} id Id
* @param {string} label Label
* @param {Array<string>|Array<number>} values Either two string values for true/false, or two numbers defining a range
* @param {Array<string>|Array<number>} values Either two string values for true/false, or two numbers defining a range + optional step value
* @param {boolean|number|function(): void} defaultValue Default value
* @param {function(boolean|number|function(): void, boolean|null): void} callback Called when the parameter changes, and also on initialization
* First argument is the current value, second argument is true if this is the initial call
Expand Down Expand Up @@ -454,6 +461,7 @@ function animate() {
}, 1000);
}

/** @type {string} */
export const olVersion =
new URL(window.location.href).searchParams.get('olVersion') ??
// @ts-ignore
Expand Down
42 changes: 36 additions & 6 deletions cases/line-rendering/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,27 @@ const source = new VectorSource({
});

/**
*
* @type {import('ol/style/flat.js').FlatStyle}
*/
const style = {
const baseStyle = {
'stroke-width': ['get', 'width'],
'stroke-color': ['get', 'color'],
'stroke-line-dash': [15, 15],
};

/**
* @type {import('ol/style/flat.js').FlatStyle}
*/
const textStyle = {
'text-value': ['get', 'label'],
'text-font': 'bold 12px "Open Sans", "Arial Unicode MS", sans-serif',
'text-fill-color': '#333',
'text-stroke-color': 'rgba(255,255,255,0.8)',
'text-stroke-width': 2,
'text-placement': 'line',
'text-repeat': 2000,
};

/**
* @param {number} lineCount From 1 to 100
* @param {number} curveComplexity From 2 to 1000
Expand All @@ -37,18 +49,24 @@ function resetData(lineCount, curveComplexity, width) {
function main() {
createMap(
(map) => {
const style = getGuiParameterValue('text')
? {...baseStyle, ...textStyle}
: baseStyle;
map.addLayer(new WebGLVectorLayer({source, properties: {style}}));
},
(map) => {
const style = getGuiParameterValue('text')
? {...baseStyle, ...textStyle}
: baseStyle;
map.addLayer(new VectorLayer({source, style}));
},
);
initializeGui();
registerGuiParameter(
'count',
'Line count',
[2, 100, 10],
2,
[2, 10000, 10],
10,
(value, initial) => {
if (initial) {
return;
Expand Down Expand Up @@ -93,9 +111,21 @@ function main() {
false,
(value, initial) => {
if (value) {
style['stroke-line-dash'] = [15, 15];
baseStyle['stroke-line-dash'] = [15, 15];
} else {
delete style['stroke-line-dash'];
delete baseStyle['stroke-line-dash'];
}
regenerateLayer();
},
);
registerGuiParameter(
'text',
'Show labels',
['yes', 'no'],
false,
(value, initial) => {
if (initial) {
return;
}
regenerateLayer();
},
Expand Down
34 changes: 32 additions & 2 deletions cases/point-rendering/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
generatePoints,
getGuiParameterValue,
initializeGui,
regenerateLayer,
registerGuiParameter,
} from '../common.js';

Expand All @@ -17,15 +18,26 @@ const source = new VectorSource({
/**
* @type {import('ol/style/flat.js').FlatStyle}
*/
const style = {
const baseStyle = {
// This has to be fixed upstream
// @ts-ignore
'circle-radius': ['get', 'radius'],
'circle-fill-color': ['get', 'color'],
'circle-stroke-color': 'gray',
'circle-stroke-width': 0.5,
};

/**
* @type {import('ol/style/flat.js').FlatStyle}
*/
const textStyle = {
'text-value': ['get', 'label'],
'text-font': 'bold 12px "Open Sans", "Arial Unicode MS", sans-serif',
'text-fill-color': '#333',
'text-stroke-color': 'rgba(255,255,255,0.8)',
'text-stroke-width': 2,
'text-offset-y': -12,
};

/**
* @param {number} count The number of features to create.
* @param {number} radius
Expand All @@ -38,9 +50,15 @@ function resetData(count, radius) {
function main() {
createMap(
(map) => {
const style = getGuiParameterValue('text')
? {...baseStyle, ...textStyle}
: baseStyle;
map.addLayer(new WebGLVectorLayer({source, properties: {style}}));
},
(map) => {
const style = getGuiParameterValue('text')
? {...baseStyle, ...textStyle}
: baseStyle;
map.addLayer(new VectorLayer({source, style}));
},
);
Expand Down Expand Up @@ -69,6 +87,18 @@ function main() {
/** @type {number} */ (value),
);
});
registerGuiParameter(
'text',
'Show labels',
['yes', 'no'],
false,
(value, initial) => {
if (initial) {
return;
}
regenerateLayer();
},
);

resetData(
/** @type {number} */ (getGuiParameterValue('count')),
Expand Down
45 changes: 40 additions & 5 deletions cases/polygon-rendering/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,25 @@ const source = new VectorSource({
/**
* @type {import('ol/style/flat.js').FlatStyle}
*/
const style = {
const baseStyle = {
'fill-color': ['get', 'color'],
'text-value': ['get', 'label'],
'text-font': 'bold 12px "Open Sans", "Arial Unicode MS", sans-serif',
'text-fill-color': '#333',
'text-stroke-color': 'rgba(255,255,255,0.8)',
'text-stroke-width': 2,
};

/**
* @type {import('ol/style/flat.js').FlatStyle}
*/
const textStyle = {
'text-value': ['get', 'label'],
'text-font': 'bold 12px "Open Sans", "Arial Unicode MS", sans-serif',
'text-fill-color': '#333',
'text-stroke-color': 'rgba(255,255,255,0.8)',
'text-stroke-width': 2,
'text-offset-y': -12,
};

/**
Expand All @@ -33,9 +50,15 @@ function resetData(count, numVertices) {
function main() {
createMap(
(map) => {
const style = getGuiParameterValue('text')
? {...baseStyle, ...textStyle}
: baseStyle;
map.addLayer(new WebGLVectorLayer({source, properties: {style}}));
},
(map) => {
const style = getGuiParameterValue('text')
? {...baseStyle, ...textStyle}
: baseStyle;
map.addLayer(new VectorLayer({source, style}));
},
);
Expand Down Expand Up @@ -77,11 +100,23 @@ function main() {
true,
(value, initial) => {
if (value) {
style['stroke-width'] = 2;
style['stroke-color'] = 'gray';
baseStyle['stroke-width'] = 2;
baseStyle['stroke-color'] = 'gray';
} else {
delete style['stroke-width'];
delete style['stroke-color'];
delete baseStyle['stroke-width'];
delete baseStyle['stroke-color'];
}
regenerateLayer();
},
);
registerGuiParameter(
'text',
'Show labels',
['yes', 'no'],
false,
(value, initial) => {
if (initial) {
return;
}
regenerateLayer();
},
Expand Down
Loading