[core] Add RendererState::{pixelForLatLng,latLngForPixel}

This commit is contained in:
Bruno de Oliveira Abinader
2018-11-13 20:42:48 +02:00
parent d44be9a91b
commit db2e1b2e5f
5 changed files with 57 additions and 8 deletions

View File

@@ -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