libosmscout  0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules
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. More...
 
bool IsLinearInterpolationEnabled () const
 
bool IsValid () const override
 
bool IsValidFor (const GeoCoord &coord) const override
 Return true if given coordinate is valid for this projection. More...
 
 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)
 
MercatorProjectionoperator= (const MercatorProjection &)=default
 
MercatorProjectionoperator= (MercatorProjection &&)=default
 
bool PixelToGeo (double x, double y, GeoCoord &coord) const override
 Converts a pixel coordinate to a geo coordinate. More...
 
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. More...
 
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. More...
 
 ~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. More...
 
double ConvertPixelToWidth (double pixel) const
 Convert a width in pixel into the equivalent mm size based on the given DPI. More...
 
double ConvertWidthToPixel (double width) const
 Convert a width in mm into the equivalent pixel size based on the given DPI. More...
 
double GetAngle () const
 Returns the angle in radians ([0..2*PI[) of the display in relation to the north. More...
 
GeoCoord GetCenter () const
 
GeoBox GetDimensions () const
 
double GetDPI () const
 Return the DPI as part of the projection. More...
 
size_t GetHeight () const
 Returns the height of the screen. More...
 
Magnification GetMagnification () const
 Return the magnification as part of the projection. More...
 
double GetMeterInMM () const
 Returns the number of on screen millimeters for one meter on the ground. More...
 
double GetMeterInPixel () const
 Returns the number of on screen pixel for one meter on the ground. More...
 
double GetPixelSize () const
 Returns the size of a pixel in meter. More...
 
ScreenBox GetScreenBox () const
 Return a ScreenBox instance for the screen. More...
 
size_t GetWidth () const
 Returns the width of the screen. More...
 
Projectionoperator= (const Projection &)=default
 
Projectionoperator= (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. More...
 
double scale =1.0
 
double scaledLatDeriv =0.0
 precalculated derivation of "latToYPixel" function in projection More...
 
double scaleGradtorad =0.0
 Precalculated scale*Gradtorad. More...
 
bool useLinearInterpolation =false
 switch to enable linear interpolation of latitude to pixel computation More...
 
bool valid =false
 projection is valid More...
 
- Protected Attributes inherited from osmscout::Projection
double angle =0.0
 Display rotation angle in radians, canvas clockwise. More...
 
GeoBox boundingBox
 Bounding box of the current projection on the ground. More...
 
GeoCoord center
 Coordinate of the center of the displayed area. More...
 
double dpi =0.0
 Screen DPI. More...
 
size_t height =0
 Height of image. More...
 
Magnification magnification
 Current magnification. More...
 
double meterInMM =0.0
 Number of on screen millimeters for one meter on the ground. More...
 
double meterInPixel =0.0
 Number of on screen pixel for one meter on the ground. More...
 
double pixelSize =0.0
 Size of a pixel in meter. More...
 
size_t width =0
 Width of image. More...
 

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

◆ MercatorProjection() [3/3]

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

◆ ~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
inline

◆ IsValid()

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

◆ 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(), and osmscout::GeoCoord::GetLon().

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

◆ Move()

◆ MoveDown()

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

◆ MoveLeft()

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

◆ MoveRight()

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

◆ MoveUp()

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

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ 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::GeoBox::CropTo(), osmscout::Projection::dpi, osmscout::Earth::extentMeter, osmscout::GeoCoord::GetLat(), osmscout::Magnification::GetMagnification(), osmscout::gradtorad, osmscout::Projection::height, osmscout::GeoBox::Include(), IsValidFor(), latOffset, osmscout::Projection::magnification, MaxLat, MaxLon, osmscout::Projection::meterInMM, osmscout::Projection::meterInPixel, MinLat, MinLon, osmscout::Projection::pixelSize, PixelToGeo(), scale, scaledLatDeriv, scaleGradtorad, 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.

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

Member Data Documentation

◆ angleCos

double osmscout::MercatorProjection::angleCos =0.0
protected

Referenced by PixelToGeo(), and Set().

◆ angleNegCos

double osmscout::MercatorProjection::angleNegCos =0.0
protected

Referenced by GeoToPixel(), and Set().

◆ angleNegSin

double osmscout::MercatorProjection::angleNegSin =0.0
protected

Referenced by GeoToPixel(), and Set().

◆ 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(), and Set().

◆ MaxLat

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

Referenced by GeoToPixel(), and Set().

◆ MaxLon

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

Referenced by Set().

◆ MinLat

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

Referenced by GeoToPixel(), and Set().

◆ MinLon

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

Referenced by Set().

◆ scale

double osmscout::MercatorProjection::scale =1.0
protected

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

◆ scaledLatDeriv

double osmscout::MercatorProjection::scaledLatDeriv =0.0
protected

precalculated derivation of "latToYPixel" function in projection

center scaled by gradtorad * scale

Referenced by GeoToPixel(), and Set().

◆ scaleGradtorad

double osmscout::MercatorProjection::scaleGradtorad =0.0
protected

Precalculated scale*Gradtorad.

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

◆ useLinearInterpolation

bool osmscout::MercatorProjection::useLinearInterpolation =false
protected

switch to enable linear interpolation of latitude to pixel computation

Referenced by GeoToPixel().

◆ valid

bool osmscout::MercatorProjection::valid =false
protected

projection is valid

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


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