[core] always reparse with the freshest possible placement config

Fixes an issue where updates to stale tiles would remove labels altogether until the map was rotated.
This commit is contained in:
Konstantin Käfer
2015-10-26 15:45:32 +01:00
parent c0c554e36f
commit 75dec6ffac
15 changed files with 231 additions and 130 deletions

View File

@@ -3,17 +3,16 @@
namespace mbgl {
CollisionTile::CollisionTile(const float angle_, const float pitch, bool debug_) :
angle(angle_), debug(debug_) {
CollisionTile::CollisionTile(PlacementConfig config_) : config(config_) {
tree.clear();
// Compute the transformation matrix.
float angle_sin = std::sin(angle);
float angle_cos = std::cos(angle);
rotationMatrix = {{angle_cos, -angle_sin, angle_sin, angle_cos}};
// Compute the transformation matrix.
const float angle_sin = std::sin(config.angle);
const float angle_cos = std::cos(config.angle);
rotationMatrix = { { angle_cos, -angle_sin, angle_sin, angle_cos } };
// Stretch boxes in y direction to account for the map tilt.
const float _yStretch = 1.0f / std::cos(pitch);
const float _yStretch = 1.0f / std::cos(config.pitch);
// The amount the map is squished depends on the y position.
// Sort of account for this by making all boxes a bit bigger.

View File

@@ -2,6 +2,7 @@
#define MBGL_TEXT_COLLISION_TILE
#include <mbgl/text/collision_feature.hpp>
#include <mbgl/text/placement_config.hpp>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
@@ -24,39 +25,34 @@
namespace mbgl {
namespace bg = boost::geometry;
namespace bgm = bg::model;
namespace bgi = bg::index;
typedef bgm::point<float, 2, bg::cs::cartesian> CollisionPoint;
typedef bgm::box<CollisionPoint> Box;
typedef std::pair<Box, CollisionBox> CollisionTreeBox;
typedef bgi::rtree<CollisionTreeBox, bgi::linear<16,4>> Tree;
namespace bg = boost::geometry;
namespace bgm = bg::model;
namespace bgi = bg::index;
typedef bgm::point<float, 2, bg::cs::cartesian> CollisionPoint;
typedef bgm::box<CollisionPoint> Box;
typedef std::pair<Box, CollisionBox> CollisionTreeBox;
typedef bgi::rtree<CollisionTreeBox, bgi::linear<16, 4>> Tree;
class CollisionTile {
public:
explicit CollisionTile(PlacementConfig);
public:
explicit CollisionTile(float angle_, float pitch_, bool debug_);
float placeFeature(const CollisionFeature& feature);
void insertFeature(CollisionFeature& feature, const float minPlacementScale);
float placeFeature(const CollisionFeature &feature);
void insertFeature(CollisionFeature &feature, const float minPlacementScale);
bool getDebug() { return debug; }
const float angle = 0;
const PlacementConfig config;
const float minScale = 0.5f;
const float maxScale = 2.0f;
float yStretch;
private:
Box getTreeBox(const vec2<float> &anchor, const CollisionBox &box);
private:
Box getTreeBox(const vec2<float>& anchor, const CollisionBox& box);
Tree tree;
std::array<float, 4> rotationMatrix;
bool debug;
};
}
} // namespace mbgl
#endif

View File

@@ -0,0 +1,28 @@
#ifndef MBGL_TEXT_PLACEMENT_CONFIG
#define MBGL_TEXT_PLACEMENT_CONFIG
namespace mbgl {
class PlacementConfig {
public:
inline PlacementConfig(float angle_ = 0, float pitch_ = 0, bool debug_ = false)
: angle(angle_), pitch(pitch_), debug(debug_) {
}
inline bool operator==(const PlacementConfig& rhs) const {
return angle == rhs.angle && pitch == rhs.pitch && debug == rhs.debug;
}
inline bool operator!=(const PlacementConfig& rhs) const {
return !operator==(rhs);
}
public:
float angle;
float pitch;
bool debug;
};
} // namespace mbgl
#endif