Implement map projection functionality (#254)
* Implement map projection functionality * Add missing MGL_EXPORT * Remove the automatic copyright header
This commit is contained in:
committed by
GitHub
parent
ea234edf67
commit
6db27f50ad
@@ -426,6 +426,12 @@ std::vector<LatLng> Map::latLngsForPixels(const std::vector<ScreenCoordinate>& s
|
||||
return ret;
|
||||
}
|
||||
|
||||
#pragma mark - Transform
|
||||
|
||||
TransformState Map::getTransfromState() const {
|
||||
return impl->transform.getState();
|
||||
}
|
||||
|
||||
#pragma mark - Annotations
|
||||
|
||||
void Map::addAnnotationImage(std::unique_ptr<style::Image> image) {
|
||||
|
||||
@@ -76,4 +76,9 @@ public:
|
||||
std::unique_ptr<StillImageRequest> stillImageRequest;
|
||||
};
|
||||
|
||||
// Forward declaration of this method is required for the MapProjection class
|
||||
CameraOptions cameraForLatLngs(const std::vector<LatLng>& latLngs,
|
||||
const Transform& transform,
|
||||
const EdgeInsets& padding);
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
39
src/mbgl/map/map_projection.cpp
Normal file
39
src/mbgl/map/map_projection.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <mbgl/map/map_projection.hpp>
|
||||
#include <mbgl/map/map_impl.hpp>
|
||||
#include <mbgl/map/transform.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
MapProjection::MapProjection(const Map& map)
|
||||
: transform(std::make_unique<Transform>(map.getTransfromState())) {}
|
||||
|
||||
MapProjection::~MapProjection() = default;
|
||||
|
||||
ScreenCoordinate MapProjection::pixelForLatLng(const LatLng& latLng) const {
|
||||
// The implementation is just a copy from map.cpp
|
||||
LatLng unwrappedLatLng = latLng.wrapped();
|
||||
unwrappedLatLng.unwrapForShortestPath(transform->getLatLng());
|
||||
return transform->latLngToScreenCoordinate(unwrappedLatLng);
|
||||
}
|
||||
|
||||
LatLng MapProjection::latLngForPixel(const ScreenCoordinate& pixel) const {
|
||||
// The implementation is just a copy from map.cpp
|
||||
return transform->screenCoordinateToLatLng(pixel);
|
||||
}
|
||||
|
||||
void MapProjection::setCamera(const CameraOptions& camera) {
|
||||
transform->jumpTo(camera);
|
||||
}
|
||||
|
||||
CameraOptions MapProjection::getCamera() const {
|
||||
return transform->getCameraOptions(nullopt);
|
||||
}
|
||||
|
||||
void MapProjection::setVisibleCoordinates(const std::vector<LatLng>& latLngs,
|
||||
const EdgeInsets& padding) {
|
||||
transform->jumpTo(mbgl::cameraForLatLngs(latLngs, *transform, padding)
|
||||
.withBearing(-transform->getBearing() * util::RAD2DEG)
|
||||
.withPitch(transform->getPitch() * util::RAD2DEG));
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user