diff --git a/src/Converter/Feature2Mesh.js b/src/Converter/Feature2Mesh.js index 3a9d07408e..f560eecaa4 100644 --- a/src/Converter/Feature2Mesh.js +++ b/src/Converter/Feature2Mesh.js @@ -23,7 +23,7 @@ const coord = new Coordinates('EPSG:4326', 0, 0, 0); * @property {Object} collection * @property {Coordinates} coordinates */ -class FeatureContext { +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/Layer/LabelLayer.js b/src/Layer/LabelLayer.js index 98aaf6d233..5b553ef970 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); @@ -240,7 +243,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, @@ -271,8 +274,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) {