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
|
|
|
|
2006-10-04 13:22:18 +02:00
|
|
|
// mapnik
|
2007-10-08 19:42:41 +02:00
|
|
|
#include <mapnik/layer.hpp>
|
2006-10-04 13:22:18 +02:00
|
|
|
#include <mapnik/datasource.hpp>
|
|
|
|
#include <mapnik/datasource_cache.hpp>
|
2011-05-10 23:09:54 +02:00
|
|
|
|
2007-10-08 19:42:41 +02:00
|
|
|
// stl
|
|
|
|
#include <string>
|
2005-12-14 18:01:09 +01:00
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
namespace mapnik
|
2012-02-02 02:53:35 +01:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
layer::layer(std::string const& name, std::string const& srs)
|
|
|
|
: name_(name),
|
|
|
|
srs_(srs),
|
2012-03-12 16:39:59 +01:00
|
|
|
min_zoom_(0),
|
|
|
|
max_zoom_(std::numeric_limits<double>::max()),
|
2010-06-02 13:03:30 +02:00
|
|
|
active_(true),
|
|
|
|
queryable_(false),
|
|
|
|
clear_label_cache_(false),
|
2011-03-01 18:09:29 +01:00
|
|
|
cache_features_(false),
|
2011-10-13 01:30:18 +02:00
|
|
|
group_by_(""),
|
2012-10-29 10:50:37 +01:00
|
|
|
ds_() {}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
layer::layer(const layer& rhs)
|
|
|
|
: name_(rhs.name_),
|
|
|
|
srs_(rhs.srs_),
|
2012-03-12 16:39:59 +01:00
|
|
|
min_zoom_(rhs.min_zoom_),
|
|
|
|
max_zoom_(rhs.max_zoom_),
|
2010-06-02 13:03:30 +02:00
|
|
|
active_(rhs.active_),
|
|
|
|
queryable_(rhs.queryable_),
|
|
|
|
clear_label_cache_(rhs.clear_label_cache_),
|
2011-03-01 18:09:29 +01:00
|
|
|
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_),
|
2012-08-01 16:44:36 +02:00
|
|
|
ds_(rhs.ds_),
|
|
|
|
buffer_size_(rhs.buffer_size_),
|
|
|
|
maximum_extent_(rhs.maximum_extent_) {}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2014-01-28 15:21:58 +01:00
|
|
|
layer& layer::operator=(layer rhs)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2014-01-28 11:57:26 +01:00
|
|
|
std::swap(*this, rhs);
|
2010-06-02 13:03:30 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool layer::operator==(layer const& other) const
|
|
|
|
{
|
|
|
|
return (this == &other);
|
|
|
|
}
|
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
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
void layer::set_name( std::string const& name)
|
|
|
|
{
|
|
|
|
name_ = name;
|
|
|
|
}
|
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_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void layer::set_srs(std::string const& srs)
|
|
|
|
{
|
|
|
|
srs_ = srs;
|
|
|
|
}
|
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_;
|
|
|
|
}
|
|
|
|
|
2012-03-12 16:39:59 +01:00
|
|
|
void layer::set_min_zoom(double min_zoom)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2012-03-12 16:39:59 +01:00
|
|
|
min_zoom_=min_zoom;
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
|
|
|
|
2012-03-12 16:39:59 +01:00
|
|
|
void layer::set_max_zoom(double max_zoom)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2012-03-12 16:39:59 +01:00
|
|
|
max_zoom_=max_zoom;
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
|
|
|
|
2012-03-12 16:39:59 +01:00
|
|
|
double layer::min_zoom() const
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2012-03-12 16:39:59 +01:00
|
|
|
return min_zoom_;
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
|
|
|
|
2012-03-12 16:39:59 +01:00
|
|
|
double layer::max_zoom() const
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2012-03-12 16:39:59 +01:00
|
|
|
return max_zoom_;
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
|
|
|
|
2012-03-12 16:39:59 +01:00
|
|
|
void layer::set_active(bool active)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
active_=active;
|
|
|
|
}
|
|
|
|
|
2012-03-12 16:39:59 +01:00
|
|
|
bool layer::active() const
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
return active_;
|
|
|
|
}
|
|
|
|
|
2012-03-12 16:39:59 +01:00
|
|
|
bool layer::visible(double scale) const
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2012-03-12 16:39:59 +01:00
|
|
|
return active() && scale >= min_zoom_ - 1e-6 && scale < max_zoom_ + 1e-6;
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
|
|
|
|
2012-03-12 16:39:59 +01:00
|
|
|
void layer::set_queryable(bool queryable)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
queryable_=queryable;
|
|
|
|
}
|
|
|
|
|
2012-03-12 16:39:59 +01: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
|
|
|
|
2012-08-01 16:44:36 +02: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 10:50:37 +01:00
|
|
|
buffer_size_.reset(size);
|
2012-08-01 16:44:36 +02:00
|
|
|
}
|
|
|
|
|
2012-10-29 10:50:37 +01:00
|
|
|
boost::optional<int> const& layer::buffer_size() const
|
2012-08-01 16:44:36 +02:00
|
|
|
{
|
|
|
|
return buffer_size_;
|
|
|
|
}
|
|
|
|
|
2012-10-29 10:50:37 +01:00
|
|
|
void layer::reset_buffer_size()
|
|
|
|
{
|
2012-11-09 11:57:10 +01:00
|
|
|
buffer_size_.reset();
|
2012-10-29 10:50:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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_;
|
|
|
|
}
|
2011-03-01 18:09:29 +01:00
|
|
|
|
|
|
|
void layer::set_cache_features(bool cache_features)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-08-21 01:26:41 +02:00
|
|
|
std::string const& layer::group_by() const
|
2011-10-13 01:30:18 +02:00
|
|
|
{
|
|
|
|
return group_by_;
|
|
|
|
}
|
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|