libosmscout 0.1
Loading...
Searching...
No Matches
osmscout::MercatorProjection Class Reference

Mercator projection that tries to render the resulting map in the same physical size on all devices. More...

#include <MercatorProjection.h>

Inheritance diagram for osmscout::MercatorProjection:

Public Member Functions

bool CanBatch () const override
bool GeoToPixel (const GeoCoord &coord, Vertex2D &pixel) const override
 Converts a geo coordinate to a pixel coordinate.
bool IsLinearInterpolationEnabled () const
bool IsValid () const override
bool IsValidFor (const GeoCoord &coord) const override
 Return true if given coordinate is valid for this projection.
 MercatorProjection ()=default
 MercatorProjection (const MercatorProjection &)=default
 MercatorProjection (MercatorProjection &&)=default
bool Move (double horizPixel, double vertPixel)
bool MoveDown (double pixel)
bool MoveLeft (double pixel)
bool MoveRight (double pixel)
bool MoveUp (double pixel)
MercatorProjection & operator= (const MercatorProjection &)=default
MercatorProjection & operator= (MercatorProjection &&)=default
bool PixelToGeo (double x, double y, GeoCoord &coord) const override
 Converts a pixel coordinate to a geo coordinate.
bool Set (const GeoCoord &coord, const Magnification &magnification, double dpi, size_t width, size_t height)
bool Set (const GeoCoord &coord, const Magnification &magnification, size_t width, size_t height)
bool Set (const GeoCoord &coord, double angle, const Magnification &magnification, double dpi, size_t width, size_t height)
 Setup projection parameters.
bool Set (const GeoCoord &coord, double angle, const Magnification &magnification, size_t width, size_t height)
void SetLinearInterpolationUsage (bool useLinearInterpolation)
 Switch to enable/disable linear interpolation of latitude to pixel computation.
 ~MercatorProjection () override=default
Public Member Functions inherited from osmscout::Projection
bool BoundingBoxToPixel (const GeoBox &boundingBox, ScreenBox &screenBox) const
 Converts a valid GeoBox to its on screen pixel coordinates.
double ConvertPixelToWidth (double pixel) const
 Convert a width in pixel into the equivalent mm size based on the given DPI.
double ConvertWidthToPixel (double width) const
 Convert a width in mm into the equivalent pixel size based on the given DPI.
double GetAngle () const
 Returns the angle in radians ([0..2*PI[) of the display in relation to the north.
GeoCoord GetCenter () const
GeoBox GetDimensions () const
double GetDPI () const
 Return the DPI as part of the projection.
size_t GetHeight () const
 Returns the height of the screen.
Magnification GetMagnification () const
 Return the magnification as part of the projection.
double GetMeterInMM () const
 Returns the number of on screen millimeters for one meter on the ground.
double GetMeterInPixel () const
 Returns the number of on screen pixel for one meter on the ground.
double GetPixelSize () const
 Returns the size of a pixel in meter.
ScreenBox GetScreenBox () const
 Return a ScreenBox instance for the screen.
size_t GetWidth () const
 Returns the width of the screen.
Projection & operator= (const Projection &)=default
Projection & operator= (Projection &&)=default
 Projection ()=default
 Projection (const Projection &)=default
 Projection (Projection &&)=default
virtual ~Projection ()=default

Static Public Attributes

static const double MaxLat = +85.0511
static const double MaxLon = +180.0
static const double MinLat = -85.0511
static const double MinLon = -180.0

Protected Member Functions

void GeoToPixel (const BatchTransformer &transformData) const override

Protected Attributes

double angleCos =0.0
double angleNegCos =0.0
double angleNegSin =0.0
double angleSin =0.0
double latOffset =0.0
 Absolute and untransformed screen position of lat coordinate.
double scale =1.0
double scaledLatDeriv =0.0
 center scaled by gradtorad * scale
double scaleGradtorad =0.0
 Precalculated scale*Gradtorad.
bool useLinearInterpolation =false
 switch to enable linear interpolation of latitude to pixel computation
bool valid =false
 projection is valid
Protected Attributes inherited from osmscout::Projection
double angle =0.0
 Display rotation angle in radians, canvas clockwise.
GeoBox boundingBox
 Bounding box of the current projection on the ground.
GeoCoord center
 Coordinate of the center of the displayed area.
double dpi =0.0
 Screen DPI.
size_t height =0
 Height of image.
Magnification magnification
 Current magnification.
double meterInMM =0.0
 Number of on screen millimeters for one meter on the ground.
double meterInPixel =0.0
 Number of on screen pixel for one meter on the ground.
double pixelSize =0.0
 Size of a pixel in meter.
size_t width =0
 Width of image.

Detailed Description

Mercator projection that tries to render the resulting map in the same physical size on all devices.

If the physical DPI of the device is correctly given, objects on any device has the same size. Bigger devices will show "more" map thus.

Scale is calculated based on the assumption that the original OpenStreetMap tiles were designed for 96 DPI displays.

Constructor & Destructor Documentation

◆ MercatorProjection() [1/3]

osmscout::MercatorProjection::MercatorProjection ( )
default

◆ MercatorProjection() [2/3]

osmscout::MercatorProjection::MercatorProjection ( const MercatorProjection & )
default

References MercatorProjection().

◆ MercatorProjection() [3/3]

osmscout::MercatorProjection::MercatorProjection ( MercatorProjection && )
default

References MercatorProjection().

◆ ~MercatorProjection()

osmscout::MercatorProjection::~MercatorProjection ( )
overridedefault

Member Function Documentation

◆ CanBatch()

bool osmscout::MercatorProjection::CanBatch ( ) const
inlineoverridevirtual

Implements osmscout::Projection.

◆ GeoToPixel() [1/2]

void osmscout::MercatorProjection::GeoToPixel ( const BatchTransformer & transformData) const
overrideprotectedvirtual

Implements osmscout::Projection.

◆ GeoToPixel() [2/2]

◆ IsLinearInterpolationEnabled()

bool osmscout::MercatorProjection::IsLinearInterpolationEnabled ( ) const
inlinenodiscard

◆ IsValid()

bool osmscout::MercatorProjection::IsValid ( ) const
inlineoverridevirtual

Implements osmscout::Projection.

References valid.

Referenced by osmscout::MapWidget::paint().

◆ IsValidFor()

bool osmscout::MercatorProjection::IsValidFor ( const GeoCoord & coord) const
inlineoverridevirtual

Return true if given coordinate is valid for this projection.

Implements osmscout::Projection.

References osmscout::GeoCoord::GetLat(), osmscout::GeoCoord::GetLon(), MaxLat, MaxLon, MinLat, and MinLon.

Referenced by GeoToPixel(), PixelToGeo(), and Set().

◆ Move()

◆ MoveDown()

bool osmscout::MercatorProjection::MoveDown ( double pixel)
inline

References Move().

◆ MoveLeft()

bool osmscout::MercatorProjection::MoveLeft ( double pixel)
inline

References Move().

◆ MoveRight()

bool osmscout::MercatorProjection::MoveRight ( double pixel)
inline

References Move().

◆ MoveUp()

bool osmscout::MercatorProjection::MoveUp ( double pixel)
inline

References Move().

◆ operator=() [1/2]

MercatorProjection & osmscout::MercatorProjection::operator= ( const MercatorProjection & )
default

References MercatorProjection().

◆ operator=() [2/2]

MercatorProjection & osmscout::MercatorProjection::operator= ( MercatorProjection && )
default

References MercatorProjection().

◆ PixelToGeo()

bool osmscout::MercatorProjection::PixelToGeo ( double x,
double y,
GeoCoord & coord ) const
overridevirtual

◆ Set() [1/4]

bool osmscout::MercatorProjection::Set ( const GeoCoord & coord,
const Magnification & magnification,
double dpi,
size_t width,
size_t height )
inline

◆ Set() [2/4]

◆ Set() [3/4]

bool osmscout::MercatorProjection::Set ( const GeoCoord & coord,
double angle,
const Magnification & magnification,
double dpi,
size_t width,
size_t height )

Setup projection parameters.

Return true on success, false if arguments are not valid for Mercator projection, projection parameters are unchanged in such case.

Angle is in radians ([0..2*PI[)

Note that coord (center) have to be valid coordinate in Mercator projection. But it is possible setup dimensions (width and height) that projection will cover area bigger than the one valid for Mercator projection. Bounding box is adjusted then to be valid for projection.

In code:

projection.GetDimensions(bbox); projection.GeoToPixel(bbox.GetMinCoord(),x,y)

may be x >= 0

References osmscout::Projection::angle, angleCos, angleNegCos, angleNegSin, angleSin, osmscout::Projection::boundingBox, osmscout::Projection::center, osmscout::Projection::dpi, osmscout::Earth::extentMeter, osmscout::GeoCoord::GetLat(), osmscout::GeoCoord::GetLon(), osmscout::gradtorad, osmscout::Projection::height, IsValidFor(), latOffset, osmscout::Projection::magnification, MaxLat, MaxLon, osmscout::Projection::meterInMM, osmscout::Projection::meterInPixel, MinLat, MinLon, osmscout::Projection::pixelSize, PixelToGeo(), scale, scaledLatDeriv, scaleGradtorad, osmscout::GeoCoord::Set(), osmscout::tileDPI, valid, and osmscout::Projection::width.

◆ Set() [4/4]

bool osmscout::MercatorProjection::Set ( const GeoCoord & coord,
double angle,
const Magnification & magnification,
size_t width,
size_t height )
inline

◆ SetLinearInterpolationUsage()

void osmscout::MercatorProjection::SetLinearInterpolationUsage ( bool useLinearInterpolation)
inline

Switch to enable/disable linear interpolation of latitude to pixel computation.

It speedup GeoToPixel calculation with fractional error on small render area.

References useLinearInterpolation.

Referenced by osmscout::PlaneMapRenderer::DrawMap(), osmscout::TiledMapRenderer::onLoadJobFinished(), and osmscout::LookupModule::requestObjectsOnView().

Member Data Documentation

◆ angleCos

double osmscout::MercatorProjection::angleCos =0.0
protected

Referenced by PixelToGeo(), and Set().

◆ angleNegCos

double osmscout::MercatorProjection::angleNegCos =0.0
protected

◆ angleNegSin

double osmscout::MercatorProjection::angleNegSin =0.0
protected

◆ angleSin

double osmscout::MercatorProjection::angleSin =0.0
protected

Referenced by PixelToGeo(), and Set().

◆ latOffset

double osmscout::MercatorProjection::latOffset =0.0
protected

Absolute and untransformed screen position of lat coordinate.

Referenced by GeoToPixel(), PixelToGeo(), Set(), and osmscout::OpenGLProjection::SetShaderUniforms().

◆ MaxLat

const double osmscout::MercatorProjection::MaxLat = +85.0511
static

Referenced by GeoToPixel(), IsValidFor(), and Set().

◆ MaxLon

const double osmscout::MercatorProjection::MaxLon = +180.0
static

Referenced by IsValidFor(), and Set().

◆ MinLat

const double osmscout::MercatorProjection::MinLat = -85.0511
static

Referenced by GeoToPixel(), IsValidFor(), and Set().

◆ MinLon

const double osmscout::MercatorProjection::MinLon = -180.0
static

Referenced by IsValidFor(), and Set().

◆ scale

double osmscout::MercatorProjection::scale =1.0
protected

◆ scaledLatDeriv

double osmscout::MercatorProjection::scaledLatDeriv =0.0
protected

center scaled by gradtorad * scale

precalculated derivation of "latToYPixel" function in projection

Referenced by GeoToPixel(), Set(), and osmscout::OpenGLProjection::SetShaderUniforms().

◆ scaleGradtorad

double osmscout::MercatorProjection::scaleGradtorad =0.0
protected

Precalculated scale*Gradtorad.

Referenced by GeoToPixel(), PixelToGeo(), Set(), and osmscout::OpenGLProjection::SetShaderUniforms().

◆ useLinearInterpolation

bool osmscout::MercatorProjection::useLinearInterpolation =false
protected

switch to enable linear interpolation of latitude to pixel computation

Referenced by GeoToPixel(), IsLinearInterpolationEnabled(), SetLinearInterpolationUsage(), and osmscout::OpenGLProjection::SetShaderUniforms().

◆ valid

bool osmscout::MercatorProjection::valid =false
protected

The documentation for this class was generated from the following files: