mapnik/src/layer.cpp

325 lines
7.4 KiB
C++
Raw Normal View History

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