AW1873 Labels -> show below zoom, overflow + format centroid
Some checks failed
FarmMaps.Develop/FarmMapsLib/pipeline/head There was a failure building this commit
Some checks failed
FarmMaps.Develop/FarmMapsLib/pipeline/head There was a failure building this commit
This commit is contained in:
parent
b516cc07e2
commit
9849eaf1e7
@ -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' : '');
|
||||
|
Loading…
Reference in New Issue
Block a user