From 9849eaf1e799ea73643bfacc7e1528a0238b9506 Mon Sep 17 00:00:00 2001 From: Peter Bastiani Date: Fri, 25 Aug 2023 09:50:38 +0200 Subject: [PATCH] AW1873 Labels -> show below zoom, overflow + format centroid --- .../item-vector-source.component.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/projects/common-map/src/fm-map/components/aol/item-vector-source/item-vector-source.component.ts b/projects/common-map/src/fm-map/components/aol/item-vector-source/item-vector-source.component.ts index 8698ee2..0deebd0 100644 --- a/projects/common-map/src/fm-map/components/aol/item-vector-source/item-vector-source.component.ts +++ b/projects/common-map/src/fm-map/components/aol/item-vector-source/item-vector-source.component.ts @@ -150,7 +150,7 @@ export class ItemVectorSourceComponent extends SourceVectorComponent implements color: fillColor }), geometry: (feature: Feature) => this.geometry(feature), - text: this.getDisplayTextForFeature(feature) + text: this.getDisplayTextForFeature(feature, this.map.instance.getView().getZoom()) }); } else { key = 'file'; @@ -210,19 +210,23 @@ export class ItemVectorSourceComponent extends SourceVectorComponent implements } } - getDisplayTextForFeature(feature: Feature, overrule: style.Text = null, zoom: { min: number, current: number } = null): style.Text { + getDisplayTextForFeature(feature: Feature, zoom: number, overrule?: style.Text) { if (!feature) return null; const propertiesToShow: string[] = this.displayMapFeatureSettings[feature.get('itemType')]; if (!propertiesToShow) return null; if (propertiesToShow.length <= 0) return null; - if (zoom && zoom.current > zoom.min) return null; + if (zoom < 14) return null; let displayText = ''; for (let i = 0; i < propertiesToShow.length; i++) { let value = feature.get(propertiesToShow[i]); switch (propertiesToShow[i]) { - case "area": value = formatNumber(value, this.locale, '0.1-2') + 'ha'; break; - case "centroid": value = feature.getGeometry() ? getCenter(feature.getGeometry().getExtent()) : null; break; + case "area": value = formatNumber(value, this.locale, '0.1-2') + ' ha'; break; + case "centroid": { + if (feature.getGeometry()) { + const centroid = getCenter(feature.getGeometry().getExtent()); + value = Math.round(centroid[0]) + ',' + Math.round(centroid[1]); + } } if (value) { displayText += value + (i < propertiesToShow.length ? '\n' : '');