2006-03-31 12:32:02 +02:00
|
|
|
/*****************************************************************************
|
2012-02-02 02:53:35 +01:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
2005-06-14 17:06:59 +02:00
|
|
|
*
|
2011-10-23 15:04:25 +02:00
|
|
|
* Copyright (C) 2011 Artem Pavlenko
|
2005-06-14 17:06:59 +02:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
2005-06-14 17:06:59 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2006-03-31 12:32:02 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-06-14 17:06:59 +02:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
*****************************************************************************/
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2012-04-08 02:20:56 +02:00
|
|
|
//mapnik
|
|
|
|
#include <mapnik/debug.hpp>
|
2007-10-08 19:42:41 +02:00
|
|
|
#include <mapnik/map.hpp>
|
2006-10-04 13:22:18 +02:00
|
|
|
#include <mapnik/datasource.hpp>
|
2006-10-16 15:44:52 +02:00
|
|
|
#include <mapnik/projection.hpp>
|
2006-12-06 21:26:59 +01:00
|
|
|
#include <mapnik/filter_featureset.hpp>
|
|
|
|
#include <mapnik/hit_test_filter.hpp>
|
2009-01-14 07:12:55 +01:00
|
|
|
#include <mapnik/scale_denominator.hpp>
|
2012-04-08 02:56:18 +02:00
|
|
|
#include <mapnik/config_error.hpp>
|
2012-04-02 20:33:29 +02:00
|
|
|
#include <mapnik/config.hpp> // for PROJ_ENVELOPE_POINTS
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2012-03-10 01:20:50 +01:00
|
|
|
// boost
|
|
|
|
#include <boost/make_shared.hpp>
|
|
|
|
|
2011-08-11 23:13:55 +02:00
|
|
|
// icu
|
|
|
|
#include <unicode/uversion.h>
|
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
namespace mapnik
|
|
|
|
{
|
2009-03-21 13:39:06 +01:00
|
|
|
|
2010-07-06 02:37:05 +02:00
|
|
|
/** Call cache_metawriters for each symbolizer.*/
|
|
|
|
struct metawriter_cache_dispatch : public boost::static_visitor<>
|
|
|
|
{
|
|
|
|
metawriter_cache_dispatch (Map const &m) : m_(m) {}
|
|
|
|
|
|
|
|
template <typename T> void operator () (T &sym) const
|
|
|
|
{
|
|
|
|
sym.cache_metawriters(m_);
|
|
|
|
}
|
|
|
|
|
|
|
|
Map const &m_;
|
|
|
|
};
|
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
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",
|
|
|
|
""
|
|
|
|
};
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-04-01 09:20:41 +02:00
|
|
|
IMPLEMENT_ENUM( aspect_fix_mode_e, aspect_fix_mode_strings )
|
2009-03-21 13:39:06 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
Map::Map()
|
2012-02-02 02:53:35 +01:00
|
|
|
: width_(400),
|
|
|
|
height_(400),
|
|
|
|
srs_("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"),
|
|
|
|
buffer_size_(0),
|
|
|
|
aspectFixMode_(GROW_BBOX),
|
|
|
|
base_path_("") {}
|
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
Map::Map(int width,int height, std::string const& srs)
|
|
|
|
: width_(width),
|
|
|
|
height_(height),
|
|
|
|
srs_(srs),
|
|
|
|
buffer_size_(0),
|
2011-06-01 20:53:47 +02:00
|
|
|
aspectFixMode_(GROW_BBOX),
|
|
|
|
base_path_("") {}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
Map::Map(const Map& rhs)
|
|
|
|
: width_(rhs.width_),
|
|
|
|
height_(rhs.height_),
|
|
|
|
srs_(rhs.srs_),
|
|
|
|
buffer_size_(rhs.buffer_size_),
|
|
|
|
background_(rhs.background_),
|
2010-07-19 13:10:03 +02:00
|
|
|
background_image_(rhs.background_image_),
|
2010-06-02 13:03:30 +02:00
|
|
|
styles_(rhs.styles_),
|
2010-07-06 02:37:05 +02:00
|
|
|
metawriters_(rhs.metawriters_),
|
2011-12-12 11:16:39 +01:00
|
|
|
fontsets_(rhs.fontsets_),
|
2010-06-02 13:03:30 +02:00
|
|
|
layers_(rhs.layers_),
|
|
|
|
aspectFixMode_(rhs.aspectFixMode_),
|
2011-04-14 04:20:33 +02:00
|
|
|
current_extent_(rhs.current_extent_),
|
|
|
|
maximum_extent_(rhs.maximum_extent_),
|
2011-05-26 01:51:40 +02:00
|
|
|
base_path_(rhs.base_path_),
|
2011-12-03 02:48:09 +01:00
|
|
|
extra_params_(rhs.extra_params_) {}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
Map& Map::operator=(const Map& rhs)
|
|
|
|
{
|
|
|
|
if (this==&rhs) return *this;
|
|
|
|
width_=rhs.width_;
|
|
|
|
height_=rhs.height_;
|
|
|
|
srs_=rhs.srs_;
|
|
|
|
buffer_size_ = rhs.buffer_size_;
|
|
|
|
background_=rhs.background_;
|
2010-07-19 13:10:03 +02:00
|
|
|
background_image_=rhs.background_image_;
|
2010-06-02 13:03:30 +02:00
|
|
|
styles_=rhs.styles_;
|
2010-07-06 02:37:05 +02:00
|
|
|
metawriters_ = rhs.metawriters_;
|
2011-12-12 11:16:39 +01:00
|
|
|
fontsets_ = rhs.fontsets_;
|
2010-06-02 13:03:30 +02:00
|
|
|
layers_=rhs.layers_;
|
|
|
|
aspectFixMode_=rhs.aspectFixMode_;
|
2011-04-14 04:20:33 +02:00
|
|
|
maximum_extent_=rhs.maximum_extent_;
|
2011-05-26 01:51:40 +02:00
|
|
|
base_path_=rhs.base_path_;
|
2011-12-03 02:48:09 +01:00
|
|
|
extra_params_=rhs.extra_params_;
|
2010-06-02 13:03:30 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
std::map<std::string,feature_type_style> const& Map::styles() const
|
|
|
|
{
|
|
|
|
return styles_;
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
std::map<std::string,feature_type_style> & Map::styles()
|
|
|
|
{
|
|
|
|
return styles_;
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
Map::style_iterator Map::begin_styles()
|
|
|
|
{
|
|
|
|
return styles_.begin();
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
Map::style_iterator Map::end_styles()
|
|
|
|
{
|
|
|
|
return styles_.end();
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
Map::const_style_iterator Map::begin_styles() const
|
|
|
|
{
|
|
|
|
return styles_.begin();
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
Map::const_style_iterator Map::end_styles() const
|
|
|
|
{
|
|
|
|
return styles_.end();
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
|
|
|
bool Map::insert_style(std::string const& name,feature_type_style const& style)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
return styles_.insert(make_pair(name,style)).second;
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
|
|
|
void Map::remove_style(std::string const& name)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
styles_.erase(name);
|
|
|
|
}
|
2010-07-06 02:37:05 +02:00
|
|
|
|
|
|
|
boost::optional<feature_type_style const&> Map::find_style(std::string const& name) const
|
|
|
|
{
|
|
|
|
std::map<std::string,feature_type_style>::const_iterator itr = styles_.find(name);
|
|
|
|
if (itr != styles_.end())
|
|
|
|
return boost::optional<feature_type_style const&>(itr->second);
|
|
|
|
else
|
|
|
|
return boost::optional<feature_type_style const&>() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Map::insert_metawriter(std::string const& name, metawriter_ptr const& writer)
|
|
|
|
{
|
|
|
|
return metawriters_.insert(make_pair(name, writer)).second;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Map::remove_metawriter(std::string const& name)
|
|
|
|
{
|
|
|
|
metawriters_.erase(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
metawriter_ptr Map::find_metawriter(std::string const& name) const
|
|
|
|
{
|
|
|
|
std::map<std::string, metawriter_ptr>::const_iterator itr = metawriters_.find(name);
|
|
|
|
if (itr != metawriters_.end())
|
|
|
|
return itr->second;
|
|
|
|
else
|
|
|
|
return metawriter_ptr();
|
|
|
|
}
|
|
|
|
|
2010-07-12 17:27:33 +02:00
|
|
|
std::map<std::string,metawriter_ptr> const& Map::metawriters() const
|
|
|
|
{
|
|
|
|
return metawriters_;
|
|
|
|
}
|
|
|
|
|
|
|
|
Map::const_metawriter_iterator Map::begin_metawriters() const
|
|
|
|
{
|
|
|
|
return metawriters_.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
Map::const_metawriter_iterator Map::end_metawriters() const
|
|
|
|
{
|
|
|
|
return metawriters_.end();
|
|
|
|
}
|
|
|
|
|
2012-02-02 02:53:35 +01:00
|
|
|
bool Map::insert_fontset(std::string const& name, font_set const& fontset)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
return fontsets_.insert(make_pair(name, fontset)).second;
|
|
|
|
}
|
2011-12-20 21:34:27 +01:00
|
|
|
|
|
|
|
boost::optional<font_set const&> Map::find_fontset(std::string const& name) const
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
std::map<std::string,font_set>::const_iterator itr = fontsets_.find(name);
|
2011-12-20 21:34:27 +01:00
|
|
|
if (itr != fontsets_.end())
|
|
|
|
return boost::optional<font_set const&>(itr->second);
|
|
|
|
else
|
|
|
|
return boost::optional<font_set const&>() ;
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2008-06-29 12:58:48 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
std::map<std::string,font_set> const& Map::fontsets() const
|
|
|
|
{
|
|
|
|
return fontsets_;
|
|
|
|
}
|
2009-01-17 21:18:41 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
std::map<std::string,font_set> & Map::fontsets()
|
|
|
|
{
|
|
|
|
return fontsets_;
|
|
|
|
}
|
2009-01-17 21:18:41 +01:00
|
|
|
|
2010-06-25 17:23:35 +02:00
|
|
|
size_t Map::layer_count() const
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
return layers_.size();
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
void Map::addLayer(const layer& l)
|
|
|
|
{
|
|
|
|
layers_.push_back(l);
|
|
|
|
}
|
2010-07-06 02:37:05 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
void Map::removeLayer(size_t index)
|
|
|
|
{
|
|
|
|
layers_.erase(layers_.begin()+index);
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
|
|
|
void Map::remove_all()
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
layers_.clear();
|
|
|
|
styles_.clear();
|
2010-07-06 02:37:05 +02:00
|
|
|
metawriters_.clear();
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
const layer& Map::getLayer(size_t index) const
|
|
|
|
{
|
|
|
|
return layers_[index];
|
|
|
|
}
|
2006-03-28 17:39:38 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
layer& Map::getLayer(size_t index)
|
|
|
|
{
|
|
|
|
return layers_[index];
|
|
|
|
}
|
2006-03-28 17:39:38 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
std::vector<layer> const& Map::layers() const
|
|
|
|
{
|
|
|
|
return layers_;
|
|
|
|
}
|
1. hit_test implementation for geometry objects:
bool hit_test(double x, double y, double tol);
2. added image_view(unsigned x, unsigned y, unsigned width, unsigned height)
allowing to select region from image data e.g (in Python):
im = Image(2048,2048)
view = im.view(0,0,256,256)
save_to_file(filename,type, view)
3. changed envelope method to return vy value in datasource classes
4. features_at_point impl for shape and postgis plug-ins
2006-11-25 12:02:59 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
std::vector<layer> & Map::layers()
|
|
|
|
{
|
|
|
|
return layers_;
|
|
|
|
}
|
1. hit_test implementation for geometry objects:
bool hit_test(double x, double y, double tol);
2. added image_view(unsigned x, unsigned y, unsigned width, unsigned height)
allowing to select region from image data e.g (in Python):
im = Image(2048,2048)
view = im.view(0,0,256,256)
save_to_file(filename,type, view)
3. changed envelope method to return vy value in datasource classes
4. features_at_point impl for shape and postgis plug-ins
2006-11-25 12:02:59 +01:00
|
|
|
|
2010-06-25 17:23:35 +02:00
|
|
|
unsigned Map::width() const
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
return width_;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-25 17:23:35 +02:00
|
|
|
unsigned Map::height() const
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
return height_;
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-25 17:23:35 +02:00
|
|
|
void Map::set_width(unsigned width)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
if (width >= MIN_MAPSIZE && width <= MAX_MAPSIZE)
|
2005-11-24 16:51:29 +01:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
width_=width;
|
|
|
|
fixAspectRatio();
|
2012-02-02 02:53:35 +01:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2005-11-24 16:51:29 +01:00
|
|
|
|
2010-06-25 17:23:35 +02:00
|
|
|
void Map::set_height(unsigned height)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
if (height >= MIN_MAPSIZE && height <= MAX_MAPSIZE)
|
2005-11-24 16:51:29 +01:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
height_=height;
|
|
|
|
fixAspectRatio();
|
2005-11-24 16:51:29 +01:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
void Map::resize(unsigned width,unsigned height)
|
|
|
|
{
|
|
|
|
if (width >= MIN_MAPSIZE && width <= MAX_MAPSIZE &&
|
|
|
|
height >= MIN_MAPSIZE && height <= MAX_MAPSIZE)
|
2005-11-24 16:51:29 +01:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
width_=width;
|
|
|
|
height_=height;
|
|
|
|
fixAspectRatio();
|
2005-11-24 16:51:29 +01:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
std::string const& Map::srs() const
|
|
|
|
{
|
|
|
|
return srs_;
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
void Map::set_srs(std::string const& srs)
|
|
|
|
{
|
|
|
|
srs_ = srs;
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
void Map::set_buffer_size( int buffer_size)
|
|
|
|
{
|
|
|
|
buffer_size_ = buffer_size;
|
|
|
|
}
|
2008-09-21 12:14:38 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
int Map::buffer_size() const
|
|
|
|
{
|
|
|
|
return buffer_size_;
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
boost::optional<color> const& Map::background() const
|
|
|
|
{
|
|
|
|
return background_;
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
void Map::set_background(const color& c)
|
|
|
|
{
|
|
|
|
background_ = c;
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-07-19 13:10:03 +02:00
|
|
|
boost::optional<std::string> const& Map::background_image() const
|
|
|
|
{
|
|
|
|
return background_image_;
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-07-19 13:10:03 +02:00
|
|
|
void Map::set_background_image(std::string const& image_filename)
|
|
|
|
{
|
|
|
|
background_image_ = image_filename;
|
|
|
|
}
|
|
|
|
|
2011-04-14 04:20:33 +02:00
|
|
|
void Map::set_maximum_extent(box2d<double> const& box)
|
|
|
|
{
|
|
|
|
maximum_extent_ = box;
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-04-14 04:20:33 +02:00
|
|
|
boost::optional<box2d<double> > const& Map::maximum_extent() const
|
|
|
|
{
|
|
|
|
return maximum_extent_;
|
|
|
|
}
|
|
|
|
|
2012-04-04 21:07:15 +02:00
|
|
|
boost::optional<box2d<double> > & Map::maximum_extent()
|
|
|
|
{
|
|
|
|
return maximum_extent_;
|
|
|
|
}
|
|
|
|
|
2011-05-26 01:51:40 +02:00
|
|
|
std::string const& Map::base_path() const
|
|
|
|
{
|
|
|
|
return base_path_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Map::set_base_path(std::string const& base)
|
|
|
|
{
|
|
|
|
base_path_ = base;
|
|
|
|
}
|
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
void Map::zoom(double factor)
|
|
|
|
{
|
2011-04-14 04:20:33 +02:00
|
|
|
coord2d center = current_extent_.center();
|
|
|
|
double w = factor * current_extent_.width();
|
|
|
|
double h = factor * current_extent_.height();
|
2012-02-02 02:53:35 +01:00
|
|
|
current_extent_ = box2d<double>(center.x - 0.5 * w,
|
|
|
|
center.y - 0.5 * h,
|
|
|
|
center.x + 0.5 * w,
|
|
|
|
center.y + 0.5 * h);
|
2010-06-02 13:03:30 +02:00
|
|
|
fixAspectRatio();
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
|
|
|
void Map::zoom_all()
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2011-04-14 04:20:33 +02:00
|
|
|
if (maximum_extent_) {
|
|
|
|
zoom_to_box(*maximum_extent_);
|
|
|
|
}
|
|
|
|
else
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2012-02-02 02:53:35 +01:00
|
|
|
try
|
2006-05-23 18:52:10 +02:00
|
|
|
{
|
2011-10-03 22:15:57 +02:00
|
|
|
if (!layers_.size() > 0)
|
|
|
|
return;
|
2011-04-14 04:20:33 +02:00
|
|
|
projection proj0(srs_);
|
|
|
|
box2d<double> ext;
|
|
|
|
bool success = false;
|
|
|
|
bool first = true;
|
|
|
|
std::vector<layer>::const_iterator itr = layers_.begin();
|
|
|
|
std::vector<layer>::const_iterator end = layers_.end();
|
|
|
|
while (itr != end)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2012-03-12 16:39:59 +01:00
|
|
|
if (itr->active())
|
2010-11-08 19:57:30 +01:00
|
|
|
{
|
2011-04-14 04:20:33 +02:00
|
|
|
std::string const& layer_srs = itr->srs();
|
|
|
|
projection proj1(layer_srs);
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-04-14 04:20:33 +02:00
|
|
|
proj_transform prj_trans(proj0,proj1);
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-04-14 04:20:33 +02:00
|
|
|
box2d<double> layer_ext = itr->envelope();
|
2012-04-02 20:33:29 +02:00
|
|
|
if (prj_trans.backward(layer_ext, PROJ_ENVELOPE_POINTS))
|
2011-04-14 04:20:33 +02:00
|
|
|
{
|
|
|
|
success = true;
|
2012-04-09 21:41:56 +02:00
|
|
|
|
|
|
|
MAPNIK_LOG_DEBUG(map) << "map: Layer " << itr->name() << " original ext=" << itr->envelope();
|
|
|
|
MAPNIK_LOG_DEBUG(map) << "map: Layer " << itr->name() << " transformed to map srs=" << layer_ext;
|
|
|
|
|
2011-04-14 04:20:33 +02:00
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
ext = layer_ext;
|
|
|
|
first = false;
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
else
|
2011-04-14 04:20:33 +02:00
|
|
|
{
|
|
|
|
ext.expand_to_include(layer_ext);
|
|
|
|
}
|
|
|
|
}
|
2010-11-08 19:57:30 +01:00
|
|
|
}
|
2011-04-14 04:20:33 +02:00
|
|
|
++itr;
|
|
|
|
}
|
|
|
|
if (success) {
|
|
|
|
zoom_to_box(ext);
|
|
|
|
} else {
|
|
|
|
std::ostringstream s;
|
|
|
|
s << "could not zoom to combined layer extents "
|
|
|
|
<< "using zoom_all because proj4 could not "
|
|
|
|
<< "back project any layer extents into the map srs "
|
2011-04-16 00:46:53 +02:00
|
|
|
<< "(set map 'maximum-extent' to override layer extents)";
|
2011-04-14 04:20:33 +02:00
|
|
|
throw std::runtime_error(s.str());
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2006-05-23 18:52:10 +02:00
|
|
|
}
|
2011-04-14 04:20:33 +02:00
|
|
|
catch (proj_init_error & ex)
|
|
|
|
{
|
2012-04-08 02:56:18 +02:00
|
|
|
throw mapnik::config_error(std::string("Projection error during map.zoom_all: ") + ex.what());
|
2012-02-02 02:53:35 +01:00
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-25 17:23:35 +02:00
|
|
|
void Map::zoom_to_box(const box2d<double> &box)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2011-04-14 04:20:33 +02:00
|
|
|
current_extent_=box;
|
2010-06-02 13:03:30 +02:00
|
|
|
fixAspectRatio();
|
|
|
|
}
|
2008-06-29 12:59:28 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
void Map::fixAspectRatio()
|
|
|
|
{
|
2012-03-09 02:02:58 +01:00
|
|
|
if (current_extent_.width() > 0 && current_extent_.height() > 0)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2012-03-09 02:02:58 +01:00
|
|
|
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:
|
2011-04-14 04:20:33 +02:00
|
|
|
current_extent_.height(current_extent_.width() / ratio1);
|
2012-03-09 02:02:58 +01:00
|
|
|
break;
|
|
|
|
case ADJUST_BBOX_WIDTH:
|
2011-04-14 04:20:33 +02:00
|
|
|
current_extent_.width(current_extent_.height() * ratio1);
|
2012-03-09 02:02:58 +01:00
|
|
|
break;
|
|
|
|
case ADJUST_CANVAS_HEIGHT:
|
2012-02-02 02:53:35 +01:00
|
|
|
height_ = int (width_ / ratio2 + 0.5);
|
2012-03-09 02:02:58 +01:00
|
|
|
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;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-25 17:23:35 +02:00
|
|
|
const box2d<double>& Map::get_current_extent() const
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2011-04-14 04:20:33 +02:00
|
|
|
return current_extent_;
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
box2d<double> Map::get_buffered_extent() const
|
|
|
|
{
|
|
|
|
double extra = 2.0 * scale() * buffer_size_;
|
2011-04-14 04:20:33 +02:00
|
|
|
box2d<double> ext(current_extent_);
|
|
|
|
ext.width(current_extent_.width() + extra);
|
|
|
|
ext.height(current_extent_.height() + extra);
|
2010-06-02 13:03:30 +02:00
|
|
|
return ext;
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
void Map::pan(int x,int y)
|
|
|
|
{
|
|
|
|
int dx = x - int(0.5 * width_);
|
|
|
|
int dy = int(0.5 * height_) - y;
|
2011-04-14 04:20:33 +02:00
|
|
|
double s = width_/current_extent_.width();
|
|
|
|
double minx = current_extent_.minx() + dx/s;
|
|
|
|
double maxx = current_extent_.maxx() + dx/s;
|
|
|
|
double miny = current_extent_.miny() + dy/s;
|
|
|
|
double maxy = current_extent_.maxy() + dy/s;
|
|
|
|
current_extent_.init(minx,miny,maxx,maxy);
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
void Map::pan_and_zoom(int x,int y,double factor)
|
|
|
|
{
|
|
|
|
pan(x,y);
|
|
|
|
zoom(factor);
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
double Map::scale() const
|
|
|
|
{
|
|
|
|
if (width_>0)
|
2011-04-14 04:20:33 +02:00
|
|
|
return current_extent_.width()/width_;
|
|
|
|
return current_extent_.width();
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
1. hit_test implementation for geometry objects:
bool hit_test(double x, double y, double tol);
2. added image_view(unsigned x, unsigned y, unsigned width, unsigned height)
allowing to select region from image data e.g (in Python):
im = Image(2048,2048)
view = im.view(0,0,256,256)
save_to_file(filename,type, view)
3. changed envelope method to return vy value in datasource classes
4. features_at_point impl for shape and postgis plug-ins
2006-11-25 12:02:59 +01:00
|
|
|
|
2012-02-02 02:53:35 +01:00
|
|
|
double Map::scale_denominator() const
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
projection map_proj(srs_);
|
2012-02-02 02:53:35 +01:00
|
|
|
return mapnik::scale_denominator( *this, map_proj.is_geographic());
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2009-01-14 07:12:55 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
CoordTransform Map::view_transform() const
|
|
|
|
{
|
2011-04-14 04:20:33 +02:00
|
|
|
return CoordTransform(width_,height_,current_extent_);
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
featureset_ptr Map::query_point(unsigned index, double x, double y) const
|
|
|
|
{
|
|
|
|
if ( index< layers_.size())
|
2006-12-06 22:21:17 +01:00
|
|
|
{
|
2012-02-02 02:53:35 +01:00
|
|
|
mapnik::layer const& layer = layers_[index];
|
2010-06-02 13:03:30 +02:00
|
|
|
try
|
2006-12-06 22:21:17 +01:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
double z = 0;
|
|
|
|
mapnik::projection dest(srs_);
|
|
|
|
mapnik::projection source(layer.srs());
|
|
|
|
proj_transform prj_trans(source,dest);
|
|
|
|
prj_trans.backward(x,y,z);
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-04-14 04:20:33 +02:00
|
|
|
double minx = current_extent_.minx();
|
|
|
|
double miny = current_extent_.miny();
|
|
|
|
double maxx = current_extent_.maxx();
|
|
|
|
double maxy = current_extent_.maxy();
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
prj_trans.backward(minx,miny,z);
|
|
|
|
prj_trans.backward(maxx,maxy,z);
|
|
|
|
double tol = (maxx - minx) / width_ * 3;
|
|
|
|
mapnik::datasource_ptr ds = layer.datasource();
|
|
|
|
if (ds)
|
|
|
|
{
|
2012-04-09 21:41:56 +02:00
|
|
|
MAPNIK_LOG_DEBUG(map) << "map: Query at point tol=" << tol << "(" << x << "," << y << ")";
|
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
featureset_ptr fs = ds->features_at_point(mapnik::coord2d(x,y));
|
2012-02-02 02:53:35 +01:00
|
|
|
if (fs)
|
2012-03-10 01:20:50 +01:00
|
|
|
return boost::make_shared<filter_featureset<hit_test_filter> >(fs,
|
2012-03-13 15:56:11 +01:00
|
|
|
hit_test_filter(x,y,tol));
|
2006-12-06 22:21:17 +01:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2012-04-10 00:51:04 +02:00
|
|
|
MAPNIK_LOG_ERROR(map) << "Exception caught in \"query_point\"";
|
2006-12-06 22:21:17 +01:00
|
|
|
}
|
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
return featureset_ptr();
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
featureset_ptr Map::query_map_point(unsigned index, double x, double y) const
|
|
|
|
{
|
|
|
|
if ( index< layers_.size())
|
2006-12-06 21:26:59 +01:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
mapnik::layer const& layer = layers_[index];
|
|
|
|
CoordTransform tr = view_transform();
|
|
|
|
tr.backward(&x,&y);
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
try
|
2006-12-06 21:26:59 +01:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
mapnik::projection dest(srs_);
|
|
|
|
mapnik::projection source(layer.srs());
|
|
|
|
proj_transform prj_trans(source,dest);
|
|
|
|
double z = 0;
|
|
|
|
prj_trans.backward(x,y,z);
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-04-14 04:20:33 +02:00
|
|
|
double minx = current_extent_.minx();
|
|
|
|
double miny = current_extent_.miny();
|
|
|
|
double maxx = current_extent_.maxx();
|
|
|
|
double maxy = current_extent_.maxy();
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
prj_trans.backward(minx,miny,z);
|
|
|
|
prj_trans.backward(maxx,maxy,z);
|
|
|
|
double tol = (maxx - minx) / width_ * 3;
|
|
|
|
mapnik::datasource_ptr ds = layer.datasource();
|
|
|
|
if (ds)
|
|
|
|
{
|
2012-04-09 21:41:56 +02:00
|
|
|
MAPNIK_LOG_DEBUG(map) << "map: Query at point tol=" << tol << "(" << x << "," << y << ")";
|
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
featureset_ptr fs = ds->features_at_point(mapnik::coord2d(x,y));
|
2012-02-02 02:53:35 +01:00
|
|
|
if (fs)
|
2012-03-10 01:20:50 +01:00
|
|
|
return boost::make_shared<filter_featureset<hit_test_filter> >(fs,
|
2012-03-13 15:56:11 +01:00
|
|
|
hit_test_filter(x,y,tol));
|
2006-12-06 21:26:59 +01:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2012-04-10 00:51:04 +02:00
|
|
|
MAPNIK_LOG_ERROR(map) << "Exception caught in \"query_map_point\"";
|
2006-12-06 21:26:59 +01:00
|
|
|
}
|
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
return featureset_ptr();
|
|
|
|
}
|
2006-12-06 21:26:59 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
Map::~Map() {}
|
2009-03-21 13:39:06 +01:00
|
|
|
|
2010-07-06 02:37:05 +02:00
|
|
|
void Map::init_metawriters()
|
|
|
|
{
|
|
|
|
metawriter_cache_dispatch d(*this);
|
|
|
|
Map::style_iterator styIter = begin_styles();
|
|
|
|
Map::style_iterator styEnd = end_styles();
|
|
|
|
for (; styIter!=styEnd; ++styIter) {
|
2011-01-13 22:35:01 +01:00
|
|
|
std::vector<rule>& rules = styIter->second.get_rules_nonconst();
|
|
|
|
std::vector<rule>::iterator ruleIter = rules.begin();
|
|
|
|
std::vector<rule>::iterator ruleEnd = rules.end();
|
2010-07-06 02:37:05 +02:00
|
|
|
for (; ruleIter!=ruleEnd; ++ruleIter) {
|
2011-01-13 22:35:01 +01:00
|
|
|
rule::symbolizers::iterator symIter = ruleIter->begin();
|
|
|
|
rule::symbolizers::iterator symEnd = ruleIter->end();
|
2010-07-06 02:37:05 +02:00
|
|
|
for (; symIter!=symEnd; ++symIter) {
|
|
|
|
boost::apply_visitor(d, *symIter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-07-25 23:05:30 +02:00
|
|
|
|
|
|
|
void Map::set_metawriter_property(std::string name, std::string value)
|
|
|
|
{
|
2011-08-11 23:13:55 +02:00
|
|
|
#if (U_ICU_VERSION_MAJOR_NUM > 4) || (U_ICU_VERSION_MAJOR_NUM == 4 && U_ICU_VERSION_MINOR_NUM >=2)
|
2010-07-25 23:05:30 +02:00
|
|
|
metawriter_output_properties[name] = UnicodeString::fromUTF8(value);
|
2011-08-11 23:13:55 +02:00
|
|
|
#else
|
|
|
|
metawriter_output_properties[name] = UnicodeString(value.c_str());
|
|
|
|
#endif
|
2010-07-25 23:05:30 +02:00
|
|
|
}
|
|
|
|
|
2010-07-26 00:41:18 +02:00
|
|
|
std::string Map::get_metawriter_property(std::string name) const
|
2010-07-25 23:05:30 +02:00
|
|
|
{
|
|
|
|
std::string result;
|
|
|
|
to_utf8(metawriter_output_properties[name], result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-12-03 02:48:09 +01:00
|
|
|
parameters const& Map::get_extra_parameters() const
|
|
|
|
{
|
|
|
|
return extra_params_;
|
|
|
|
}
|
|
|
|
|
|
|
|
parameters& Map::get_extra_parameters()
|
|
|
|
{
|
|
|
|
return extra_params_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Map::set_extra_parameters(parameters& params)
|
|
|
|
{
|
|
|
|
extra_params_ = params;
|
2010-10-07 21:34:36 +02:00
|
|
|
}
|
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|