summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer/renderer_state.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/renderer/renderer_state.cpp')
-rw-r--r--src/mbgl/renderer/renderer_state.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/mbgl/renderer/renderer_state.cpp b/src/mbgl/renderer/renderer_state.cpp
index a024f37dfc..33f6eb27dd 100644
--- a/src/mbgl/renderer/renderer_state.cpp
+++ b/src/mbgl/renderer/renderer_state.cpp
@@ -7,11 +7,11 @@
namespace mbgl {
-CameraOptions RendererState::getCameraOptions(UpdateParameters& updateParameters, const EdgeInsets& padding) {
+CameraOptions RendererState::getCameraOptions(const UpdateParameters& updateParameters, const EdgeInsets& padding) {
return updateParameters.transformState.getCameraOptions(padding);
}
-bool RendererState::hasImage(UpdateParameters& updateParameters, const std::string& id) {
+bool RendererState::hasImage(const UpdateParameters& updateParameters, const std::string& id) {
for (const auto& image : *updateParameters.images) {
if (image.get()->id == id) {
return true;
@@ -20,7 +20,7 @@ bool RendererState::hasImage(UpdateParameters& updateParameters, const std::stri
return false;
}
-bool RendererState::hasLayer(UpdateParameters& updateParameters, const std::string& id) {
+bool RendererState::hasLayer(const UpdateParameters& updateParameters, const std::string& id) {
for (const auto& layer : *updateParameters.layers) {
if (layer.get()->id == id) {
return true;
@@ -29,7 +29,7 @@ bool RendererState::hasLayer(UpdateParameters& updateParameters, const std::stri
return false;
}
-bool RendererState::hasSource(UpdateParameters& updateParameters, const std::string& id) {
+bool RendererState::hasSource(const UpdateParameters& updateParameters, const std::string& id) {
for (const auto& source : *updateParameters.sources) {
if (source.get()->id == id) {
return true;
@@ -38,5 +38,20 @@ bool RendererState::hasSource(UpdateParameters& updateParameters, const std::str
return false;
}
+ScreenCoordinate RendererState::pixelForLatLng(const UpdateParameters& updateParameters, const LatLng& latLng) {
+ // If the center and point longitudes are not in the same side of the
+ // antimeridian, we unwrap the point longitude so it would be seen if
+ // e.g. the next antimeridian side is visible.
+ LatLng unwrappedLatLng = latLng.wrapped();
+ unwrappedLatLng.unwrapForShortestPath(updateParameters.transformState.getLatLng());
+ const ScreenCoordinate point = updateParameters.transformState.latLngToScreenCoordinate(latLng);
+ return ScreenCoordinate { point.x, updateParameters.transformState.size.height - point.y };
+}
+
+LatLng RendererState::latLngForPixel(const UpdateParameters& updateParameters, const ScreenCoordinate& point) {
+ ScreenCoordinate flippedPoint = point;
+ flippedPoint.y = updateParameters.transformState.size.height - flippedPoint.y;
+ return updateParameters.transformState.screenCoordinateToLatLng(flippedPoint);
+}
} // namespace mbgl