diff --git a/src/Converter/Feature2Mesh.js b/src/Converter/Feature2Mesh.js index f459bb29e5..2f9a97bdce 100644 --- a/src/Converter/Feature2Mesh.js +++ b/src/Converter/Feature2Mesh.js @@ -10,7 +10,20 @@ import Coordinates from 'Core/Geographic/Coordinates'; const coord = new Coordinates('EPSG:4326', 0, 0, 0); -class FeatureContext { +/** + * @class + * @classdesc FeatureContext is a class to store all informations + * about context to generate the style of each FeatureGeometry. + * + * @property {Coordinates} worldCoord @private Coordinates of the FeatureGeometry in world system. + * @property {Coordinates} localCoordinates @private Are the coordinates systeme origin local or global. + * @property {boolean} isProjected @private Are the coordinates already been projected. + * @property {FeatureGeometry} geometry @private + * @property {Object} globals + * @property {Object} collection + * @property {Coordinates} coordinates + */ +export class FeatureContext { #worldCoord = new Coordinates('EPSG:4326', 0, 0, 0); #localCoordinates = new Coordinates('EPSG:4326', 0, 0, 0); #isProjected = true; diff --git a/src/Converter/Feature2Texture.js b/src/Converter/Feature2Texture.js index e74b268440..afcd645c2c 100644 --- a/src/Converter/Feature2Texture.js +++ b/src/Converter/Feature2Texture.js @@ -3,6 +3,9 @@ import { FEATURE_TYPES } from 'Core/Feature'; import Extent from 'Core/Geographic/Extent'; import Coordinates from 'Core/Geographic/Coordinates'; import Style from 'Core/Style'; +import { FeatureContext } from 'Converter/Feature2Mesh'; + +const context = new FeatureContext(); /** * Draw polygon (contour, line edge and fill) based on feature vertices into canvas @@ -74,7 +77,7 @@ 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 = { + context.globals = { fill: true, stroke: true, point: true, @@ -83,7 +86,7 @@ function drawFeature(ctx, feature, extent, style, invCtxScale) { for (const geometry of feature.geometries) { if (Extent.intersectsExtent(geometry.extent, extent)) { - const context = { globals, properties: () => geometry.properties }; + context.setGeometry(geometry); const contextStyle = (geometry.properties.style || style).applyContext(context); if (contextStyle) { diff --git a/src/Core/Style.js b/src/Core/Style.js index 2a6480699d..3b6b1801df 100644 --- a/src/Core/Style.js +++ b/src/Core/Style.js @@ -987,7 +987,7 @@ class Style { if (this.text.field.expression) { return readExpression(this.text.field, ctx); } else { - return this.text.field.replace(/\{(.+?)\}/g, (a, b) => (ctx.properties()[b] || '')).trim(); + return this.text.field.replace(/\{(.+?)\}/g, (a, b) => (ctx.properties[b] || '')).trim(); } } } diff --git a/src/Layer/LabelLayer.js b/src/Layer/LabelLayer.js index fcf266d39b..6c389babe9 100644 --- a/src/Layer/LabelLayer.js +++ b/src/Layer/LabelLayer.js @@ -8,6 +8,9 @@ import Label from 'Core/Label'; import { FEATURE_TYPES } from 'Core/Feature'; import { readExpression } from 'Core/Style'; import { ScreenGrid } from 'Renderer/Label2DRenderer'; +import { FeatureContext } from 'Converter/Feature2Mesh'; + +const context = new FeatureContext(); const coord = new Coordinates('EPSG:4326', 0, 0, 0); @@ -241,7 +244,7 @@ class LabelLayer extends GeometryLayer { // Converting the extent now is faster for further operation extent.as(data.crs, _extent); coord.crs = data.crs; - const globals = { + context.globals = { icon: true, text: true, zoom: extent.zoom, @@ -272,8 +275,9 @@ class LabelLayer extends GeometryLayer { if (!_extent.isPointInside(coord)) { return; } const geometryField = g.properties.style && g.properties.style.text.field; + + context.setGeometry(g); let content; - const context = { globals, properties: () => g.properties }; if (this.labelDomelement) { content = readExpression(this.labelDomelement, context); } else if (!geometryField && !featureField && !layerField) {