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
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* Copyright (C) 2006 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
|
|
|
|
|
|
|
//$Id: layer.cpp 17 2005-03-08 23:58:43Z pavlenko $
|
|
|
|
|
2005-12-14 18:01:09 +01:00
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
#include "style.hpp"
|
|
|
|
#include "datasource.hpp"
|
|
|
|
#include "datasource_cache.hpp"
|
|
|
|
#include "layer.hpp"
|
|
|
|
|
2005-12-14 18:01:09 +01:00
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
namespace mapnik
|
|
|
|
{
|
|
|
|
using namespace std;
|
2006-03-28 10:29:36 +02:00
|
|
|
Layer::Layer()
|
2006-05-19 18:07:13 +02:00
|
|
|
: params_(),
|
|
|
|
name_("unknown"),
|
|
|
|
minZoom_(0),
|
|
|
|
maxZoom_(std::numeric_limits<double>::max()),
|
|
|
|
active_(true),
|
|
|
|
selectable_(false),
|
|
|
|
selection_style_("default_selection")
|
2006-03-28 10:29:36 +02:00
|
|
|
{}
|
|
|
|
|
2005-12-14 18:01:09 +01:00
|
|
|
Layer::Layer(const parameters& params)
|
2005-06-14 17:06:59 +02:00
|
|
|
:params_(params),
|
2006-05-19 18:07:13 +02:00
|
|
|
name_(params_["name"]),
|
|
|
|
minZoom_(0),
|
|
|
|
maxZoom_(std::numeric_limits<double>::max()),
|
|
|
|
active_(true),
|
|
|
|
selectable_(false),
|
|
|
|
selection_style_("default_selection")
|
2005-12-14 18:01:09 +01:00
|
|
|
{}
|
2005-12-12 14:15:33 +01:00
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
Layer::Layer(const Layer& rhs)
|
2006-05-23 18:52:10 +02:00
|
|
|
: params_(rhs.params_),
|
|
|
|
name_(rhs.name_),
|
|
|
|
minZoom_(rhs.minZoom_),
|
|
|
|
maxZoom_(rhs.maxZoom_),
|
|
|
|
active_(rhs.active_),
|
|
|
|
selectable_(rhs.selectable_),
|
|
|
|
styles_(rhs.styles_),
|
|
|
|
selection_style_(rhs.selection_style_),
|
|
|
|
ds_(rhs.ds_) {}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
|
|
|
Layer& Layer::operator=(const Layer& rhs)
|
|
|
|
{
|
|
|
|
Layer tmp(rhs);
|
|
|
|
swap(tmp);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2005-09-08 15:20:37 +02:00
|
|
|
bool Layer::operator==(Layer const& other) const
|
|
|
|
{
|
2006-05-19 18:07:13 +02:00
|
|
|
return (this == &other);
|
2005-09-08 15:20:37 +02:00
|
|
|
}
|
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
void Layer::swap(const Layer& rhs)
|
|
|
|
{
|
|
|
|
params_=rhs.params_;
|
|
|
|
name_=rhs.name_;
|
|
|
|
minZoom_=rhs.minZoom_;
|
|
|
|
maxZoom_=rhs.maxZoom_;
|
|
|
|
active_=rhs.active_;
|
|
|
|
selectable_=rhs.selectable_;
|
2006-05-23 18:52:10 +02:00
|
|
|
ds_=rhs.ds_;
|
2005-06-14 17:06:59 +02:00
|
|
|
styles_=rhs.styles_;
|
2006-05-19 18:07:13 +02:00
|
|
|
selection_style_=rhs.selection_style_;
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2006-05-19 18:07:13 +02:00
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
Layer::~Layer() {}
|
|
|
|
|
2005-12-14 18:01:09 +01:00
|
|
|
parameters const& Layer::params() const
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
|
|
|
return params_;
|
|
|
|
}
|
|
|
|
|
2006-05-19 18:07:13 +02:00
|
|
|
void Layer::set_name( std::string const& name)
|
|
|
|
{
|
|
|
|
name_ = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
string const& Layer::name() const
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
|
|
|
return name_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::add_style(std::string const& stylename)
|
|
|
|
{
|
|
|
|
styles_.push_back(stylename);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> const& Layer::styles() const
|
|
|
|
{
|
|
|
|
return styles_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::setMinZoom(double minZoom)
|
|
|
|
{
|
|
|
|
minZoom_=minZoom;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::setMaxZoom(double maxZoom)
|
|
|
|
{
|
|
|
|
maxZoom_=maxZoom;
|
|
|
|
}
|
|
|
|
|
|
|
|
double Layer::getMinZoom() const
|
|
|
|
{
|
|
|
|
return minZoom_;
|
|
|
|
}
|
|
|
|
|
|
|
|
double Layer::getMaxZoom() const
|
|
|
|
{
|
|
|
|
return maxZoom_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::setActive(bool active)
|
|
|
|
{
|
|
|
|
active_=active;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Layer::isActive() const
|
|
|
|
{
|
|
|
|
return active_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Layer::isVisible(double scale) const
|
|
|
|
{
|
|
|
|
return isActive() && scale>=minZoom_ && scale<maxZoom_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::setSelectable(bool selectable)
|
|
|
|
{
|
|
|
|
selectable_=selectable;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Layer::isSelectable() const
|
|
|
|
{
|
|
|
|
return selectable_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const datasource_p& Layer::datasource() const
|
|
|
|
{
|
2006-05-19 18:07:13 +02:00
|
|
|
if (!ds_)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ds_=datasource_cache::instance()->create(params_);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
std::clog << "exception caught : can not create datasource" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ds_;
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2006-03-28 10:29:36 +02:00
|
|
|
// TODO: !!!!
|
|
|
|
void Layer::set_datasource(datasource_p const& ds)
|
|
|
|
{
|
2006-05-19 18:07:13 +02:00
|
|
|
ds_ = ds;
|
2006-03-28 10:29:36 +02:00
|
|
|
}
|
|
|
|
|
2005-12-01 11:06:40 +01:00
|
|
|
Envelope<double> Layer::envelope() const
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2006-05-19 18:07:13 +02:00
|
|
|
datasource_p const& ds = datasource();
|
|
|
|
if (ds)
|
|
|
|
{
|
|
|
|
return ds->envelope();
|
|
|
|
}
|
2005-12-14 18:01:09 +01:00
|
|
|
return Envelope<double>();
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::selection_style(const std::string& name)
|
|
|
|
{
|
2006-05-19 18:07:13 +02:00
|
|
|
selection_style_=name;
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& Layer::selection_style() const
|
|
|
|
{
|
2006-05-19 18:07:13 +02:00
|
|
|
return selection_style_;
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
|
|
|
|
2005-12-12 14:15:33 +01:00
|
|
|
void Layer::add_to_selection(shared_ptr<Feature>& feature) const
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2006-05-19 18:07:13 +02:00
|
|
|
selection_.push_back(feature);
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
|
|
|
|
2005-12-12 14:15:33 +01:00
|
|
|
vector<shared_ptr<Feature> >& Layer::selection() const
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2006-05-19 18:07:13 +02:00
|
|
|
return selection_;
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::clear_selection() const
|
|
|
|
{
|
2006-05-19 18:07:13 +02:00
|
|
|
selection_.clear();
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
|
|
|
}
|