From 08b94a0c4265c4cd2081f82a4fad2fb89b273836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80?= Date: Mon, 17 May 2021 16:18:20 +0300 Subject: [PATCH] Distant labels rendering (#844) --- .../tile/vector/labeling/LabelPlacement.java | 18 +++++++++++++++--- vtm/src/org/oscim/utils/Parameters.java | 5 +++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/vtm/src/org/oscim/layers/tile/vector/labeling/LabelPlacement.java b/vtm/src/org/oscim/layers/tile/vector/labeling/LabelPlacement.java index 2097253e..68ec1526 100644 --- a/vtm/src/org/oscim/layers/tile/vector/labeling/LabelPlacement.java +++ b/vtm/src/org/oscim/layers/tile/vector/labeling/LabelPlacement.java @@ -2,6 +2,7 @@ * Copyright 2013 Hannes Janetzek * Copyright 2016-2019 devemux86 * Copyright 2018 Gustl22 + * Copyright 2021 blakfast * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -31,6 +32,7 @@ import org.oscim.renderer.bucket.SymbolItem; import org.oscim.renderer.bucket.TextItem; import org.oscim.theme.styles.TextStyle; import org.oscim.utils.FastMath; +import org.oscim.utils.Parameters; import org.oscim.utils.geom.OBB2D; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,6 +51,7 @@ public class LabelPlacement { return (LabelTileData) tile.getData(LabelLayer.LABEL_DATA); } + private static final float DISTANCE_COEFFICIENT = 3; private static final float MIN_CAPTION_DIST = 5; private static final float MIN_WAY_DIST = 3; @@ -352,9 +355,18 @@ public class LabelPlacement { } /* estimation for visible area to be labeled */ - int mw = (mMap.getWidth() + Tile.SIZE) / 2; - int mh = (mMap.getHeight() + Tile.SIZE) / 2; - mSquareRadius = mw * mw + mh * mh; + if (Parameters.DISTANT_LABELS) { + int mw = mMap.getWidth(); + int mh = mMap.getHeight(); + float k = pos.tilt / mMap.viewport().getMaxTilt() * DISTANCE_COEFFICIENT; + if (k < 0.5) + k = 0.5f; + mSquareRadius = (mw * mw + mh * mh) * k; + } else { + int mw = (mMap.getWidth() + Tile.SIZE) / 2; + int mh = (mMap.getHeight() + Tile.SIZE) / 2; + mSquareRadius = mw * mw + mh * mh; + } /* scale of tiles zoom-level relative to current position */ double scale = pos.scale / (1 << zoom); diff --git a/vtm/src/org/oscim/utils/Parameters.java b/vtm/src/org/oscim/utils/Parameters.java index 2d72252b..ded22996 100644 --- a/vtm/src/org/oscim/utils/Parameters.java +++ b/vtm/src/org/oscim/utils/Parameters.java @@ -33,6 +33,11 @@ public final class Parameters { */ public static boolean CUSTOM_TILE_SIZE = false; + /** + * Rendering of distant labels. + */ + public static boolean DISTANT_LABELS = false; + /** * If true the MapEventLayer2 will be used instead of default MapEventLayer. */