fixed scale_denomitator

This commit is contained in:
Artem Pavlenko 2006-11-17 02:01:21 +00:00
parent 70adefc9ec
commit 81fbe706a6
4 changed files with 9 additions and 25 deletions

View file

@ -76,7 +76,7 @@ namespace mapnik
try try
{ {
projection proj(m_.srs()); // map projection projection proj(m_.srs()); // map projection
double scale_denom = scale_denominator(m_,proj); double scale_denom = scale_denominator(m_,proj.is_geographic());
std::clog << "scale denominator = " << scale_denom << "\n"; std::clog << "scale denominator = " << scale_denom << "\n";
std::vector<Layer>::const_iterator itr = m_.layers().begin(); std::vector<Layer>::const_iterator itr = m_.layers().begin();

View file

@ -26,6 +26,5 @@
namespace mapnik { namespace mapnik {
class Map; class Map;
class projection; MAPNIK_DECL double scale_denominator(Map const& map, bool geographic);
MAPNIK_DECL double scale_denominator(Map const& map,projection const& prj);
} }

View file

@ -173,7 +173,7 @@ namespace mapnik
bool Layer::isVisible(double scale) const bool Layer::isVisible(double scale) const
{ {
return isActive() && scale >= minZoom_ && scale < maxZoom_; return isActive() && scale >= minZoom_ - 1e-6 && scale < maxZoom_ + 1e-6;
} }
void Layer::setSelectable(bool selectable) void Layer::setSelectable(bool selectable)

View file

@ -23,32 +23,17 @@
//$Id$ //$Id$
#include <cmath> #include <cmath>
#include <mapnik/map.hpp> #include <mapnik/map.hpp>
#include <mapnik/projection.hpp>
#include <mapnik/distance.hpp>
#include <mapnik/scale_denominator.hpp> #include <mapnik/scale_denominator.hpp>
namespace mapnik { namespace mapnik {
static const double dpi = 90.0; // display resolution static const double pi = 3.14159265359;
static const double meters_per_degree = 6378137 * 2 * pi/ 360;
double scale_denominator(Map const& map,projection const& prj) double scale_denominator(Map const& map, bool geographic)
{ {
double map_width = map.getWidth(); double denom = map.scale() / 0.00028;
double map_height = map.getHeight(); if (geographic) denom *= meters_per_degree;
Envelope<double> const& extent = map.getCurrentExtent(); return denom;
double x0 = extent.minx();
double y0 = extent.miny();
double x1 = extent.maxx();
double y1 = extent.maxy();
if (!prj.is_geographic())
{
prj.inverse(x0,y0);
prj.inverse(x1,y1);
}
great_circle_distance distance;
double d1 = distance(coord2d(x0,y0),coord2d(x1, y1));
double d0 = sqrt(map_width * map_width + map_height * map_height) / dpi * 0.0254;
return d1 / d0;
} }
} }