Skip to content

Commit

Permalink
fix(LabelLayer): gestion simplified of line and polygon Label
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Jan 15, 2025
1 parent b8a13d9 commit cb3c3b7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/Core/Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,8 @@ class Style {
style.point.opacity = opacity;
style.point.radius = readVectorProperty(layer.paint['circle-radius']);
} else if (layer.type === 'symbol') {
// if symbol we shouldn't draw stroke but defaut value is 1.
style.stroke.width = 0.0;
// overlapping order
style.text.zOrder = readVectorProperty(layer.layout['symbol-z-order']);
if (style.text.zOrder == 'auto') {
Expand Down
40 changes: 22 additions & 18 deletions src/Layer/LabelLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import GeometryLayer from 'Layer/GeometryLayer';
import Coordinates from 'Core/Geographic/Coordinates';
import Extent from 'Core/Geographic/Extent';
import Label from 'Core/Label';
import { FEATURE_TYPES } from 'Core/Feature';
import { readExpression, StyleContext } from 'Core/Style';
import { ScreenGrid } from 'Renderer/Label2DRenderer';

Expand Down Expand Up @@ -254,10 +253,12 @@ class LabelLayer extends GeometryLayer {
context.setZoom(extentOrTile.zoom);

data.features.forEach((f) => {
// TODO: add support for LINE and POLYGON
if (f.type !== FEATURE_TYPES.POINT) {
return;
if (f.style.text) {
if (Object.keys(f.style.text).length === 0) {
return;
}
}

context.setFeature(f);

const featureField = f.style?.text?.field;
Expand All @@ -270,19 +271,11 @@ class LabelLayer extends GeometryLayer {
labels.needsAltitude = labels.needsAltitude || this.forceClampToTerrain === true || (isDefaultElevationStyle && !f.hasRawElevationData);

f.geometries.forEach((g) => {
// NOTE: this only works because only POINT is supported, it
// needs more work for LINE and POLYGON
coord.setFromArray(f.vertices, g.size * g.indices[0].offset);
// Transform coordinate to data.crs projection
coord.applyMatrix4(data.matrixWorld);

if (!_extent.isPointInside(coord)) { return; }
const geometryField = g.properties.style && g.properties.style.text && g.properties.style.text.field;

context.setGeometry(g);
let content;
this.style.setContext(context);
const layerField = this.style.text && this.style.text.field;
const geometryField = g.properties.style && g.properties.style.text && g.properties.style.text.field;
let content;
if (this.labelDomelement) {
content = readExpression(this.labelDomelement, context);
} else if (!geometryField && !featureField && !layerField) {
Expand All @@ -298,12 +291,23 @@ class LabelLayer extends GeometryLayer {
return;
}

const label = new Label(content, coord.clone(), this.style);
// NOTE: this only works fine for POINT.
// It needs more work for LINE and POLYGON as we currently only use the first point of the entity

g.indices.forEach((i) => {
coord.setFromArray(f.vertices, g.size * i.offset);
// Transform coordinate to data.crs projection
coord.applyMatrix4(data.matrixWorld);

label.layerId = this.id;
label.padding = this.margin || label.padding;
if (!_extent.isPointInside(coord)) { return; }

labels.push(label);
const label = new Label(content, coord.clone(), this.style);

label.layerId = this.id;
label.padding = this.margin || label.padding;

labels.push(label);
});
});
});

Expand Down

0 comments on commit cb3c3b7

Please # to comment.