make text layers respect the translate-anchor
you can now specify "translate-anchor": "viewport" to have the text translated in screen coordinates rather than relative to the tile. The default value remains "translate-anchor": "map" refs #189
This commit is contained in:
@@ -171,7 +171,7 @@ void Painter::renderTileLayer(const Tile& tile, const LayerDescription &layer_de
|
||||
}
|
||||
}
|
||||
|
||||
void Painter::translateLayer(const std::array<float, 2> translation, const Tile::ID &id, bool reverse) {
|
||||
void Painter::translateLayer(const std::array<float, 2> &translation, const Tile::ID &id, bool reverse) {
|
||||
if (translation[0] || translation[1]) {
|
||||
const int direction = reverse ? -1 : 1;
|
||||
// TODO: Get rid of the 8 (scaling from 4096 to tile size)
|
||||
@@ -181,6 +181,32 @@ void Painter::translateLayer(const std::array<float, 2> translation, const Tile:
|
||||
}
|
||||
}
|
||||
|
||||
mat4 Painter::translatedMatrix(const std::array<float, 2> &translation, const Tile::ID &id, TranslateAnchor anchor) {
|
||||
if (translation[0] == 0 && translation[1] == 0) {
|
||||
return matrix;
|
||||
} else {
|
||||
// TODO: Get rid of the 8 (scaling from 4096 to tile size)
|
||||
const double factor = ((double)(1 << id.z)) / map.getState().getScale() /
|
||||
map.getState().getPixelRatio() * (4096.0 / util::tileSize);
|
||||
|
||||
mat4 result;
|
||||
if (anchor == TranslateAnchor::Viewport) {
|
||||
const double sin_a = sin(-map.getState().getAngle());
|
||||
const double cos_a = cos(-map.getState().getAngle());
|
||||
matrix::translate(result, matrix,
|
||||
factor * (translation[0] * cos_a - translation[1] * sin_a),
|
||||
factor * (translation[0] * sin_a + translation[1] * cos_a),
|
||||
0);
|
||||
} else {
|
||||
matrix::translate(result, matrix,
|
||||
factor * translation[0],
|
||||
factor * translation[1],
|
||||
0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
void Painter::renderMatte() {
|
||||
gl::group group("matte");
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
Reference in New Issue
Block a user