2006-03-31 10:32:02 +00:00
|
|
|
/*****************************************************************************
|
2012-02-02 01:53:35 +00:00
|
|
|
*
|
2006-03-31 10:32:02 +00:00
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
2005-06-14 15:06:59 +00:00
|
|
|
*
|
2021-01-05 14:39:07 +00:00
|
|
|
* Copyright (C) 2021 Artem Pavlenko
|
2005-06-14 15:06:59 +00:00
|
|
|
*
|
2006-03-31 10:32:02 +00: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 15:06:59 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2006-03-31 10:32:02 +00: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 15:06:59 +00:00
|
|
|
*
|
2006-03-31 10:32:02 +00:00
|
|
|
*****************************************************************************/
|
2005-06-14 15:06:59 +00:00
|
|
|
|
2012-07-25 01:35:41 +00:00
|
|
|
// mapnik
|
2013-01-04 04:07:44 +00:00
|
|
|
#include <mapnik/rule.hpp>
|
|
|
|
#include <mapnik/color.hpp>
|
|
|
|
#include <mapnik/font_set.hpp>
|
|
|
|
#include <mapnik/enumeration.hpp>
|
2012-07-25 01:35:41 +00:00
|
|
|
#include <mapnik/layer.hpp>
|
|
|
|
#include <mapnik/feature_type_style.hpp>
|
2012-04-08 00:20:56 +00:00
|
|
|
#include <mapnik/debug.hpp>
|
2007-10-08 17:42:41 +00:00
|
|
|
#include <mapnik/map.hpp>
|
2006-10-04 11:22:18 +00:00
|
|
|
#include <mapnik/datasource.hpp>
|
2006-10-16 13:44:52 +00:00
|
|
|
#include <mapnik/projection.hpp>
|
2021-03-25 12:16:15 +00:00
|
|
|
#include <mapnik/proj_transform_cache.hpp>
|
2014-08-28 09:29:04 +00:00
|
|
|
#include <mapnik/view_transform.hpp>
|
2006-12-06 20:26:59 +00:00
|
|
|
#include <mapnik/filter_featureset.hpp>
|
|
|
|
#include <mapnik/hit_test_filter.hpp>
|
2009-01-14 06:12:55 +00:00
|
|
|
#include <mapnik/scale_denominator.hpp>
|
2012-04-08 00:56:18 +00:00
|
|
|
#include <mapnik/config_error.hpp>
|
2012-04-02 18:33:29 +00:00
|
|
|
#include <mapnik/config.hpp> // for PROJ_ENVELOPE_POINTS
|
2014-10-02 01:45:28 +00:00
|
|
|
#include <mapnik/text/font_library.hpp>
|
2014-09-27 02:54:07 +00:00
|
|
|
#include <mapnik/util/file_io.hpp>
|
|
|
|
#include <mapnik/font_engine_freetype.hpp>
|
2012-03-10 00:20:50 +00:00
|
|
|
|
2013-06-03 03:19:33 +00:00
|
|
|
// stl
|
|
|
|
#include <stdexcept>
|
|
|
|
|
2005-06-14 15:06:59 +00:00
|
|
|
namespace mapnik
|
|
|
|
{
|
2009-03-21 12:39:06 +00:00
|
|
|
|
2010-06-02 11:03:30 +00: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",
|
2014-08-15 03:25:53 +00:00
|
|
|
"RESPECT",
|
2010-06-02 11:03:30 +00:00
|
|
|
""
|
|
|
|
};
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2011-04-01 07:20:41 +00:00
|
|
|
IMPLEMENT_ENUM( aspect_fix_mode_e, aspect_fix_mode_strings )
|
2009-03-21 12:39:06 +00:00
|
|
|
|
2021-03-25 12:16:15 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
Map::Map()
|
2021-03-25 12:16:15 +00:00
|
|
|
: width_(400),
|
2012-02-02 01:53:35 +00:00
|
|
|
height_(400),
|
2021-03-15 18:06:26 +00:00
|
|
|
srs_(MAPNIK_GEOGRAPHIC_PROJ),
|
2012-02-02 01:53:35 +00:00
|
|
|
buffer_size_(0),
|
2013-07-25 05:00:38 +00:00
|
|
|
background_image_comp_op_(src_over),
|
|
|
|
background_image_opacity_(1.0),
|
2012-02-02 01:53:35 +00:00
|
|
|
aspectFixMode_(GROW_BBOX),
|
2014-09-27 02:54:07 +00:00
|
|
|
base_path_(""),
|
|
|
|
extra_params_(),
|
|
|
|
font_directory_(),
|
|
|
|
font_file_mapping_(),
|
2021-04-06 09:30:12 +00:00
|
|
|
font_memory_cache_() {}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
Map::Map(int width,int height, std::string const& srs)
|
|
|
|
: width_(width),
|
|
|
|
height_(height),
|
|
|
|
srs_(srs),
|
|
|
|
buffer_size_(0),
|
2013-07-25 05:00:38 +00:00
|
|
|
background_image_comp_op_(src_over),
|
|
|
|
background_image_opacity_(1.0),
|
2011-06-01 18:53:47 +00:00
|
|
|
aspectFixMode_(GROW_BBOX),
|
2014-09-27 02:54:07 +00:00
|
|
|
base_path_(""),
|
|
|
|
extra_params_(),
|
|
|
|
font_directory_(),
|
|
|
|
font_file_mapping_(),
|
2021-04-06 09:30:12 +00:00
|
|
|
font_memory_cache_() {}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2013-02-26 00:33:35 +00:00
|
|
|
Map::Map(Map const& rhs)
|
2010-06-02 11:03:30 +00:00
|
|
|
: width_(rhs.width_),
|
|
|
|
height_(rhs.height_),
|
|
|
|
srs_(rhs.srs_),
|
|
|
|
buffer_size_(rhs.buffer_size_),
|
|
|
|
background_(rhs.background_),
|
2010-07-19 11:10:03 +00:00
|
|
|
background_image_(rhs.background_image_),
|
2013-07-25 05:00:38 +00:00
|
|
|
background_image_comp_op_(rhs.background_image_comp_op_),
|
|
|
|
background_image_opacity_(rhs.background_image_opacity_),
|
2010-06-02 11:03:30 +00:00
|
|
|
styles_(rhs.styles_),
|
2011-12-12 10:16:39 +00:00
|
|
|
fontsets_(rhs.fontsets_),
|
2010-06-02 11:03:30 +00:00
|
|
|
layers_(rhs.layers_),
|
|
|
|
aspectFixMode_(rhs.aspectFixMode_),
|
2011-04-14 02:20:33 +00:00
|
|
|
current_extent_(rhs.current_extent_),
|
2014-05-27 14:35:37 +00:00
|
|
|
maximum_extent_(rhs.maximum_extent_),
|
|
|
|
base_path_(rhs.base_path_),
|
2014-09-27 02:54:07 +00:00
|
|
|
extra_params_(rhs.extra_params_),
|
|
|
|
font_directory_(rhs.font_directory_),
|
|
|
|
font_file_mapping_(rhs.font_file_mapping_),
|
2021-02-25 11:05:11 +00:00
|
|
|
// on copy discard memory caches
|
2021-04-06 09:30:12 +00:00
|
|
|
font_memory_cache_()
|
2021-03-04 10:19:44 +00:00
|
|
|
{
|
|
|
|
init_proj_transforms();
|
|
|
|
}
|
2014-05-27 14:35:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
Map::Map(Map && rhs)
|
|
|
|
: width_(std::move(rhs.width_)),
|
|
|
|
height_(std::move(rhs.height_)),
|
|
|
|
srs_(std::move(rhs.srs_)),
|
|
|
|
buffer_size_(std::move(rhs.buffer_size_)),
|
|
|
|
background_(std::move(rhs.background_)),
|
|
|
|
background_image_(std::move(rhs.background_image_)),
|
|
|
|
background_image_comp_op_(std::move(rhs.background_image_comp_op_)),
|
|
|
|
background_image_opacity_(std::move(rhs.background_image_opacity_)),
|
|
|
|
styles_(std::move(rhs.styles_)),
|
|
|
|
fontsets_(std::move(rhs.fontsets_)),
|
|
|
|
layers_(std::move(rhs.layers_)),
|
|
|
|
aspectFixMode_(std::move(rhs.aspectFixMode_)),
|
|
|
|
current_extent_(std::move(rhs.current_extent_)),
|
|
|
|
maximum_extent_(std::move(rhs.maximum_extent_)),
|
|
|
|
base_path_(std::move(rhs.base_path_)),
|
2014-09-27 02:54:07 +00:00
|
|
|
extra_params_(std::move(rhs.extra_params_)),
|
|
|
|
font_directory_(std::move(rhs.font_directory_)),
|
|
|
|
font_file_mapping_(std::move(rhs.font_file_mapping_)),
|
2021-04-06 09:30:12 +00:00
|
|
|
font_memory_cache_(std::move(rhs.font_memory_cache_)) {}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2012-08-15 08:47:03 +00:00
|
|
|
Map::~Map() {}
|
|
|
|
|
2021-03-18 16:05:58 +00:00
|
|
|
|
2014-01-28 09:56:45 +00:00
|
|
|
Map& Map::operator=(Map rhs)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2014-05-27 09:35:19 +00:00
|
|
|
swap(*this, rhs);
|
2021-03-04 10:19:44 +00:00
|
|
|
init_proj_transforms();
|
2010-06-02 11:03:30 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2014-05-27 09:35:19 +00:00
|
|
|
void swap (Map & lhs, Map & rhs)
|
|
|
|
{
|
|
|
|
using std::swap;
|
|
|
|
std::swap(lhs.width_, rhs.width_);
|
|
|
|
std::swap(lhs.height_, rhs.height_);
|
|
|
|
std::swap(lhs.srs_, rhs.srs_);
|
|
|
|
std::swap(lhs.buffer_size_, rhs.buffer_size_);
|
|
|
|
std::swap(lhs.background_, rhs.background_);
|
|
|
|
std::swap(lhs.background_image_, rhs.background_image_);
|
|
|
|
std::swap(lhs.background_image_comp_op_, rhs.background_image_comp_op_);
|
|
|
|
std::swap(lhs.background_image_opacity_, rhs.background_image_opacity_);
|
|
|
|
std::swap(lhs.styles_, rhs.styles_);
|
|
|
|
std::swap(lhs.fontsets_, rhs.fontsets_);
|
|
|
|
std::swap(lhs.layers_, rhs.layers_);
|
|
|
|
std::swap(lhs.aspectFixMode_, rhs.aspectFixMode_);
|
|
|
|
std::swap(lhs.current_extent_, rhs.current_extent_);
|
|
|
|
std::swap(lhs.maximum_extent_, rhs.maximum_extent_);
|
|
|
|
std::swap(lhs.base_path_, rhs.base_path_);
|
|
|
|
std::swap(lhs.extra_params_, rhs.extra_params_);
|
2014-09-27 02:54:07 +00:00
|
|
|
std::swap(lhs.font_directory_,rhs.font_directory_);
|
|
|
|
std::swap(lhs.font_file_mapping_,rhs.font_file_mapping_);
|
2021-02-25 11:05:11 +00:00
|
|
|
// on assignment discard memory caches
|
2014-09-29 06:31:48 +00:00
|
|
|
//std::swap(lhs.font_memory_cache_,rhs.font_memory_cache_);
|
2014-05-27 09:35:19 +00:00
|
|
|
}
|
|
|
|
|
2014-05-27 10:34:39 +00:00
|
|
|
bool Map::operator==(Map const& rhs) const
|
|
|
|
{
|
2014-05-27 11:36:05 +00:00
|
|
|
return (width_ == rhs.width_) &&
|
2014-05-27 10:34:39 +00:00
|
|
|
(height_ == rhs.height_) &&
|
|
|
|
(srs_ == rhs.srs_) &&
|
|
|
|
(buffer_size_ == rhs.buffer_size_) &&
|
|
|
|
(background_ == rhs.background_) &&
|
|
|
|
(background_image_ == rhs.background_image_) &&
|
|
|
|
(background_image_comp_op_ == rhs.background_image_comp_op_) &&
|
|
|
|
(background_image_opacity_ == rhs.background_image_opacity_) &&
|
|
|
|
(styles_ == rhs.styles_) &&
|
|
|
|
(fontsets_ == rhs.fontsets_) &&
|
|
|
|
(layers_ == rhs.layers_) &&
|
|
|
|
(aspectFixMode_ == rhs.aspectFixMode_) &&
|
|
|
|
(current_extent_ == rhs.current_extent_) &&
|
|
|
|
(maximum_extent_ == rhs.maximum_extent_) &&
|
|
|
|
(base_path_ == rhs.base_path_) &&
|
2014-09-27 02:54:07 +00:00
|
|
|
(extra_params_ == rhs.extra_params_) &&
|
|
|
|
(font_directory_ == rhs.font_directory_) &&
|
2014-09-29 06:31:48 +00:00
|
|
|
(font_file_mapping_ == rhs.font_file_mapping_);
|
|
|
|
// Note: we don't care about font_memory_cache in comparison
|
2014-05-27 10:34:39 +00:00
|
|
|
}
|
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
std::map<std::string,feature_type_style> const& Map::styles() const
|
|
|
|
{
|
|
|
|
return styles_;
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
std::map<std::string,feature_type_style> & Map::styles()
|
|
|
|
{
|
|
|
|
return styles_;
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
Map::style_iterator Map::begin_styles()
|
|
|
|
{
|
|
|
|
return styles_.begin();
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
Map::style_iterator Map::end_styles()
|
|
|
|
{
|
|
|
|
return styles_.end();
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2013-02-26 00:33:35 +00:00
|
|
|
Map::const_style_iterator Map::begin_styles() const
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
|
|
|
return styles_.begin();
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2013-02-26 00:33:35 +00:00
|
|
|
Map::const_style_iterator Map::end_styles() const
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
|
|
|
return styles_.end();
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2014-10-01 21:09:09 +00:00
|
|
|
bool Map::insert_style(std::string const& name, feature_type_style const& style)
|
|
|
|
{
|
|
|
|
return styles_.emplace(name, style).second;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Map::insert_style(std::string const& name, feature_type_style && style)
|
2014-04-29 00:10:00 +00:00
|
|
|
{
|
2014-08-05 22:19:37 +00:00
|
|
|
return styles_.emplace(name, std::move(style)).second;
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
|
|
|
void Map::remove_style(std::string const& name)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
|
|
|
styles_.erase(name);
|
|
|
|
}
|
2010-07-06 00:37:05 +00: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&>() ;
|
|
|
|
}
|
|
|
|
|
2014-10-01 21:09:09 +00:00
|
|
|
bool Map::insert_fontset(std::string const& name, font_set const& fontset)
|
|
|
|
{
|
|
|
|
if (fontset.get_name() != name)
|
|
|
|
{
|
|
|
|
throw mapnik::config_error("Fontset name must match the name used to reference it on the map");
|
|
|
|
}
|
|
|
|
return fontsets_.emplace(name, fontset).second;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Map::insert_fontset(std::string const& name, font_set && fontset)
|
2014-04-29 00:10:00 +00:00
|
|
|
{
|
|
|
|
if (fontset.get_name() != name)
|
|
|
|
{
|
|
|
|
throw mapnik::config_error("Fontset name must match the name used to reference it on the map");
|
|
|
|
}
|
2014-08-05 22:19:37 +00:00
|
|
|
return fontsets_.emplace(name, std::move(fontset)).second;
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2011-12-20 20:34:27 +00:00
|
|
|
|
2013-11-28 06:50:15 +00:00
|
|
|
boost::optional<font_set const&> Map::find_fontset(std::string const& name) const
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
|
|
|
std::map<std::string,font_set>::const_iterator itr = fontsets_.find(name);
|
2011-12-20 20:34:27 +00:00
|
|
|
if (itr != fontsets_.end())
|
|
|
|
return boost::optional<font_set const&>(itr->second);
|
|
|
|
else
|
|
|
|
return boost::optional<font_set const&>() ;
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2008-06-29 10:58:48 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
std::map<std::string,font_set> const& Map::fontsets() const
|
|
|
|
{
|
|
|
|
return fontsets_;
|
|
|
|
}
|
2009-01-17 20:18:41 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
std::map<std::string,font_set> & Map::fontsets()
|
|
|
|
{
|
|
|
|
return fontsets_;
|
|
|
|
}
|
2009-01-17 20:18:41 +00:00
|
|
|
|
2014-09-27 02:54:07 +00:00
|
|
|
bool Map::register_fonts(std::string const& dir, bool recurse)
|
|
|
|
{
|
2014-10-02 01:45:28 +00:00
|
|
|
font_library library;
|
2017-06-01 10:47:18 +00:00
|
|
|
return freetype_engine::instance().register_fonts_impl(dir, library, font_file_mapping_, recurse);
|
2014-09-27 02:54:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Map::load_fonts()
|
|
|
|
{
|
|
|
|
bool result = false;
|
2014-10-06 18:37:39 +00:00
|
|
|
auto const& global_mapping = freetype_engine::get_mapping();
|
2014-10-07 07:21:52 +00:00
|
|
|
for (auto const& kv : font_file_mapping_) // for every face-name -> idx/filepath
|
2014-09-27 02:54:07 +00:00
|
|
|
{
|
2014-10-07 07:21:52 +00:00
|
|
|
auto const& file_path = kv.second.second;
|
|
|
|
// do not attemp to re-cache in memory
|
|
|
|
if (font_memory_cache_.find(file_path) != font_memory_cache_.end())
|
2014-09-27 02:54:07 +00:00
|
|
|
{
|
2014-10-07 07:21:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auto const& meta = global_mapping.find(kv.first);
|
|
|
|
// no need to cache if global mapping already has same font
|
|
|
|
if ((meta != global_mapping.end()) && (meta->second.second == file_path))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
mapnik::util::file file(file_path);
|
2016-03-18 09:02:19 +00:00
|
|
|
if (file)
|
2014-10-07 07:21:52 +00:00
|
|
|
{
|
2015-06-02 13:25:57 +00:00
|
|
|
auto item = font_memory_cache_.emplace(file_path, std::make_pair(file.data(),file.size()));
|
2014-10-07 07:21:52 +00:00
|
|
|
if (item.second) result = true;
|
2014-09-27 02:54:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-06-25 15:23:35 +00:00
|
|
|
size_t Map::layer_count() const
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
|
|
|
return layers_.size();
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2014-10-01 21:09:09 +00:00
|
|
|
void Map::add_layer(layer const& l)
|
|
|
|
{
|
2021-04-06 09:30:12 +00:00
|
|
|
proj_transform_cache::init(srs_, l.srs());
|
2014-10-01 21:09:09 +00:00
|
|
|
layers_.emplace_back(l);
|
|
|
|
}
|
|
|
|
|
2014-10-01 21:20:58 +00:00
|
|
|
void Map::add_layer(layer && l)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2021-04-06 09:30:12 +00:00
|
|
|
proj_transform_cache::init(srs_, l.srs());
|
2014-05-28 08:54:02 +00:00
|
|
|
layers_.push_back(std::move(l));
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2010-07-06 00:37:05 +00:00
|
|
|
|
2013-11-28 06:50:15 +00:00
|
|
|
void Map::remove_layer(size_t index)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
|
|
|
layers_.erase(layers_.begin()+index);
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
|
|
|
void Map::remove_all()
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
|
|
|
layers_.clear();
|
|
|
|
styles_.clear();
|
2014-11-08 00:50:18 +00:00
|
|
|
fontsets_.clear();
|
|
|
|
font_file_mapping_.clear();
|
|
|
|
font_memory_cache_.clear();
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2013-11-28 06:50:15 +00:00
|
|
|
layer const& Map::get_layer(size_t index) const
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
|
|
|
return layers_[index];
|
|
|
|
}
|
2006-03-28 15:39:38 +00:00
|
|
|
|
2021-03-09 10:48:32 +00:00
|
|
|
layer& Map::get_layer(size_t index)
|
|
|
|
{
|
|
|
|
return layers_[index];
|
|
|
|
}
|
|
|
|
|
2010-06-02 11:03:30 +00: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 11:02:59 +00:00
|
|
|
|
2021-03-09 10:48:32 +00:00
|
|
|
std::vector<layer> & Map::layers()
|
|
|
|
{
|
|
|
|
return layers_;
|
|
|
|
}
|
|
|
|
|
2010-06-25 15:23:35 +00:00
|
|
|
unsigned Map::width() const
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
|
|
|
return width_;
|
|
|
|
}
|
2005-06-14 15:06:59 +00:00
|
|
|
|
2010-06-25 15:23:35 +00:00
|
|
|
unsigned Map::height() const
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
|
|
|
return height_;
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2016-08-26 09:09:22 +00:00
|
|
|
void Map::set_width(unsigned _width)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2016-08-26 09:09:22 +00:00
|
|
|
if (_width != width_ &&
|
|
|
|
_width >= MIN_MAPSIZE &&
|
|
|
|
_width <= MAX_MAPSIZE)
|
2005-11-24 15:51:29 +00:00
|
|
|
{
|
2016-08-26 09:09:22 +00:00
|
|
|
width_=_width;
|
2010-06-02 11:03:30 +00:00
|
|
|
fixAspectRatio();
|
2012-02-02 01:53:35 +00:00
|
|
|
}
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2005-11-24 15:51:29 +00:00
|
|
|
|
2016-08-26 09:09:22 +00:00
|
|
|
void Map::set_height(unsigned _height)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2016-08-26 09:09:22 +00:00
|
|
|
if (_height != height_ &&
|
|
|
|
_height >= MIN_MAPSIZE &&
|
|
|
|
_height <= MAX_MAPSIZE)
|
2005-11-24 15:51:29 +00:00
|
|
|
{
|
2016-08-26 09:09:22 +00:00
|
|
|
height_ = _height;
|
2010-06-02 11:03:30 +00:00
|
|
|
fixAspectRatio();
|
2005-11-24 15:51:29 +00:00
|
|
|
}
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2016-08-26 09:09:22 +00:00
|
|
|
void Map::resize(unsigned _width, unsigned _height)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2016-08-26 09:09:22 +00:00
|
|
|
if ((_width != width_ ||
|
|
|
|
_height != height_) &&
|
|
|
|
_width >= MIN_MAPSIZE &&
|
|
|
|
_width <= MAX_MAPSIZE &&
|
|
|
|
_height >= MIN_MAPSIZE &&
|
|
|
|
_height <= MAX_MAPSIZE)
|
2005-11-24 15:51:29 +00:00
|
|
|
{
|
2016-08-26 09:09:22 +00:00
|
|
|
width_ = _width;
|
|
|
|
height_ = _height;
|
2010-06-02 11:03:30 +00:00
|
|
|
fixAspectRatio();
|
2005-11-24 15:51:29 +00:00
|
|
|
}
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2005-06-14 15:06:59 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
std::string const& Map::srs() const
|
|
|
|
{
|
|
|
|
return srs_;
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2016-08-26 09:09:22 +00:00
|
|
|
void Map::set_srs(std::string const& _srs)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2021-03-18 16:05:58 +00:00
|
|
|
if (srs_ != _srs) init_proj_transforms();
|
2016-08-26 09:09:22 +00:00
|
|
|
srs_ = _srs;
|
2021-03-18 16:05:58 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2016-08-26 09:09:22 +00:00
|
|
|
void Map::set_buffer_size(int _buffer_size)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2016-08-26 09:09:22 +00:00
|
|
|
buffer_size_ = _buffer_size;
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2008-09-21 10:14:38 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
int Map::buffer_size() const
|
|
|
|
{
|
|
|
|
return buffer_size_;
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
boost::optional<color> const& Map::background() const
|
|
|
|
{
|
|
|
|
return background_;
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2013-02-26 00:33:35 +00:00
|
|
|
void Map::set_background(color const& c)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
|
|
|
background_ = c;
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-07-19 11:10:03 +00:00
|
|
|
boost::optional<std::string> const& Map::background_image() const
|
|
|
|
{
|
|
|
|
return background_image_;
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-07-19 11:10:03 +00:00
|
|
|
void Map::set_background_image(std::string const& image_filename)
|
|
|
|
{
|
|
|
|
background_image_ = image_filename;
|
|
|
|
}
|
|
|
|
|
2013-07-25 05:00:38 +00:00
|
|
|
composite_mode_e Map::background_image_comp_op() const
|
|
|
|
{
|
|
|
|
return background_image_comp_op_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Map::set_background_image_comp_op(composite_mode_e comp_op)
|
|
|
|
{
|
|
|
|
background_image_comp_op_ = comp_op;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Map::background_image_opacity() const
|
|
|
|
{
|
|
|
|
return background_image_opacity_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Map::set_background_image_opacity(float opacity)
|
|
|
|
{
|
|
|
|
background_image_opacity_ = opacity;
|
|
|
|
}
|
|
|
|
|
2011-04-14 02:20:33 +00:00
|
|
|
void Map::set_maximum_extent(box2d<double> const& box)
|
|
|
|
{
|
2012-08-01 14:44:36 +00:00
|
|
|
maximum_extent_.reset(box);
|
2011-04-14 02:20:33 +00:00
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2011-04-14 02:20:33 +00:00
|
|
|
boost::optional<box2d<double> > const& Map::maximum_extent() const
|
|
|
|
{
|
|
|
|
return maximum_extent_;
|
|
|
|
}
|
|
|
|
|
2012-08-01 14:44:36 +00:00
|
|
|
void Map::reset_maximum_extent()
|
2012-04-04 19:07:15 +00:00
|
|
|
{
|
2012-08-01 14:44:36 +00:00
|
|
|
maximum_extent_.reset();
|
2012-04-04 19:07:15 +00:00
|
|
|
}
|
|
|
|
|
2011-05-25 23:51:40 +00: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 11:03:30 +00:00
|
|
|
void Map::zoom(double factor)
|
|
|
|
{
|
2011-04-14 02:20:33 +00:00
|
|
|
coord2d center = current_extent_.center();
|
|
|
|
double w = factor * current_extent_.width();
|
|
|
|
double h = factor * current_extent_.height();
|
2012-02-02 01:53:35 +00: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 11:03:30 +00:00
|
|
|
fixAspectRatio();
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
|
|
|
void Map::zoom_all()
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2012-09-07 17:36:14 +00:00
|
|
|
try
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2012-10-30 18:00:51 +00:00
|
|
|
if (layers_.empty())
|
|
|
|
{
|
2012-09-07 17:36:14 +00:00
|
|
|
return;
|
2012-10-30 18:00:51 +00:00
|
|
|
}
|
2012-09-07 17:36:14 +00:00
|
|
|
box2d<double> ext;
|
|
|
|
bool success = false;
|
|
|
|
bool first = true;
|
2015-10-12 17:10:12 +00:00
|
|
|
for (auto const& layer : layers_)
|
2006-05-23 16:52:10 +00:00
|
|
|
{
|
2015-10-12 17:10:12 +00:00
|
|
|
if (layer.active())
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2015-10-12 17:10:12 +00:00
|
|
|
std::string const& layer_srs = layer.srs();
|
2021-04-06 09:30:12 +00:00
|
|
|
proj_transform const* proj_trans_ptr = proj_transform_cache::get(srs_, layer_srs);
|
2015-10-12 17:10:12 +00:00
|
|
|
box2d<double> layer_ext = layer.envelope();
|
2021-01-27 09:40:28 +00:00
|
|
|
if (proj_trans_ptr->backward(layer_ext, PROJ_ENVELOPE_POINTS))
|
2010-11-08 18:57:30 +00:00
|
|
|
{
|
2012-09-07 17:36:14 +00:00
|
|
|
success = true;
|
2015-10-12 17:10:12 +00:00
|
|
|
MAPNIK_LOG_DEBUG(map) << "map: Layer " << layer.name() << " original ext=" << layer.envelope();
|
|
|
|
MAPNIK_LOG_DEBUG(map) << "map: Layer " << layer.name() << " transformed to map srs=" << layer_ext;
|
2012-09-07 17:36:14 +00:00
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
ext = layer_ext;
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
else
|
2011-04-14 02:20:33 +00:00
|
|
|
{
|
2012-09-07 17:36:14 +00:00
|
|
|
ext.expand_to_include(layer_ext);
|
2011-04-14 02:20:33 +00:00
|
|
|
}
|
2010-11-08 18:57:30 +00:00
|
|
|
}
|
2011-04-14 02:20:33 +00:00
|
|
|
}
|
2012-09-07 17:36:14 +00:00
|
|
|
}
|
|
|
|
if (success)
|
|
|
|
{
|
|
|
|
if (maximum_extent_) {
|
|
|
|
ext.clip(*maximum_extent_);
|
|
|
|
}
|
|
|
|
zoom_to_box(ext);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (maximum_extent_)
|
|
|
|
{
|
|
|
|
MAPNIK_LOG_ERROR(map) << "could not zoom to combined layer extents"
|
2014-05-27 09:35:19 +00:00
|
|
|
<< " so falling back to maximum-extent for zoom_all result";
|
2012-09-07 17:36:14 +00:00
|
|
|
zoom_to_box(*maximum_extent_);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-14 02:20:33 +00:00
|
|
|
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-15 22:46:53 +00:00
|
|
|
<< "(set map 'maximum-extent' to override layer extents)";
|
2011-04-14 02:20:33 +00:00
|
|
|
throw std::runtime_error(s.str());
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2006-05-23 16:52:10 +00:00
|
|
|
}
|
2012-09-07 17:36:14 +00:00
|
|
|
}
|
2013-03-15 23:52:02 +00:00
|
|
|
catch (proj_init_error const& ex)
|
2012-09-07 17:36:14 +00:00
|
|
|
{
|
|
|
|
throw mapnik::config_error(std::string("Projection error during map.zoom_all: ") + ex.what());
|
2005-06-14 15:06:59 +00:00
|
|
|
}
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2005-06-14 15:06:59 +00:00
|
|
|
|
2013-02-26 00:33:35 +00:00
|
|
|
void Map::zoom_to_box(box2d<double> const& box)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2015-11-19 12:26:16 +00:00
|
|
|
current_extent_= box;
|
2010-06-02 11:03:30 +00:00
|
|
|
fixAspectRatio();
|
|
|
|
}
|
2008-06-29 10:59:28 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
void Map::fixAspectRatio()
|
|
|
|
{
|
2014-08-15 03:25:53 +00:00
|
|
|
if (aspectFixMode_ == RESPECT) return;
|
2012-03-09 01:02:58 +00:00
|
|
|
if (current_extent_.width() > 0 && current_extent_.height() > 0)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2012-03-09 01:02:58 +00: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 02:20:33 +00:00
|
|
|
current_extent_.height(current_extent_.width() / ratio1);
|
2012-03-09 01:02:58 +00:00
|
|
|
break;
|
|
|
|
case ADJUST_BBOX_WIDTH:
|
2011-04-14 02:20:33 +00:00
|
|
|
current_extent_.width(current_extent_.height() * ratio1);
|
2012-03-09 01:02:58 +00:00
|
|
|
break;
|
|
|
|
case ADJUST_CANVAS_HEIGHT:
|
2013-11-02 03:49:34 +00:00
|
|
|
height_ = static_cast<unsigned>(std::floor(static_cast<double>(width_) / ratio2 + 0.5));
|
2012-03-09 01:02:58 +00:00
|
|
|
break;
|
|
|
|
case ADJUST_CANVAS_WIDTH:
|
2013-11-02 03:49:34 +00:00
|
|
|
width_ = static_cast<unsigned>(std::floor(static_cast<double>(height_) * ratio2 + 0.5));
|
2012-03-09 01:02:58 +00:00
|
|
|
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)
|
2013-11-02 03:49:34 +00:00
|
|
|
width_ = static_cast<unsigned>(std::floor(static_cast<double>(height_) * ratio2 + 0.5));
|
2012-03-09 01:02:58 +00:00
|
|
|
else
|
2013-11-02 03:49:34 +00:00
|
|
|
height_ = static_cast<unsigned>(std::floor(static_cast<double>(width_) / ratio2 + 0.5));
|
2012-03-09 01:02:58 +00:00
|
|
|
break;
|
|
|
|
case SHRINK_CANVAS:
|
|
|
|
if (ratio2 > ratio1)
|
2013-11-02 03:49:34 +00:00
|
|
|
height_ = static_cast<unsigned>(std::floor(static_cast<double>(width_) / ratio2 + 0.5));
|
2012-03-09 01:02:58 +00:00
|
|
|
else
|
2013-11-02 03:49:34 +00:00
|
|
|
width_ = static_cast<unsigned>(std::floor(static_cast<double>(height_) * ratio2 + 0.5));
|
2012-03-09 01:02:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (ratio2 > ratio1)
|
|
|
|
current_extent_.height(current_extent_.width() / ratio1);
|
|
|
|
else
|
|
|
|
current_extent_.width(current_extent_.height() * ratio1);
|
|
|
|
break;
|
|
|
|
}
|
2005-06-14 15:06:59 +00:00
|
|
|
}
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2013-02-26 00:33:35 +00:00
|
|
|
box2d<double> const& Map::get_current_extent() const
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2011-04-14 02:20:33 +00:00
|
|
|
return current_extent_;
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2005-06-14 15:06:59 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
box2d<double> Map::get_buffered_extent() const
|
|
|
|
{
|
|
|
|
double extra = 2.0 * scale() * buffer_size_;
|
2011-04-14 02:20:33 +00:00
|
|
|
box2d<double> ext(current_extent_);
|
|
|
|
ext.width(current_extent_.width() + extra);
|
|
|
|
ext.height(current_extent_.height() + extra);
|
2010-06-02 11:03:30 +00:00
|
|
|
return ext;
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
void Map::pan(int x,int y)
|
|
|
|
{
|
|
|
|
int dx = x - int(0.5 * width_);
|
|
|
|
int dy = int(0.5 * height_) - y;
|
2013-11-02 03:49:34 +00:00
|
|
|
double s = static_cast<double>(width_)/current_extent_.width();
|
2011-04-14 02:20:33 +00:00
|
|
|
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 11:03:30 +00:00
|
|
|
}
|
2005-06-14 15:06:59 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
void Map::pan_and_zoom(int x,int y,double factor)
|
|
|
|
{
|
|
|
|
pan(x,y);
|
|
|
|
zoom(factor);
|
|
|
|
}
|
2005-06-14 15:06:59 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
double Map::scale() const
|
|
|
|
{
|
|
|
|
if (width_>0)
|
2013-11-02 03:49:34 +00:00
|
|
|
return current_extent_.width()/static_cast<double>(width_);
|
2011-04-14 02:20:33 +00:00
|
|
|
return current_extent_.width();
|
2010-06-02 11:03:30 +00: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 11:02:59 +00:00
|
|
|
|
2012-02-02 01:53:35 +00:00
|
|
|
double Map::scale_denominator() const
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
|
|
|
projection map_proj(srs_);
|
2013-02-21 02:02:28 +00:00
|
|
|
return mapnik::scale_denominator( scale(), map_proj.is_geographic());
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2009-01-14 06:12:55 +00:00
|
|
|
|
2014-08-28 09:17:15 +00:00
|
|
|
view_transform Map::transform() const
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2014-08-28 09:17:15 +00:00
|
|
|
return view_transform(width_,height_,current_extent_);
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
featureset_ptr Map::query_point(unsigned index, double x, double y) const
|
|
|
|
{
|
2012-04-13 18:28:30 +00:00
|
|
|
if (!current_extent_.valid())
|
|
|
|
{
|
2016-08-05 12:49:45 +00:00
|
|
|
throw std::runtime_error("query_point: map extent is not initialized, you need to set a valid extent before querying");
|
2012-04-13 18:28:30 +00:00
|
|
|
}
|
|
|
|
if (!current_extent_.intersects(x,y))
|
|
|
|
{
|
|
|
|
throw std::runtime_error("query_point: x,y coords do not intersect map extent");
|
|
|
|
}
|
|
|
|
if (index < layers_.size())
|
2006-12-06 21:21:17 +00:00
|
|
|
{
|
2012-02-02 01:53:35 +00:00
|
|
|
mapnik::layer const& layer = layers_[index];
|
2012-04-13 18:28:30 +00:00
|
|
|
mapnik::datasource_ptr ds = layer.datasource();
|
|
|
|
if (ds)
|
2006-12-06 21:21:17 +00:00
|
|
|
{
|
2021-04-06 09:30:12 +00:00
|
|
|
proj_transform const* proj_trans_ptr = proj_transform_cache::get(layer.srs(), srs_);
|
2012-04-13 18:28:30 +00:00
|
|
|
double z = 0;
|
2021-01-27 09:40:28 +00:00
|
|
|
if (!proj_trans_ptr->equal() && !proj_trans_ptr->backward(x,y,z))
|
2012-04-13 18:28:30 +00:00
|
|
|
{
|
|
|
|
throw std::runtime_error("query_point: could not project x,y into layer srs");
|
|
|
|
}
|
2012-09-28 13:12:10 +00:00
|
|
|
// calculate default tolerance
|
|
|
|
mapnik::box2d<double> map_ex = current_extent_;
|
|
|
|
if (maximum_extent_)
|
|
|
|
{
|
|
|
|
map_ex.clip(*maximum_extent_);
|
|
|
|
}
|
2021-01-27 09:40:28 +00:00
|
|
|
if (!proj_trans_ptr->backward(map_ex,PROJ_ENVELOPE_POINTS))
|
2012-09-28 13:12:10 +00:00
|
|
|
{
|
|
|
|
std::ostringstream s;
|
|
|
|
s << "query_point: could not project map extent '" << map_ex
|
|
|
|
<< "' into layer srs for tolerance calculation";
|
|
|
|
throw std::runtime_error(s.str());
|
|
|
|
}
|
2013-11-02 03:49:34 +00:00
|
|
|
double tol = (map_ex.maxx() - map_ex.minx()) / static_cast<double>(width_) * 3;
|
2012-09-28 13:12:10 +00:00
|
|
|
featureset_ptr fs = ds->features_at_point(mapnik::coord2d(x,y), tol);
|
|
|
|
MAPNIK_LOG_DEBUG(map) << "map: Query at point tol=" << tol << "(" << x << "," << y << ")";
|
2012-04-13 18:28:30 +00:00
|
|
|
if (fs)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2013-09-20 13:00:11 +00:00
|
|
|
return std::make_shared<filter_featureset<hit_test_filter> >(fs,
|
2014-05-27 09:35:19 +00:00
|
|
|
hit_test_filter(x,y,tol));
|
2006-12-06 21:21:17 +00:00
|
|
|
}
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2012-04-13 18:28:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::ostringstream s;
|
|
|
|
s << "Invalid layer index passed to query_point: '" << index << "'";
|
2012-10-30 18:00:51 +00:00
|
|
|
if (!layers_.empty()) s << " for map with " << layers_.size() << " layers(s)";
|
2012-04-13 18:28:30 +00:00
|
|
|
else s << " (map has no layers)";
|
|
|
|
throw std::out_of_range(s.str());
|
2006-12-06 21:21:17 +00:00
|
|
|
}
|
2016-08-15 09:41:30 +00:00
|
|
|
return mapnik::make_invalid_featureset();
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
featureset_ptr Map::query_map_point(unsigned index, double x, double y) const
|
|
|
|
{
|
2014-08-28 09:17:15 +00:00
|
|
|
view_transform tr = transform();
|
2012-04-13 18:28:30 +00:00
|
|
|
tr.backward(&x,&y);
|
|
|
|
return query_point(index,x,y);
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2006-12-06 20:26:59 +00:00
|
|
|
|
2010-07-25 21:05:30 +00:00
|
|
|
|
2011-12-03 01:48:09 +00: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 19:34:36 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 16:05:58 +00:00
|
|
|
void Map::init_proj_transforms()
|
|
|
|
{
|
|
|
|
std::for_each(layers_.begin(),
|
|
|
|
layers_.end(),
|
|
|
|
[this] (auto const& l)
|
|
|
|
{
|
2021-04-06 09:30:12 +00:00
|
|
|
proj_transform_cache::init(srs_, l.srs());
|
2021-03-18 16:05:58 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2005-06-14 15:06:59 +00:00
|
|
|
}
|