1.removed named_style_cache
2.styles moved to Map object
This commit is contained in:
parent
95d26be572
commit
2a858bcd19
10 changed files with 44 additions and 135 deletions
|
@ -91,6 +91,8 @@ void export_map()
|
||||||
.def("pan",&Map::pan)
|
.def("pan",&Map::pan)
|
||||||
.def("zoom",&Map::zoom)
|
.def("zoom",&Map::zoom)
|
||||||
.def("pan_and_zoom",&Map::pan_and_zoom)
|
.def("pan_and_zoom",&Map::pan_and_zoom)
|
||||||
|
.def("append_style",&Map::insert_style)
|
||||||
|
.def("remove_style",&Map::remove_style)
|
||||||
.add_property("layers",make_function
|
.add_property("layers",make_function
|
||||||
(&Map::layers,return_value_policy<reference_existing_object>()))
|
(&Map::layers,return_value_policy<reference_existing_object>()))
|
||||||
.def_pickle(map_pickle_suite())
|
.def_pickle(map_pickle_suite())
|
||||||
|
|
|
@ -23,9 +23,6 @@
|
||||||
#include "mapnik.hpp"
|
#include "mapnik.hpp"
|
||||||
|
|
||||||
using mapnik::feature_type_style;
|
using mapnik::feature_type_style;
|
||||||
using mapnik::named_style_cache;
|
|
||||||
using mapnik::singleton;
|
|
||||||
using mapnik::CreateStatic;
|
|
||||||
using mapnik::rules;
|
using mapnik::rules;
|
||||||
|
|
||||||
void export_style()
|
void export_style()
|
||||||
|
@ -40,18 +37,5 @@ void export_style()
|
||||||
(&feature_type_style::get_rules,return_value_policy<reference_existing_object>()))
|
(&feature_type_style::get_rules,return_value_policy<reference_existing_object>()))
|
||||||
;
|
;
|
||||||
|
|
||||||
class_<singleton<named_style_cache,CreateStatic>,boost::noncopyable>("singleton",no_init)
|
|
||||||
.def("instance",&singleton<named_style_cache,CreateStatic>::instance,
|
|
||||||
return_value_policy<reference_existing_object>())
|
|
||||||
.staticmethod("instance")
|
|
||||||
;
|
|
||||||
|
|
||||||
class_<named_style_cache,bases<singleton<named_style_cache,CreateStatic> >,
|
|
||||||
boost::noncopyable>("style_cache",no_init)
|
|
||||||
.def("insert",&named_style_cache::insert)
|
|
||||||
.staticmethod("insert")
|
|
||||||
.def("remove",&named_style_cache::remove)
|
|
||||||
.staticmethod("remove")
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include <boost/serialization/serialization.hpp>
|
#include <boost/serialization/serialization.hpp>
|
||||||
#include <boost/serialization/vector.hpp>
|
#include <boost/serialization/vector.hpp>
|
||||||
|
#include "feature_type_style.hpp"
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik
|
||||||
{
|
{
|
||||||
|
@ -46,6 +47,7 @@ namespace mapnik
|
||||||
unsigned height_;
|
unsigned height_;
|
||||||
int srid_;
|
int srid_;
|
||||||
Color background_;
|
Color background_;
|
||||||
|
std::map<std::string,feature_type_style> styles_;
|
||||||
std::vector<Layer> layers_;
|
std::vector<Layer> layers_;
|
||||||
Envelope<double> currentExtent_;
|
Envelope<double> currentExtent_;
|
||||||
public:
|
public:
|
||||||
|
@ -53,11 +55,15 @@ namespace mapnik
|
||||||
Map(int width,int height,int srid=-1);
|
Map(int width,int height,int srid=-1);
|
||||||
Map(const Map& rhs);
|
Map(const Map& rhs);
|
||||||
Map& operator=(const Map& rhs);
|
Map& operator=(const Map& rhs);
|
||||||
|
|
||||||
|
bool insert_style(std::string const& name,feature_type_style const& style);
|
||||||
|
void remove_style(const std::string& name);
|
||||||
|
feature_type_style find_style(std::string const& name) const;
|
||||||
|
|
||||||
size_t layerCount() const;
|
size_t layerCount() const;
|
||||||
void addLayer(const Layer& l);
|
void addLayer(const Layer& l);
|
||||||
const Layer& getLayer(size_t index) const;
|
const Layer& getLayer(size_t index) const;
|
||||||
void removeLayer(size_t index);
|
void removeLayer(size_t index);
|
||||||
void removeLayer(const char* lName);
|
|
||||||
std::vector<Layer> const& layers() const;
|
std::vector<Layer> const& layers() const;
|
||||||
unsigned getWidth() const;
|
unsigned getWidth() const;
|
||||||
unsigned getHeight() const;
|
unsigned getHeight() const;
|
||||||
|
|
|
@ -56,7 +56,6 @@
|
||||||
#include "wkb.hpp"
|
#include "wkb.hpp"
|
||||||
#include "map.hpp"
|
#include "map.hpp"
|
||||||
#include "feature_type_style.hpp"
|
#include "feature_type_style.hpp"
|
||||||
#include "named_style_cache.hpp"
|
|
||||||
#include "feature_factory.hpp"
|
#include "feature_factory.hpp"
|
||||||
#include "math_expr.hpp"
|
#include "math_expr.hpp"
|
||||||
#include "value.hpp"
|
#include "value.hpp"
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
/* This file is part of Mapnik (c++ mapping toolkit)
|
|
||||||
* Copyright (C) 2005 Artem Pavlenko
|
|
||||||
*
|
|
||||||
* Mapnik is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//$Id: style_cache.hpp 39 2005-04-10 20:39:53Z pavlenko $
|
|
||||||
|
|
||||||
#ifndef STYLE_CACHE_HPP
|
|
||||||
#define STYLE_CACHE_HPP
|
|
||||||
|
|
||||||
#include "utils.hpp"
|
|
||||||
#include <map>
|
|
||||||
#include "feature_type_style.hpp"
|
|
||||||
|
|
||||||
namespace mapnik {
|
|
||||||
|
|
||||||
class named_style_cache : public singleton <named_style_cache,CreateStatic>
|
|
||||||
{
|
|
||||||
friend class CreateStatic<named_style_cache>;
|
|
||||||
private:
|
|
||||||
static std::map<std::string,feature_type_style> styles_;
|
|
||||||
named_style_cache();
|
|
||||||
~named_style_cache();
|
|
||||||
named_style_cache(const named_style_cache&);
|
|
||||||
named_style_cache& operator=(const named_style_cache&);
|
|
||||||
public:
|
|
||||||
static bool insert(const std::string& name,const feature_type_style& style);
|
|
||||||
static void remove(const std::string& name);
|
|
||||||
static feature_type_style find(const std::string& name);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif //STYLE_CACHE_HPP
|
|
|
@ -36,7 +36,7 @@ namespace mapnik
|
||||||
static void render(const Map& map,Image& image);
|
static void render(const Map& map,Image& image);
|
||||||
private:
|
private:
|
||||||
Renderer();
|
Renderer();
|
||||||
static void render_vector_layer(datasource_p const& ds,
|
static void render_vector_layer(datasource_p const& ds,Map const& map,
|
||||||
std::vector<std::string> const& ,
|
std::vector<std::string> const& ,
|
||||||
unsigned width,
|
unsigned width,
|
||||||
unsigned height,
|
unsigned height,
|
||||||
|
|
|
@ -41,7 +41,6 @@ source = Split(
|
||||||
plugin.cpp
|
plugin.cpp
|
||||||
png_reader.cpp
|
png_reader.cpp
|
||||||
render.cpp
|
render.cpp
|
||||||
named_style_cache.cpp
|
|
||||||
text.cpp
|
text.cpp
|
||||||
tiff_reader.cpp
|
tiff_reader.cpp
|
||||||
wkb.cpp
|
wkb.cpp
|
||||||
|
|
25
src/map.cpp
25
src/map.cpp
|
@ -40,6 +40,7 @@ namespace mapnik
|
||||||
height_(rhs.height_),
|
height_(rhs.height_),
|
||||||
srid_(rhs.srid_),
|
srid_(rhs.srid_),
|
||||||
background_(rhs.background_),
|
background_(rhs.background_),
|
||||||
|
styles_(rhs.styles_),
|
||||||
layers_(rhs.layers_),
|
layers_(rhs.layers_),
|
||||||
currentExtent_(rhs.currentExtent_) {}
|
currentExtent_(rhs.currentExtent_) {}
|
||||||
|
|
||||||
|
@ -50,10 +51,29 @@ namespace mapnik
|
||||||
height_=rhs.height_;
|
height_=rhs.height_;
|
||||||
srid_=rhs.srid_;
|
srid_=rhs.srid_;
|
||||||
background_=rhs.background_;
|
background_=rhs.background_;
|
||||||
|
styles_=rhs.styles_;
|
||||||
layers_=rhs.layers_;
|
layers_=rhs.layers_;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Map::insert_style(std::string const& name,feature_type_style const& style)
|
||||||
|
{
|
||||||
|
return styles_.insert(make_pair(name,style)).second;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::remove_style(std::string const& name)
|
||||||
|
{
|
||||||
|
styles_.erase(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
feature_type_style Map::find_style(std::string const& name) const
|
||||||
|
{
|
||||||
|
std::map<std::string,feature_type_style>::const_iterator itr=styles_.find(name);
|
||||||
|
if (itr!=styles_.end())
|
||||||
|
return itr->second;
|
||||||
|
return feature_type_style();
|
||||||
|
}
|
||||||
|
|
||||||
size_t Map::layerCount() const
|
size_t Map::layerCount() const
|
||||||
{
|
{
|
||||||
return layers_.size();
|
return layers_.size();
|
||||||
|
@ -67,10 +87,7 @@ namespace mapnik
|
||||||
{
|
{
|
||||||
layers_.erase(layers_.begin()+index);
|
layers_.erase(layers_.begin()+index);
|
||||||
}
|
}
|
||||||
void Map::removeLayer(const char* lName)
|
|
||||||
{
|
|
||||||
//todo
|
|
||||||
}
|
|
||||||
const Layer& Map::getLayer(size_t index) const
|
const Layer& Map::getLayer(size_t index) const
|
||||||
{
|
{
|
||||||
return layers_[index];
|
return layers_[index];
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
/* This file is part of Mapnik (c++ mapping toolkit)
|
|
||||||
* Copyright (C) 2005 Artem Pavlenko
|
|
||||||
*
|
|
||||||
* Mapnik is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//$Id: style_cache.cpp 37 2005-04-07 17:09:38Z pavlenko $
|
|
||||||
|
|
||||||
#include "named_style_cache.hpp"
|
|
||||||
#include <boost/thread/mutex.hpp>
|
|
||||||
|
|
||||||
namespace mapnik
|
|
||||||
{
|
|
||||||
named_style_cache::named_style_cache() {}
|
|
||||||
named_style_cache::~named_style_cache() {}
|
|
||||||
|
|
||||||
std::map<std::string,feature_type_style> named_style_cache::styles_;
|
|
||||||
|
|
||||||
bool named_style_cache::insert(const std::string& name,const feature_type_style& style)
|
|
||||||
{
|
|
||||||
mutex::scoped_lock lock(mutex_);
|
|
||||||
return styles_.insert(make_pair(name,style)).second;
|
|
||||||
}
|
|
||||||
|
|
||||||
void named_style_cache::remove(const std::string& name)
|
|
||||||
{
|
|
||||||
mutex::scoped_lock lock(mutex_);
|
|
||||||
styles_.erase(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
feature_type_style named_style_cache::find(const std::string& name)
|
|
||||||
{
|
|
||||||
mutex::scoped_lock lock(mutex_);
|
|
||||||
std::map<std::string,feature_type_style>::iterator itr=styles_.find(name);
|
|
||||||
if (itr!=styles_.end())
|
|
||||||
{
|
|
||||||
return itr->second;
|
|
||||||
}
|
|
||||||
return feature_type_style();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -21,7 +21,6 @@
|
||||||
#include "render.hpp"
|
#include "render.hpp"
|
||||||
#include "image_util.hpp"
|
#include "image_util.hpp"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
#include "named_style_cache.hpp"
|
|
||||||
#include "symbolizer.hpp"
|
#include "symbolizer.hpp"
|
||||||
#include "query.hpp"
|
#include "query.hpp"
|
||||||
#include "feature_layer_desc.hpp"
|
#include "feature_layer_desc.hpp"
|
||||||
|
@ -36,7 +35,7 @@ namespace mapnik
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename Image>
|
template <typename Image>
|
||||||
void Renderer<Image>::render_vector_layer(datasource_p const& ds,
|
void Renderer<Image>::render_vector_layer(datasource_p const& ds,Map const& map,
|
||||||
std::vector<std::string> const& namedStyles,
|
std::vector<std::string> const& namedStyles,
|
||||||
unsigned width,unsigned height,
|
unsigned width,unsigned height,
|
||||||
const Envelope<double>& bbox,Image& image)
|
const Envelope<double>& bbox,Image& image)
|
||||||
|
@ -45,7 +44,7 @@ namespace mapnik
|
||||||
std::vector<std::string>::const_iterator stylesIter=namedStyles.begin();
|
std::vector<std::string>::const_iterator stylesIter=namedStyles.begin();
|
||||||
while (stylesIter!=namedStyles.end())
|
while (stylesIter!=namedStyles.end())
|
||||||
{
|
{
|
||||||
feature_type_style style=named_style_cache::instance()->find(*stylesIter++);
|
//feature_type_style style=named_style_cache::instance()->find(*stylesIter++);
|
||||||
|
|
||||||
std::set<std::string> names;
|
std::set<std::string> names;
|
||||||
attribute_collector<Feature> collector(names);
|
attribute_collector<Feature> collector(names);
|
||||||
|
@ -56,6 +55,9 @@ namespace mapnik
|
||||||
std::vector<rule_type*> else_rules;
|
std::vector<rule_type*> else_rules;
|
||||||
|
|
||||||
bool active_rules=false;
|
bool active_rules=false;
|
||||||
|
|
||||||
|
feature_type_style style=map.find_style(*stylesIter++);
|
||||||
|
|
||||||
const std::vector<rule_type>& rules=style.get_rules();
|
const std::vector<rule_type>& rules=style.get_rules();
|
||||||
std::vector<rule_type>::const_iterator ruleIter=rules.begin();
|
std::vector<rule_type>::const_iterator ruleIter=rules.begin();
|
||||||
|
|
||||||
|
@ -182,7 +184,7 @@ namespace mapnik
|
||||||
if (!ds) continue;
|
if (!ds) continue;
|
||||||
if (ds->type() == datasource::Vector)
|
if (ds->type() == datasource::Vector)
|
||||||
{
|
{
|
||||||
render_vector_layer(ds,l.styles(),width,height,extent,image);
|
render_vector_layer(ds,map,l.styles(),width,height,extent,image);
|
||||||
}
|
}
|
||||||
else if (ds->type() == datasource::Raster)
|
else if (ds->type() == datasource::Raster)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue