remove aspect_fix_mode as a map property

This commit is contained in:
Dane Springmeyer 2013-03-13 15:45:16 -07:00
parent 5e1f81d954
commit a4675f2d53
6 changed files with 10 additions and 148 deletions

View file

@ -8,6 +8,8 @@ For a complete change history, see the git log.
## Future ## Future
- Removed `Map.aspect_fix_mode` (#1758)
- Added `text-halo-rasterizer` property. Set to `fast` for lower quality but faster - Added `text-halo-rasterizer` property. Set to `fast` for lower quality but faster
halo rendering (#1298) halo rendering (#1298)

View file

@ -137,18 +137,6 @@ void export_map()
{ {
using namespace boost::python; using namespace boost::python;
// aspect ratio fix modes
mapnik::enumeration_<mapnik::aspect_fix_mode_e>("aspect_fix_mode")
.value("GROW_BBOX", mapnik::Map::GROW_BBOX)
.value("GROW_CANVAS",mapnik::Map::GROW_CANVAS)
.value("SHRINK_BBOX",mapnik::Map::SHRINK_BBOX)
.value("SHRINK_CANVAS",mapnik::Map::SHRINK_CANVAS)
.value("ADJUST_BBOX_WIDTH",mapnik::Map::ADJUST_BBOX_WIDTH)
.value("ADJUST_BBOX_HEIGHT",mapnik::Map::ADJUST_BBOX_HEIGHT)
.value("ADJUST_CANVAS_WIDTH",mapnik::Map::ADJUST_CANVAS_WIDTH)
.value("ADJUST_CANVAS_HEIGHT", mapnik::Map::ADJUST_CANVAS_HEIGHT)
;
class_<std::vector<layer> >("Layers") class_<std::vector<layer> >("Layers")
.def(vector_indexing_suite<std::vector<layer> >()) .def(vector_indexing_suite<std::vector<layer> >())
; ;
@ -385,17 +373,6 @@ void export_map()
//.def("__deepcopy__",&map_deepcopy) //.def("__deepcopy__",&map_deepcopy)
.add_property("parameters",make_function(params_nonconst,return_value_policy<reference_existing_object>()),"TODO") .add_property("parameters",make_function(params_nonconst,return_value_policy<reference_existing_object>()),"TODO")
.add_property("aspect_fix_mode",
&Map::get_aspect_fix_mode,
&Map::set_aspect_fix_mode,
// TODO - how to add arg info to properties?
//(arg("aspect_fix_mode")),
"Get/Set aspect fix mode.\n"
"Usage:\n"
"\n"
">>> m.aspect_fix_mode = aspect_fix_mode.GROW_BBOX\n"
)
.add_property("background",make_function .add_property("background",make_function
(&Map::background,return_value_policy<copy_const_reference>()), (&Map::background,return_value_policy<copy_const_reference>()),
&Map::set_background, &Map::set_background,

View file

@ -43,29 +43,6 @@ class CoordTransform;
class MAPNIK_DECL Map 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,
//
aspect_fix_mode_MAX
};
private: private:
static const unsigned MIN_MAPSIZE=16; static const unsigned MIN_MAPSIZE=16;
@ -79,7 +56,6 @@ private:
std::map<std::string,feature_type_style> styles_; std::map<std::string,feature_type_style> styles_;
std::map<std::string,font_set> fontsets_; std::map<std::string,font_set> fontsets_;
std::vector<layer> layers_; std::vector<layer> layers_;
aspect_fix_mode aspectFixMode_;
box2d<double> current_extent_; box2d<double> current_extent_;
boost::optional<box2d<double> > maximum_extent_; boost::optional<box2d<double> > maximum_extent_;
std::string base_path_; std::string base_path_;
@ -324,7 +300,6 @@ public:
/*! \brief Zoom the map to a bounding box. /*! \brief Zoom the map to a bounding box.
* *
* Aspect is handled automatic if not fitting to width/height.
* @param box The bounding box where to zoom. * @param box The bounding box where to zoom.
*/ */
void zoom_to_box(box2d<double> const& box); void zoom_to_box(box2d<double> const& box);
@ -384,9 +359,6 @@ public:
~Map(); ~Map();
inline void set_aspect_fix_mode(aspect_fix_mode afm) { aspectFixMode_ = afm; }
inline aspect_fix_mode get_aspect_fix_mode() const { return aspectFixMode_; }
/*! /*!
* @brief Get extra, arbitrary Parameters attached to the Map * @brief Get extra, arbitrary Parameters attached to the Map
*/ */
@ -401,12 +373,8 @@ public:
* @brief Set extra, arbitary Parameters of the Map * @brief Set extra, arbitary Parameters of the Map
*/ */
void set_extra_parameters(parameters& params); void set_extra_parameters(parameters& params);
private:
void fixAspectRatio();
}; };
DEFINE_ENUM(aspect_fix_mode_e,Map::aspect_fix_mode);
} }
#endif // MAPNIK_MAP_HPP #endif // MAPNIK_MAP_HPP

View file

@ -62,7 +62,6 @@ namespace mapnik { namespace util {
// * styles_(rhs.styles_), // * styles_(rhs.styles_),
// fontsets_(rhs.fontsets_), // fontsets_(rhs.fontsets_),
// * layers_(rhs.layers_), // * layers_(rhs.layers_),
// aspectFixMode_(rhs.aspectFixMode_),
// current_extent_(rhs.current_extent_), // current_extent_(rhs.current_extent_),
// * maximum_extent_(rhs.maximum_extent_), // * maximum_extent_(rhs.maximum_extent_),
// * base_path_(rhs.base_path_), // * base_path_(rhs.base_path_),

View file

@ -45,26 +45,11 @@
namespace mapnik namespace mapnik
{ {
static const char * aspect_fix_mode_strings[] = {
"GROW_BBOX",
"GROW_CANVAS",
"SHRINK_BBOX",
"SHRINK_CANVAS",
"ADJUST_BBOX_WIDTH",
"ADJUST_BBOX_HEIGHT",
"ADJUST_CANVAS_WIDTH",
"ADJUST_CANVAS_HEIGHT",
""
};
IMPLEMENT_ENUM( aspect_fix_mode_e, aspect_fix_mode_strings )
Map::Map() Map::Map()
: width_(400), : width_(400),
height_(400), height_(400),
srs_(MAPNIK_LONGLAT_PROJ), srs_(MAPNIK_LONGLAT_PROJ),
buffer_size_(0), buffer_size_(0),
aspectFixMode_(GROW_BBOX),
base_path_("") {} base_path_("") {}
Map::Map(int width,int height, std::string const& srs) Map::Map(int width,int height, std::string const& srs)
@ -72,7 +57,6 @@ Map::Map(int width,int height, std::string const& srs)
height_(height), height_(height),
srs_(srs), srs_(srs),
buffer_size_(0), buffer_size_(0),
aspectFixMode_(GROW_BBOX),
base_path_("") {} base_path_("") {}
Map::Map(Map const& rhs) Map::Map(Map const& rhs)
@ -85,7 +69,6 @@ Map::Map(Map const& rhs)
styles_(rhs.styles_), styles_(rhs.styles_),
fontsets_(rhs.fontsets_), fontsets_(rhs.fontsets_),
layers_(rhs.layers_), layers_(rhs.layers_),
aspectFixMode_(rhs.aspectFixMode_),
current_extent_(rhs.current_extent_), current_extent_(rhs.current_extent_),
maximum_extent_(rhs.maximum_extent_), maximum_extent_(rhs.maximum_extent_),
base_path_(rhs.base_path_), base_path_(rhs.base_path_),
@ -105,7 +88,6 @@ Map& Map::operator=(Map const& rhs)
styles_=rhs.styles_; styles_=rhs.styles_;
fontsets_ = rhs.fontsets_; fontsets_ = rhs.fontsets_;
layers_=rhs.layers_; layers_=rhs.layers_;
aspectFixMode_=rhs.aspectFixMode_;
maximum_extent_=rhs.maximum_extent_; maximum_extent_=rhs.maximum_extent_;
base_path_=rhs.base_path_; base_path_=rhs.base_path_;
extra_params_=rhs.extra_params_; extra_params_=rhs.extra_params_;
@ -242,38 +224,31 @@ unsigned Map::height() const
void Map::set_width(unsigned width) void Map::set_width(unsigned width)
{ {
if (width != width_ && if (width >= MIN_MAPSIZE &&
width >= MIN_MAPSIZE &&
width <= MAX_MAPSIZE) width <= MAX_MAPSIZE)
{ {
width_=width; width_ = width;
fixAspectRatio();
} }
} }
void Map::set_height(unsigned height) void Map::set_height(unsigned height)
{ {
if (height != height_ && if (height >= MIN_MAPSIZE &&
height >= MIN_MAPSIZE &&
height <= MAX_MAPSIZE) height <= MAX_MAPSIZE)
{ {
height_=height; height_ = height;
fixAspectRatio();
} }
} }
void Map::resize(unsigned width,unsigned height) void Map::resize(unsigned width,unsigned height)
{ {
if (width != width_ && if (width >= MIN_MAPSIZE &&
height != height_ &&
width >= MIN_MAPSIZE &&
width <= MAX_MAPSIZE && width <= MAX_MAPSIZE &&
height >= MIN_MAPSIZE && height >= MIN_MAPSIZE &&
height <= MAX_MAPSIZE) height <= MAX_MAPSIZE)
{ {
width_=width; width_ = width;
height_=height; height_ = height;
fixAspectRatio();
} }
} }
@ -351,7 +326,6 @@ void Map::zoom(double factor)
center.y - 0.5 * h, center.y - 0.5 * h,
center.x + 0.5 * w, center.x + 0.5 * w,
center.y + 0.5 * h); center.y + 0.5 * h);
fixAspectRatio();
} }
void Map::zoom_all() void Map::zoom_all()
@ -428,64 +402,7 @@ void Map::zoom_all()
void Map::zoom_to_box(box2d<double> const& box) void Map::zoom_to_box(box2d<double> const& box)
{ {
current_extent_=box; current_extent_ = box;
fixAspectRatio();
}
void Map::fixAspectRatio()
{
if (current_extent_.width() > 0 && current_extent_.height() > 0)
{
double ratio1 = static_cast<double>(width_) / static_cast<double>(height_);
double ratio2 = current_extent_.width() / current_extent_.height();
if (ratio1 == ratio2) return;
switch(aspectFixMode_)
{
case ADJUST_BBOX_HEIGHT:
current_extent_.height(current_extent_.width() / ratio1);
break;
case ADJUST_BBOX_WIDTH:
current_extent_.width(current_extent_.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)
current_extent_.height(current_extent_.width() / ratio1);
else
current_extent_.width(current_extent_.height() * ratio1);
break;
case SHRINK_BBOX:
if (ratio2 < ratio1)
current_extent_.height(current_extent_.width() / ratio1);
else
current_extent_.width(current_extent_.height() * ratio1);
break;
case GROW_CANVAS:
if (ratio2 > ratio1)
width_ = static_cast<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_ = static_cast<int>(height_ * ratio2 + 0.5);
break;
default:
if (ratio2 > ratio1)
current_extent_.height(current_extent_.width() / ratio1);
else
current_extent_.width(current_extent_.height() * ratio1);
break;
}
}
} }
box2d<double> const& Map::get_current_extent() const box2d<double> const& Map::get_current_extent() const

View file

@ -23,7 +23,6 @@ def setup():
# eq_(m2.base, m1.base) # eq_(m2.base, m1.base)
# eq_(m2.background, m1.background) # eq_(m2.background, m1.background)
# eq_(m2.buffer_size, m1.buffer_size) # eq_(m2.buffer_size, m1.buffer_size)
# eq_(m2.aspect_fix_mode, m1.aspect_fix_mode)
# eq_(m2.envelope(),m1.envelope()) # eq_(m2.envelope(),m1.envelope())
# eq_(m2.buffered_envelope(),m1.buffered_envelope()) # eq_(m2.buffered_envelope(),m1.buffered_envelope())
# eq_(m2.scale(),m1.scale()) # eq_(m2.scale(),m1.scale())