From 2a858bcd192831889d8cced465909c1e65972430 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Sun, 5 Feb 2006 09:45:51 +0000 Subject: [PATCH] 1.removed named_style_cache 2.styles moved to Map object --- bindings/python/mapnik_map.cpp | 2 ++ bindings/python/mapnik_style.cpp | 16 ---------- include/map.hpp | 8 ++++- include/mapnik.hpp | 1 - include/named_style_cache.hpp | 47 ---------------------------- include/render.hpp | 2 +- src/SConscript | 1 - src/map.cpp | 39 ++++++++++++++++------- src/named_style_cache.cpp | 53 -------------------------------- src/render.cpp | 10 +++--- 10 files changed, 44 insertions(+), 135 deletions(-) delete mode 100644 include/named_style_cache.hpp delete mode 100644 src/named_style_cache.cpp diff --git a/bindings/python/mapnik_map.cpp b/bindings/python/mapnik_map.cpp index 48e4a16d2..10a87d8e3 100644 --- a/bindings/python/mapnik_map.cpp +++ b/bindings/python/mapnik_map.cpp @@ -91,6 +91,8 @@ void export_map() .def("pan",&Map::pan) .def("zoom",&Map::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 (&Map::layers,return_value_policy())) .def_pickle(map_pickle_suite()) diff --git a/bindings/python/mapnik_style.cpp b/bindings/python/mapnik_style.cpp index 6426d061f..79c5bd87d 100644 --- a/bindings/python/mapnik_style.cpp +++ b/bindings/python/mapnik_style.cpp @@ -23,9 +23,6 @@ #include "mapnik.hpp" using mapnik::feature_type_style; -using mapnik::named_style_cache; -using mapnik::singleton; -using mapnik::CreateStatic; using mapnik::rules; void export_style() @@ -40,18 +37,5 @@ void export_style() (&feature_type_style::get_rules,return_value_policy())) ; - class_,boost::noncopyable>("singleton",no_init) - .def("instance",&singleton::instance, - return_value_policy()) - .staticmethod("instance") - ; - - class_ >, - boost::noncopyable>("style_cache",no_init) - .def("insert",&named_style_cache::insert) - .staticmethod("insert") - .def("remove",&named_style_cache::remove) - .staticmethod("remove") - ; } diff --git a/include/map.hpp b/include/map.hpp index 6ef59e849..cfcd6af1a 100644 --- a/include/map.hpp +++ b/include/map.hpp @@ -23,6 +23,7 @@ #include #include +#include "feature_type_style.hpp" namespace mapnik { @@ -46,6 +47,7 @@ namespace mapnik unsigned height_; int srid_; Color background_; + std::map styles_; std::vector layers_; Envelope currentExtent_; public: @@ -53,11 +55,15 @@ namespace mapnik Map(int width,int height,int srid=-1); Map(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; void addLayer(const Layer& l); const Layer& getLayer(size_t index) const; void removeLayer(size_t index); - void removeLayer(const char* lName); std::vector const& layers() const; unsigned getWidth() const; unsigned getHeight() const; diff --git a/include/mapnik.hpp b/include/mapnik.hpp index c46c922a0..31b63418d 100644 --- a/include/mapnik.hpp +++ b/include/mapnik.hpp @@ -56,7 +56,6 @@ #include "wkb.hpp" #include "map.hpp" #include "feature_type_style.hpp" -#include "named_style_cache.hpp" #include "feature_factory.hpp" #include "math_expr.hpp" #include "value.hpp" diff --git a/include/named_style_cache.hpp b/include/named_style_cache.hpp deleted file mode 100644 index d290bc093..000000000 --- a/include/named_style_cache.hpp +++ /dev/null @@ -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 -#include "feature_type_style.hpp" - -namespace mapnik { - - class named_style_cache : public singleton - { - friend class CreateStatic; - private: - static std::map 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 diff --git a/include/render.hpp b/include/render.hpp index a4c025ac9..b21e1605a 100644 --- a/include/render.hpp +++ b/include/render.hpp @@ -36,7 +36,7 @@ namespace mapnik static void render(const Map& map,Image& image); private: Renderer(); - static void render_vector_layer(datasource_p const& ds, + static void render_vector_layer(datasource_p const& ds,Map const& map, std::vector const& , unsigned width, unsigned height, diff --git a/src/SConscript b/src/SConscript index fb4cdfc15..4a704e59c 100644 --- a/src/SConscript +++ b/src/SConscript @@ -41,7 +41,6 @@ source = Split( plugin.cpp png_reader.cpp render.cpp - named_style_cache.cpp text.cpp tiff_reader.cpp wkb.cpp diff --git a/src/map.cpp b/src/map.cpp index a5f48a351..2e24a27ce 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -37,12 +37,13 @@ namespace mapnik Map::Map(const Map& rhs) : width_(rhs.width_), - height_(rhs.height_), - srid_(rhs.srid_), - background_(rhs.background_), - layers_(rhs.layers_), - currentExtent_(rhs.currentExtent_) {} - + height_(rhs.height_), + srid_(rhs.srid_), + background_(rhs.background_), + styles_(rhs.styles_), + layers_(rhs.layers_), + currentExtent_(rhs.currentExtent_) {} + Map& Map::operator=(const Map& rhs) { if (this==&rhs) return *this; @@ -50,15 +51,34 @@ namespace mapnik height_=rhs.height_; srid_=rhs.srid_; background_=rhs.background_; + styles_=rhs.styles_; layers_=rhs.layers_; 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::const_iterator itr=styles_.find(name); + if (itr!=styles_.end()) + return itr->second; + return feature_type_style(); + } + size_t Map::layerCount() const { return layers_.size(); } - + void Map::addLayer(const Layer& l) { layers_.push_back(l); @@ -67,10 +87,7 @@ namespace mapnik { layers_.erase(layers_.begin()+index); } - void Map::removeLayer(const char* lName) - { - //todo - } + const Layer& Map::getLayer(size_t index) const { return layers_[index]; diff --git a/src/named_style_cache.cpp b/src/named_style_cache.cpp deleted file mode 100644 index 7e1e46da6..000000000 --- a/src/named_style_cache.cpp +++ /dev/null @@ -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 - -namespace mapnik -{ - named_style_cache::named_style_cache() {} - named_style_cache::~named_style_cache() {} - - std::map 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::iterator itr=styles_.find(name); - if (itr!=styles_.end()) - { - return itr->second; - } - return feature_type_style(); - } -} diff --git a/src/render.cpp b/src/render.cpp index 0b81adaa5..927d0943b 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -21,7 +21,6 @@ #include "render.hpp" #include "image_util.hpp" #include "utils.hpp" -#include "named_style_cache.hpp" #include "symbolizer.hpp" #include "query.hpp" #include "feature_layer_desc.hpp" @@ -36,7 +35,7 @@ namespace mapnik { template - void Renderer::render_vector_layer(datasource_p const& ds, + void Renderer::render_vector_layer(datasource_p const& ds,Map const& map, std::vector const& namedStyles, unsigned width,unsigned height, const Envelope& bbox,Image& image) @@ -45,7 +44,7 @@ namespace mapnik std::vector::const_iterator stylesIter=namedStyles.begin(); 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 names; attribute_collector collector(names); @@ -56,6 +55,9 @@ namespace mapnik std::vector else_rules; bool active_rules=false; + + feature_type_style style=map.find_style(*stylesIter++); + const std::vector& rules=style.get_rules(); std::vector::const_iterator ruleIter=rules.begin(); @@ -182,7 +184,7 @@ namespace mapnik if (!ds) continue; 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) {