AW1873 Labels -> show below zoom, overflow + format centroid
FarmMaps.Develop/FarmMapsLib/pipeline/head There was a failure building this commit Details

master
Peter Bastiani 2023-08-25 09:50:38 +02:00
parent b516cc07e2
commit 9849eaf1e7
1 changed files with 9 additions and 5 deletions

View File

@ -150,7 +150,7 @@ export class ItemVectorSourceComponent extends SourceVectorComponent implements
color: fillColor
}),
geometry: (feature: Feature<Geometry>) => 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<Geometry>, overrule: style.Text = null, zoom: { min: number, current: number } = null): style.Text {
getDisplayTextForFeature(feature: Feature<Geometry>, 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' : '');