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 $
|
|
|
|
|
2006-10-04 13:22:18 +02:00
|
|
|
// stl
|
2005-12-14 18:01:09 +01:00
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
2006-10-04 13:22:18 +02:00
|
|
|
// boost
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
// mapnik
|
|
|
|
#include <mapnik/style.hpp>
|
|
|
|
#include <mapnik/datasource.hpp>
|
|
|
|
#include <mapnik/datasource_cache.hpp>
|
|
|
|
#include <mapnik/layer.hpp>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using boost::shared_ptr;
|
2005-12-14 18:01:09 +01:00
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
namespace mapnik
|
2006-10-04 13:22:18 +02:00
|
|
|
{
|
2006-10-16 15:44:52 +02:00
|
|
|
Layer::Layer(std::string const& name, std::string const& srs)
|
2006-10-03 10:44:04 +02:00
|
|
|
: name_(name),
|
2006-05-25 00:15:04 +02:00
|
|
|
title_(""),
|
|
|
|
abstract_(""),
|
2006-10-16 15:44:52 +02:00
|
|
|
srs_(srs),
|
2006-05-19 18:07:13 +02:00
|
|
|
minZoom_(0),
|
|
|
|
maxZoom_(std::numeric_limits<double>::max()),
|
|
|
|
active_(true),
|
2007-01-09 12:23:19 +01:00
|
|
|
queryable_(false),
|
2007-05-01 09:53:20 +02:00
|
|
|
clear_label_cache_(false),
|
2006-10-04 13:22:18 +02:00
|
|
|
ds_() {}
|
2005-12-12 14:15:33 +01:00
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
Layer::Layer(const Layer& rhs)
|
2006-10-03 10:44:04 +02:00
|
|
|
: name_(rhs.name_),
|
|
|
|
title_(rhs.title_),
|
|
|
|
abstract_(rhs.abstract_),
|
2006-10-16 15:44:52 +02:00
|
|
|
srs_(rhs.srs_),
|
2006-10-03 10:44:04 +02:00
|
|
|
minZoom_(rhs.minZoom_),
|
|
|
|
maxZoom_(rhs.maxZoom_),
|
|
|
|
active_(rhs.active_),
|
2007-01-09 12:23:19 +01:00
|
|
|
queryable_(rhs.queryable_),
|
2007-05-01 09:53:20 +02:00
|
|
|
clear_label_cache_(rhs.clear_label_cache_),
|
2006-10-03 10:44:04 +02:00
|
|
|
styles_(rhs.styles_),
|
2006-10-04 13:22:18 +02:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
name_=rhs.name_;
|
2006-05-25 00:15:04 +02:00
|
|
|
title_=rhs.title_;
|
|
|
|
abstract_=rhs.abstract_;
|
2005-06-14 17:06:59 +02:00
|
|
|
minZoom_=rhs.minZoom_;
|
|
|
|
maxZoom_=rhs.maxZoom_;
|
|
|
|
active_=rhs.active_;
|
2007-01-09 12:23:19 +01:00
|
|
|
queryable_=rhs.queryable_;
|
2005-06-14 17:06:59 +02:00
|
|
|
styles_=rhs.styles_;
|
2006-10-04 13:22:18 +02:00
|
|
|
ds_=rhs.ds_;
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2006-10-03 10:44:04 +02:00
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
Layer::~Layer() {}
|
|
|
|
|
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_;
|
|
|
|
}
|
|
|
|
|
2006-05-25 00:15:04 +02:00
|
|
|
void Layer::set_title( std::string const& title)
|
|
|
|
{
|
|
|
|
title_ = title;
|
|
|
|
}
|
|
|
|
|
|
|
|
string const& Layer::title() const
|
|
|
|
{
|
|
|
|
return title_;
|
|
|
|
}
|
2006-10-03 10:44:04 +02:00
|
|
|
|
2006-05-25 00:15:04 +02:00
|
|
|
void Layer::set_abstract( std::string const& abstract)
|
|
|
|
{
|
|
|
|
abstract_ = abstract;
|
|
|
|
}
|
|
|
|
|
|
|
|
string const& Layer::abstract() const
|
|
|
|
{
|
|
|
|
return abstract_;
|
|
|
|
}
|
|
|
|
|
2006-10-16 15:44:52 +02:00
|
|
|
void Layer::set_srs(std::string const& srs)
|
|
|
|
{
|
|
|
|
srs_ = srs;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string const& Layer::srs() const
|
|
|
|
{
|
|
|
|
return srs_;
|
|
|
|
}
|
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
void Layer::add_style(std::string const& stylename)
|
|
|
|
{
|
|
|
|
styles_.push_back(stylename);
|
|
|
|
}
|
2006-10-16 15:44:52 +02:00
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
std::vector<std::string> const& Layer::styles() const
|
|
|
|
{
|
|
|
|
return styles_;
|
|
|
|
}
|
2006-12-20 01:22:45 +01:00
|
|
|
|
|
|
|
std::vector<std::string> & Layer::styles()
|
|
|
|
{
|
|
|
|
return styles_;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2006-11-17 03:01:21 +01:00
|
|
|
return isActive() && scale >= minZoom_ - 1e-6 && scale < maxZoom_ + 1e-6;
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
|
|
|
|
2007-01-09 12:23:19 +01:00
|
|
|
void Layer::setQueryable(bool queryable)
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2007-01-09 12:23:19 +01:00
|
|
|
queryable_=queryable;
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
|
|
|
|
2007-01-09 12:23:19 +01:00
|
|
|
bool Layer::isQueryable() const
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2007-01-09 12:23:19 +01:00
|
|
|
return queryable_;
|
2005-06-14 17:06:59 +02: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 12:02:59 +01:00
|
|
|
datasource_ptr Layer::datasource() const
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2006-05-19 18:07:13 +02:00
|
|
|
return ds_;
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2006-10-03 10:44:04 +02: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 12:02:59 +01:00
|
|
|
void Layer::set_datasource(datasource_ptr const& ds)
|
2006-03-28 10:29:36 +02:00
|
|
|
{
|
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-10-03 10:44:04 +02:00
|
|
|
if (ds_) return ds_->envelope();
|
2005-12-14 18:01:09 +01:00
|
|
|
return Envelope<double>();
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2006-10-03 10:44:04 +02:00
|
|
|
|
2007-05-01 09:53:20 +02:00
|
|
|
void Layer::set_clear_label_cache(bool clear)
|
|
|
|
{
|
|
|
|
clear_label_cache_ = clear;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Layer::clear_label_cache() const
|
|
|
|
{
|
|
|
|
return clear_label_cache_;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|