applied aspect ratio patch from Frederik Ramm
This commit is contained in:
parent
1b47afde07
commit
376cdeb453
2 changed files with 73 additions and 9 deletions
|
@ -37,6 +37,28 @@ namespace mapnik
|
|||
{
|
||||
class MAPNIK_DECL Map
|
||||
{
|
||||
public:
|
||||
|
||||
enum aspect_fix_mode
|
||||
{
|
||||
/* grow the width or height of the specified geo bbox to fill the map size. default behaviour. */
|
||||
GROW_BBOX,
|
||||
/* grow the width or height of the map to accomodate the specified geo bbox. */
|
||||
GROW_CANVAS,
|
||||
/* shrink the width or height of the specified geo bbox to fill the map size. */
|
||||
SHRINK_BBOX,
|
||||
/* shrink the width or height of the map to accomodate the specified geo bbox. */
|
||||
SHRINK_CANVAS,
|
||||
/* adjust the width of the specified geo bbox, leave height and map size unchanged */
|
||||
ADJUST_BBOX_WIDTH,
|
||||
/* adjust the height of the specified geo bbox, leave width and map size unchanged */
|
||||
ADJUST_BBOX_HEIGHT,
|
||||
/* adjust the width of the map, leave height and geo bbox unchanged */
|
||||
ADJUST_CANVAS_WIDTH,
|
||||
/* adjust the height of the map, leave width and geo bbox unchanged */
|
||||
ADJUST_CANVAS_HEIGHT
|
||||
};
|
||||
private:
|
||||
static const unsigned MIN_MAPSIZE=16;
|
||||
static const unsigned MAX_MAPSIZE=MIN_MAPSIZE<<10;
|
||||
unsigned width_;
|
||||
|
@ -47,8 +69,10 @@ namespace mapnik
|
|||
std::map<std::string,FontSet> fontsets_;
|
||||
std::vector<Layer> layers_;
|
||||
Envelope<double> currentExtent_;
|
||||
aspect_fix_mode aspectFixMode_;
|
||||
|
||||
public:
|
||||
|
||||
typedef std::map<std::string,feature_type_style>::const_iterator const_style_iterator;
|
||||
typedef std::map<std::string,feature_type_style>::iterator style_iterator;
|
||||
|
||||
|
@ -258,6 +282,10 @@ namespace mapnik
|
|||
|
||||
featureset_ptr query_map_point(unsigned index, double x, double y) const;
|
||||
~Map();
|
||||
|
||||
void setAspectFixMode(aspect_fix_mode afm) { aspectFixMode_ = afm; }
|
||||
bool getAspectFixMode() { return aspectFixMode_; }
|
||||
|
||||
private:
|
||||
void fixAspectRatio();
|
||||
};
|
||||
|
|
54
src/map.cpp
54
src/map.cpp
|
@ -34,12 +34,14 @@ namespace mapnik
|
|||
Map::Map()
|
||||
: width_(400),
|
||||
height_(400),
|
||||
srs_("+proj=latlong +datum=WGS84") {}
|
||||
srs_("+proj=latlong +datum=WGS84"),
|
||||
aspectFixMode_(GROW_BBOX) {}
|
||||
|
||||
Map::Map(int width,int height, std::string const& srs)
|
||||
: width_(width),
|
||||
height_(height),
|
||||
srs_(srs) {}
|
||||
srs_(srs),
|
||||
aspectFixMode_(GROW_BBOX) {}
|
||||
|
||||
Map::Map(const Map& rhs)
|
||||
: width_(rhs.width_),
|
||||
|
@ -48,6 +50,7 @@ namespace mapnik
|
|||
background_(rhs.background_),
|
||||
styles_(rhs.styles_),
|
||||
layers_(rhs.layers_),
|
||||
aspectFixMode_(rhs.aspectFixMode_),
|
||||
currentExtent_(rhs.currentExtent_) {}
|
||||
|
||||
Map& Map::operator=(const Map& rhs)
|
||||
|
@ -59,6 +62,7 @@ namespace mapnik
|
|||
background_=rhs.background_;
|
||||
styles_=rhs.styles_;
|
||||
layers_=rhs.layers_;
|
||||
aspectFixMode_=rhs.aspectFixMode_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -295,15 +299,47 @@ namespace mapnik
|
|||
{
|
||||
double ratio1 = (double) width_ / (double) height_;
|
||||
double ratio2 = currentExtent_.width() / currentExtent_.height();
|
||||
|
||||
if (ratio2 > ratio1)
|
||||
if (ratio1 == ratio2) return;
|
||||
|
||||
switch(aspectFixMode_)
|
||||
{
|
||||
currentExtent_.height(currentExtent_.width() / ratio1);
|
||||
case ADJUST_BBOX_HEIGHT:
|
||||
currentExtent_.height(currentExtent_.width() / ratio1);
|
||||
break;
|
||||
case ADJUST_BBOX_WIDTH:
|
||||
currentExtent_.width(currentExtent_.height() * ratio1);
|
||||
break;
|
||||
case ADJUST_CANVAS_HEIGHT:
|
||||
height_ = int (width_ / ratio2 + 0.5);
|
||||
break;
|
||||
case ADJUST_CANVAS_WIDTH:
|
||||
width_ = int (height_ * ratio2 + 0.5);
|
||||
break;
|
||||
case GROW_BBOX:
|
||||
if (ratio2 > ratio1)
|
||||
currentExtent_.height(currentExtent_.width() / ratio1);
|
||||
else
|
||||
currentExtent_.width(currentExtent_.height() * ratio1);
|
||||
break;
|
||||
case SHRINK_BBOX:
|
||||
if (ratio2 < ratio1)
|
||||
currentExtent_.height(currentExtent_.width() / ratio1);
|
||||
else
|
||||
currentExtent_.width(currentExtent_.height() * ratio1);
|
||||
break;
|
||||
case GROW_CANVAS:
|
||||
if (ratio2 > ratio1)
|
||||
width_ = (int) (height_ * ratio2 + 0.5);
|
||||
else
|
||||
height_ = int (width_ / ratio2 + 0.5);
|
||||
break;
|
||||
case SHRINK_CANVAS:
|
||||
if (ratio2 > ratio1)
|
||||
height_ = int (width_ / ratio2 + 0.5);
|
||||
else
|
||||
width_ = (int) (height_ * ratio2 + 0.5);
|
||||
break;
|
||||
}
|
||||
else if (ratio2 < ratio1)
|
||||
{
|
||||
currentExtent_.width(currentExtent_.height() * ratio1);
|
||||
}
|
||||
}
|
||||
|
||||
const Envelope<double>& Map::getCurrentExtent() const
|
||||
|
|
Loading…
Reference in a new issue