simplify scale_denominator interface

This commit is contained in:
Dane Springmeyer 2013-02-20 18:02:28 -08:00
parent 12dfcef3a0
commit 86a873857f
6 changed files with 12 additions and 10 deletions

View file

@ -8,6 +8,8 @@ For a complete change history, see the git log.
## Future ## Future
- Changed scale_denominator C++ interface to take scale as first argument rather than map.
- Added support for `background-image` in cairo_renderer (#1724) - Added support for `background-image` in cairo_renderer (#1724)
- Added Layer `buffer-size` that can be used to override Map `buffer-size` to avoid - Added Layer `buffer-size` that can be used to override Map `buffer-size` to avoid

View file

@ -329,7 +329,7 @@ void render_to_file3(const mapnik::Map& map,
double scale_denominator(mapnik::Map const &map, bool geographic) double scale_denominator(mapnik::Map const &map, bool geographic)
{ {
return mapnik::scale_denominator(map, geographic); return mapnik::scale_denominator(map.scale(), geographic);
} }
// http://docs.python.org/c-api/exceptions.html#standard-exceptions // http://docs.python.org/c-api/exceptions.html#standard-exceptions
@ -691,6 +691,7 @@ BOOST_PYTHON_MODULE(_mapnik)
#endif #endif
def("scale_denominator", &scale_denominator, def("scale_denominator", &scale_denominator,
(arg("map"),arg("is_geographic")),
"\n" "\n"
"Return the Map Scale Denominator.\n" "Return the Map Scale Denominator.\n"
"Also available as Map.scale_denominator()\n" "Also available as Map.scale_denominator()\n"

View file

@ -157,7 +157,7 @@ void feature_style_processor<Processor>::apply()
try try
{ {
projection proj(m_.srs(),true); projection proj(m_.srs(),true);
double scale_denom = mapnik::scale_denominator(m_,proj.is_geographic()); double scale_denom = mapnik::scale_denominator(m_.scale(),proj.is_geographic());
scale_denom *= scale_factor_; scale_denom *= scale_factor_;
BOOST_FOREACH ( layer const& lyr, m_.layers() ) BOOST_FOREACH ( layer const& lyr, m_.layers() )
@ -191,7 +191,7 @@ void feature_style_processor<Processor>::apply(mapnik::layer const& lyr, std::se
try try
{ {
projection proj(m_.srs(),true); projection proj(m_.srs(),true);
double scale_denom = mapnik::scale_denominator(m_,proj.is_geographic()); double scale_denom = mapnik::scale_denominator(m_.scale(),proj.is_geographic());
scale_denom *= scale_factor_; scale_denom *= scale_factor_;
if (lyr.visible(scale_denom)) if (lyr.visible(scale_denom))

View file

@ -29,7 +29,7 @@
namespace mapnik { namespace mapnik {
class Map; class Map;
MAPNIK_DECL double scale_denominator(Map const& map, bool geographic); MAPNIK_DECL double scale_denominator(double map_scale, bool geographic);
} }
#endif // MAPNIK_SCALE_DENOMINATOR_HPP #endif // MAPNIK_SCALE_DENOMINATOR_HPP

View file

@ -530,7 +530,7 @@ double Map::scale() const
double Map::scale_denominator() const double Map::scale_denominator() const
{ {
projection map_proj(srs_); projection map_proj(srs_);
return mapnik::scale_denominator( *this, map_proj.is_geographic()); return mapnik::scale_denominator( scale(), map_proj.is_geographic());
} }
CoordTransform Map::view_transform() const CoordTransform Map::view_transform() const

View file

@ -22,19 +22,18 @@
// mapnik // mapnik
#include <mapnik/scale_denominator.hpp> #include <mapnik/scale_denominator.hpp>
#include <mapnik/map.hpp> #include <mapnik/global.hpp>
// stl // stl
#include <cmath> #include <cmath>
namespace mapnik { namespace mapnik {
static const double pi = 3.14159265359; static const double meters_per_degree = 6378137 * 2 * M_PI / 360;
static const double meters_per_degree = 6378137 * 2 * pi/ 360;
double scale_denominator(Map const& map, bool geographic) double scale_denominator(double map_scale, bool geographic)
{ {
double denom = map.scale() / 0.00028; double denom = map_scale / 0.00028;
if (geographic) denom *= meters_per_degree; if (geographic) denom *= meters_per_degree;
return denom; return denom;
} }