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
|
|
|
|
2006-10-04 11:22:18 +00:00
|
|
|
// mapnik
|
|
|
|
#include <mapnik/datasource.hpp>
|
|
|
|
#include <mapnik/datasource_cache.hpp>
|
2014-07-23 06:57:06 +00:00
|
|
|
#include <mapnik/layer.hpp>
|
2011-05-10 21:09:54 +00:00
|
|
|
|
2007-10-08 17:42:41 +00:00
|
|
|
// stl
|
|
|
|
#include <string>
|
2005-12-14 17:01:09 +00:00
|
|
|
|
2005-06-14 15:06:59 +00:00
|
|
|
namespace mapnik
|
2012-02-02 01:53:35 +00:00
|
|
|
{
|
2014-10-01 20:53:12 +00:00
|
|
|
|
2016-08-26 09:09:22 +00:00
|
|
|
layer::layer(std::string const& _name, std::string const& _srs)
|
|
|
|
: name_(_name),
|
|
|
|
srs_(_srs),
|
2015-05-15 19:34:12 +00:00
|
|
|
minimum_scale_denom_(0),
|
|
|
|
maximum_scale_denom_(std::numeric_limits<double>::max()),
|
2010-06-02 11:03:30 +00:00
|
|
|
active_(true),
|
|
|
|
queryable_(false),
|
|
|
|
clear_label_cache_(false),
|
2011-03-01 17:09:29 +00:00
|
|
|
cache_features_(false),
|
2014-10-01 20:53:12 +00:00
|
|
|
group_by_(),
|
|
|
|
styles_(),
|
2016-07-29 10:44:51 +00:00
|
|
|
layers_(),
|
2014-10-01 20:53:12 +00:00
|
|
|
ds_(),
|
2014-10-01 21:08:08 +00:00
|
|
|
buffer_size_(),
|
2016-07-29 10:44:51 +00:00
|
|
|
maximum_extent_(),
|
|
|
|
comp_op_(),
|
|
|
|
opacity_(1.0f)
|
|
|
|
{}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2014-05-27 10:20:32 +00:00
|
|
|
layer::layer(layer const& rhs)
|
2010-06-02 11:03:30 +00:00
|
|
|
: name_(rhs.name_),
|
|
|
|
srs_(rhs.srs_),
|
2015-05-15 19:34:12 +00:00
|
|
|
minimum_scale_denom_(rhs.minimum_scale_denom_),
|
|
|
|
maximum_scale_denom_(rhs.maximum_scale_denom_),
|
2010-06-02 11:03:30 +00:00
|
|
|
active_(rhs.active_),
|
|
|
|
queryable_(rhs.queryable_),
|
|
|
|
clear_label_cache_(rhs.clear_label_cache_),
|
2011-03-01 17:09:29 +00:00
|
|
|
cache_features_(rhs.cache_features_),
|
2011-10-12 23:30:18 +00:00
|
|
|
group_by_(rhs.group_by_),
|
2010-06-02 11:03:30 +00:00
|
|
|
styles_(rhs.styles_),
|
2016-07-29 10:44:51 +00:00
|
|
|
layers_(rhs.layers_),
|
2014-05-30 10:02:50 +00:00
|
|
|
ds_(rhs.ds_),
|
2012-08-01 14:44:36 +00:00
|
|
|
buffer_size_(rhs.buffer_size_),
|
2016-07-29 10:44:51 +00:00
|
|
|
maximum_extent_(rhs.maximum_extent_),
|
|
|
|
comp_op_(rhs.comp_op_),
|
|
|
|
opacity_(rhs.opacity_)
|
|
|
|
{}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2014-05-28 08:48:13 +00:00
|
|
|
layer::layer(layer && rhs)
|
|
|
|
: name_(std::move(rhs.name_)),
|
|
|
|
srs_(std::move(rhs.srs_)),
|
2015-05-15 19:34:12 +00:00
|
|
|
minimum_scale_denom_(std::move(rhs.minimum_scale_denom_)),
|
|
|
|
maximum_scale_denom_(std::move(rhs.maximum_scale_denom_)),
|
2014-05-28 08:48:13 +00:00
|
|
|
active_(std::move(rhs.active_)),
|
|
|
|
queryable_(std::move(rhs.queryable_)),
|
|
|
|
clear_label_cache_(std::move(rhs.clear_label_cache_)),
|
|
|
|
cache_features_(std::move(rhs.cache_features_)),
|
|
|
|
group_by_(std::move(rhs.group_by_)),
|
|
|
|
styles_(std::move(rhs.styles_)),
|
2016-07-29 10:44:51 +00:00
|
|
|
layers_(std::move(rhs.layers_)),
|
2014-05-28 08:48:13 +00:00
|
|
|
ds_(std::move(rhs.ds_)),
|
|
|
|
buffer_size_(std::move(rhs.buffer_size_)),
|
2016-07-29 10:44:51 +00:00
|
|
|
maximum_extent_(std::move(rhs.maximum_extent_)),
|
|
|
|
comp_op_(std::move(rhs.comp_op_)),
|
|
|
|
opacity_(std::move(rhs.opacity_))
|
|
|
|
{}
|
2014-05-28 08:48:13 +00:00
|
|
|
|
2014-01-28 14:21:58 +00:00
|
|
|
layer& layer::operator=(layer rhs)
|
2014-05-27 10:20:32 +00:00
|
|
|
{
|
|
|
|
using std::swap;
|
2014-08-31 07:44:41 +00:00
|
|
|
std::swap(this->name_,rhs.name_);
|
|
|
|
std::swap(this->srs_, rhs.srs_);
|
2015-05-15 19:34:12 +00:00
|
|
|
std::swap(this->minimum_scale_denom_, rhs.minimum_scale_denom_);
|
|
|
|
std::swap(this->maximum_scale_denom_,rhs.maximum_scale_denom_);
|
2014-08-31 07:44:41 +00:00
|
|
|
std::swap(this->active_, rhs.active_);
|
|
|
|
std::swap(this->queryable_, rhs.queryable_);
|
|
|
|
std::swap(this->clear_label_cache_, rhs.clear_label_cache_);
|
|
|
|
std::swap(this->cache_features_, rhs.cache_features_);
|
|
|
|
std::swap(this->group_by_, rhs.group_by_);
|
|
|
|
std::swap(this->styles_, rhs.styles_);
|
|
|
|
std::swap(this->ds_, rhs.ds_);
|
|
|
|
std::swap(this->buffer_size_, rhs.buffer_size_);
|
|
|
|
std::swap(this->maximum_extent_, rhs.maximum_extent_);
|
2016-07-29 10:44:51 +00:00
|
|
|
std::swap(this->comp_op_, rhs.comp_op_);
|
|
|
|
std::swap(this->opacity_, rhs.opacity_);
|
2014-08-31 07:44:41 +00:00
|
|
|
return *this;
|
2014-05-27 10:20:32 +00:00
|
|
|
}
|
|
|
|
|
2014-05-27 10:33:26 +00:00
|
|
|
bool layer::operator==(layer const& rhs) const
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2014-05-27 10:33:26 +00:00
|
|
|
return (name_ == rhs.name_) &&
|
|
|
|
(srs_ == rhs.srs_) &&
|
2015-05-15 19:34:12 +00:00
|
|
|
(minimum_scale_denom_ == rhs.minimum_scale_denom_) &&
|
|
|
|
(maximum_scale_denom_ == rhs.maximum_scale_denom_) &&
|
2014-05-27 10:33:26 +00:00
|
|
|
(active_ == rhs.active_) &&
|
|
|
|
(queryable_ == rhs.queryable_) &&
|
|
|
|
(clear_label_cache_ == rhs.clear_label_cache_) &&
|
|
|
|
(cache_features_ == rhs.cache_features_) &&
|
|
|
|
(group_by_ == rhs.group_by_) &&
|
|
|
|
(styles_ == rhs.styles_) &&
|
2014-05-28 14:40:25 +00:00
|
|
|
((ds_ && rhs.ds_) ? *ds_ == *rhs.ds_ : ds_ == rhs.ds_) &&
|
2014-05-27 10:33:26 +00:00
|
|
|
(buffer_size_ == rhs.buffer_size_) &&
|
2016-07-29 10:44:51 +00:00
|
|
|
(maximum_extent_ == rhs.maximum_extent_) &&
|
|
|
|
(comp_op_ == rhs.comp_op_) &&
|
|
|
|
(opacity_ == rhs.opacity_);
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
layer::~layer() {}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2016-08-26 09:09:22 +00:00
|
|
|
void layer::set_name( std::string const& _name)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2016-08-26 09:09:22 +00:00
|
|
|
name_ = _name;
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2011-06-24 00:53:00 +00:00
|
|
|
std::string const& layer::name() const
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
|
|
|
return name_;
|
|
|
|
}
|
|
|
|
|
2016-08-26 09:09:22 +00:00
|
|
|
void layer::set_srs(std::string const& _srs)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2016-08-26 09:09:22 +00:00
|
|
|
srs_ = _srs;
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
std::string const& layer::srs() const
|
|
|
|
{
|
|
|
|
return srs_;
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
void layer::add_style(std::string const& stylename)
|
|
|
|
{
|
|
|
|
styles_.push_back(stylename);
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
std::vector<std::string> const& layer::styles() const
|
|
|
|
{
|
|
|
|
return styles_;
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
std::vector<std::string> & layer::styles()
|
|
|
|
{
|
|
|
|
return styles_;
|
|
|
|
}
|
|
|
|
|
2016-07-29 10:44:51 +00:00
|
|
|
void layer::add_layer(layer const& l)
|
|
|
|
{
|
|
|
|
layers_.emplace_back(l);
|
|
|
|
}
|
|
|
|
|
|
|
|
void layer::add_layer(layer && l)
|
|
|
|
{
|
|
|
|
layers_.push_back(std::move(l));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<layer> const& layer::layers() const
|
|
|
|
{
|
|
|
|
return layers_;
|
|
|
|
}
|
|
|
|
|
2015-05-15 19:34:12 +00:00
|
|
|
void layer::set_minimum_scale_denominator(double minimum_scale_denom)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2015-05-15 19:34:12 +00:00
|
|
|
minimum_scale_denom_=minimum_scale_denom;
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 19:34:12 +00:00
|
|
|
void layer::set_maximum_scale_denominator(double maximum_scale_denom)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2015-05-15 19:34:12 +00:00
|
|
|
maximum_scale_denom_=maximum_scale_denom;
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 19:34:12 +00:00
|
|
|
double layer::minimum_scale_denominator() const
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2015-05-15 19:34:12 +00:00
|
|
|
return minimum_scale_denom_;
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 19:34:12 +00:00
|
|
|
double layer::maximum_scale_denominator() const
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2015-05-15 19:34:12 +00:00
|
|
|
return maximum_scale_denom_;
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
|
|
|
|
2016-08-26 09:09:22 +00:00
|
|
|
void layer::set_active(bool _active)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2016-08-26 09:09:22 +00:00
|
|
|
active_ = _active;
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
|
|
|
|
2012-03-12 15:39:59 +00:00
|
|
|
bool layer::active() const
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
|
|
|
return active_;
|
|
|
|
}
|
|
|
|
|
2015-05-15 19:34:12 +00:00
|
|
|
bool layer::visible(double scale_denom) const
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2015-05-15 19:34:12 +00:00
|
|
|
return active() && scale_denom >= minimum_scale_denom_ - 1e-6 && scale_denom < maximum_scale_denom_ + 1e-6;
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
|
|
|
|
2016-08-26 09:09:22 +00:00
|
|
|
void layer::set_queryable(bool _queryable)
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2016-08-26 09:09:22 +00:00
|
|
|
queryable_ = _queryable;
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
|
|
|
|
2012-03-12 15:39:59 +00:00
|
|
|
bool layer::queryable() const
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
|
|
|
return queryable_;
|
|
|
|
}
|
|
|
|
|
|
|
|
datasource_ptr layer::datasource() const
|
|
|
|
{
|
|
|
|
return ds_;
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
void layer::set_datasource(datasource_ptr const& ds)
|
|
|
|
{
|
|
|
|
ds_ = ds;
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2012-08-01 14:44:36 +00:00
|
|
|
void layer::set_maximum_extent(box2d<double> const& box)
|
|
|
|
{
|
|
|
|
maximum_extent_.reset(box);
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::optional<box2d<double> > const& layer::maximum_extent() const
|
|
|
|
{
|
|
|
|
return maximum_extent_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void layer::reset_maximum_extent()
|
|
|
|
{
|
|
|
|
maximum_extent_.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void layer::set_buffer_size(int size)
|
|
|
|
{
|
2012-10-29 09:50:37 +00:00
|
|
|
buffer_size_.reset(size);
|
2012-08-01 14:44:36 +00:00
|
|
|
}
|
|
|
|
|
2012-10-29 09:50:37 +00:00
|
|
|
boost::optional<int> const& layer::buffer_size() const
|
2012-08-01 14:44:36 +00:00
|
|
|
{
|
|
|
|
return buffer_size_;
|
|
|
|
}
|
|
|
|
|
2012-10-29 09:50:37 +00:00
|
|
|
void layer::reset_buffer_size()
|
|
|
|
{
|
2012-11-09 10:57:10 +00:00
|
|
|
buffer_size_.reset();
|
2012-10-29 09:50:37 +00:00
|
|
|
}
|
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
box2d<double> layer::envelope() const
|
|
|
|
{
|
|
|
|
if (ds_) return ds_->envelope();
|
|
|
|
return box2d<double>();
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
void layer::set_clear_label_cache(bool clear)
|
|
|
|
{
|
|
|
|
clear_label_cache_ = clear;
|
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
bool layer::clear_label_cache() const
|
|
|
|
{
|
|
|
|
return clear_label_cache_;
|
|
|
|
}
|
2011-03-01 17:09:29 +00:00
|
|
|
|
2016-08-26 09:09:22 +00:00
|
|
|
void layer::set_cache_features(bool _cache_features)
|
2011-03-01 17:09:29 +00:00
|
|
|
{
|
2016-08-26 09:09:22 +00:00
|
|
|
cache_features_ = _cache_features;
|
2011-03-01 17:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool layer::cache_features() const
|
|
|
|
{
|
|
|
|
return cache_features_;
|
|
|
|
}
|
|
|
|
|
2013-07-19 19:46:01 +00:00
|
|
|
void layer::set_group_by(std::string const& column)
|
2011-10-12 23:30:18 +00:00
|
|
|
{
|
|
|
|
group_by_ = column;
|
|
|
|
}
|
|
|
|
|
2012-08-20 23:26:41 +00:00
|
|
|
std::string const& layer::group_by() const
|
2011-10-12 23:30:18 +00:00
|
|
|
{
|
|
|
|
return group_by_;
|
|
|
|
}
|
|
|
|
|
2016-07-29 10:44:51 +00:00
|
|
|
void layer::set_comp_op(composite_mode_e comp_op)
|
|
|
|
{
|
|
|
|
comp_op_ = comp_op;
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::optional<composite_mode_e> layer::comp_op() const
|
|
|
|
{
|
|
|
|
return comp_op_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void layer::set_opacity(double opacity)
|
|
|
|
{
|
|
|
|
opacity_ = opacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
double layer::get_opacity() const
|
|
|
|
{
|
|
|
|
return opacity_;
|
|
|
|
}
|
|
|
|
|
2005-06-14 15:06:59 +00:00
|
|
|
}
|