Skip to content

Commit

Permalink
refactor(FeatureContext): use Context on LabelLayer and Feature2Texture
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Oct 23, 2023
1 parent debd5c8 commit 742dad7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Converter/Feature2Mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Coordinates from 'Core/Geographic/Coordinates';

const coord = new Coordinates('EPSG:4326', 0, 0, 0);

class FeatureContext {
export class FeatureContext {
#worldCoord = new Coordinates('EPSG:4326', 0, 0, 0);
#localCoordinates = new Coordinates('EPSG:4326', 0, 0, 0);
#geometry = {};
Expand Down
7 changes: 5 additions & 2 deletions src/Converter/Feature2Texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import * as THREE from 'three';
import { FEATURE_TYPES } from 'Core/Feature';
import Extent from 'Core/Geographic/Extent';
import Coordinates from 'Core/Geographic/Coordinates';
import { FeatureContext } from 'Converter/Feature2Mesh';

const context = new FeatureContext();

const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
const matrix = svg.createSVGMatrix();
Expand Down Expand Up @@ -105,11 +108,11 @@ 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 };
context.globals = { zoom: extent.zoom };

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).drawingStylefromContext(context);

if (contextStyle) {
Expand Down
8 changes: 6 additions & 2 deletions src/Layer/LabelLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 = { zoom: extent.zoom };
context.globals = { zoom: extent.zoom };

data.features.forEach((f) => {
// TODO: add support for LINE and POLYGON
Expand All @@ -267,8 +270,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) {
Expand Down

0 comments on commit 742dad7

Please sign in to comment.