Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(Style): fuse drawStylefromContext() and symbolStylefromConte…
Browse files Browse the repository at this point in the history
…xt() into applyContext()
ftoromanoff committed Oct 25, 2023
1 parent 396edfb commit 92149ff
Showing 6 changed files with 146 additions and 146 deletions.
2 changes: 1 addition & 1 deletion examples/js/plugins/FeatureToolTip.js
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ const FeatureToolTip = (function _() {
geometry = feature.geometry;
style = (geometry.properties && geometry.properties.style) || feature.style || layer.style;
const context = { globals: {}, properties: getGeometryProperties(geometry) };
style = style.drawingStylefromContext(context);
style = style.applyContext(context);

if (feature.type === itowns.FEATURE_TYPES.POLYGON) {
symb = '&#9724';
10 changes: 5 additions & 5 deletions src/Converter/Feature2Mesh.js
Original file line number Diff line number Diff line change
@@ -231,7 +231,7 @@ function featureToPoint(feature, options) {
const globals = { point: true };
for (const geometry of feature.geometries) {
const context = { globals, properties: () => geometry.properties };
const style = feature.style.drawingStylefromContext(context);
const style = feature.style.applyContext(context);

const start = geometry.indices[0].offset;
const count = geometry.indices[0].count;
@@ -286,7 +286,7 @@ function featureToLine(feature, options) {
// Multi line case
for (const geometry of feature.geometries) {
const context = { globals, properties: () => geometry.properties };
const style = feature.style.drawingStylefromContext(context);
const style = feature.style.applyContext(context);

const start = geometry.indices[0].offset;
// To avoid integer overflow with indice value (16 bits)
@@ -317,7 +317,7 @@ function featureToLine(feature, options) {
lines = new THREE.LineSegments(geom, options.lineMaterial);
} else {
const context = { globals, properties: () => feature.geometries[0].properties };
const style = feature.style.drawingStylefromContext(context);
const style = feature.style.applyContext(context);

fillColorArray(colors, count, toColor(style.stroke.color));
geom.setAttribute('color', new THREE.BufferAttribute(colors, 3, true));
@@ -360,7 +360,7 @@ function featureToPolygon(feature, options) {
break;
}
const context = { globals, properties: () => geometry.properties };
const style = feature.style.drawingStylefromContext(context);
const style = feature.style.applyContext(context);

const lastIndice = geometry.indices.slice(-1)[0];
const end = lastIndice.offset + lastIndice.count;
@@ -429,7 +429,7 @@ function featureToExtrudedPolygon(feature, options) {
const start = geometry.indices[0].offset;

const context = { globals, properties: () => geometry.properties };
const style = feature.style.drawingStylefromContext(context);
const style = feature.style.applyContext(context);


const lastIndice = geometry.indices.slice(-1)[0];
9 changes: 7 additions & 2 deletions src/Converter/Feature2Texture.js
Original file line number Diff line number Diff line change
@@ -74,12 +74,17 @@ const coord = new Coordinates('EPSG:4326', 0, 0, 0);
function drawFeature(ctx, feature, extent, style, invCtxScale) {
const extentDim = extent.planarDimensions();
const scaleRadius = extentDim.x / ctx.canvas.width;
const globals = { zoom: extent.zoom };
const globals = {
fill: true,
stroke: true,
point: true,
zoom: extent.zoom,
};

for (const geometry of feature.geometries) {
if (Extent.intersectsExtent(geometry.extent, extent)) {
const context = { globals, properties: () => geometry.properties };
const contextStyle = (geometry.properties.style || style).drawingStylefromContext(context);
const contextStyle = (geometry.properties.style || style).applyContext(context);

if (contextStyle) {
if (
259 changes: 125 additions & 134 deletions src/Core/Style.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/Layer/LabelLayer.js
Original file line number Diff line number Diff line change
@@ -240,7 +240,11 @@ class LabelLayer extends GeometryLayer {
// Converting the extent now is faster for further operation
extent.as(data.crs, _extent);
coord.crs = data.crs;
const globals = { zoom: extent.zoom };
const globals = {
icon: true,
text: true,
zoom: extent.zoom,
};

data.features.forEach((f) => {
// TODO: add support for LINE and POLYGON
@@ -286,7 +290,7 @@ class LabelLayer extends GeometryLayer {
content = this.style.getTextFromProperties(context);
}

const style = (g.properties.style || f.style || this.style).symbolStylefromContext(context);
const style = (g.properties.style || f.style || this.style).applyContext(context);

const label = new Label(content, coord.clone(), style);
label.layerId = this.id;
4 changes: 2 additions & 2 deletions test/unit/vectortiles.js
Original file line number Diff line number Diff line change
@@ -140,8 +140,8 @@ describe('Vector tiles', function () {
},
});
source.whenReady.then(() => {
const styleLand_zoom_3 = source.styles.land.drawingStylefromContext({ globals: { zoom: 3 }, properties: () => {} });
const styleLand_zoom_5 = source.styles.land.drawingStylefromContext({ globals: { zoom: 5 }, properties: () => {} });
const styleLand_zoom_3 = source.styles.land.applyContext({ globals: { zoom: 3 }, properties: () => {} });
const styleLand_zoom_5 = source.styles.land.applyContext({ globals: { zoom: 5 }, properties: () => {} });
assert.equal(styleLand_zoom_3.fill.color, 'rgb(255,0,0)');
assert.equal(styleLand_zoom_3.fill.opacity, 1);
assert.equal(styleLand_zoom_5.fill.color, 'rgb(255,0,0)');

0 comments on commit 92149ff

Please sign in to comment.