Skip to content

Commit

Permalink
refactor(Style): fuse drawStylefromContext() and symbolStylefromConte…
Browse files Browse the repository at this point in the history
…xt() into applyContext()
  • Loading branch information
ftoromanoff committed Oct 25, 2023
1 parent f045341 commit 37fe32e
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 139 deletions.
2 changes: 1 addition & 1 deletion examples/js/plugins/FeatureToolTip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
10 changes: 5 additions & 5 deletions src/Converter/Feature2Mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
9 changes: 7 additions & 2 deletions src/Converter/Feature2Texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Loading

0 comments on commit 37fe32e

Please sign in to comment.