Created
September 7, 2011 07:55
-
-
Save rundel/1200005 to your computer and use it in GitHub Desktop.
Mapnik patches - bugfix and deep copy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/include/mapnik/feature_type_style.hpp b/include/mapnik/feature_type_style.hpp | |
index d4a4287..0a54dfe 100644 | |
--- a/include/mapnik/feature_type_style.hpp | |
+++ b/include/mapnik/feature_type_style.hpp | |
@@ -51,7 +51,7 @@ private: | |
public: | |
feature_type_style(); | |
- feature_type_style(feature_type_style const& rhs); | |
+ feature_type_style(feature_type_style const& rhs, bool deep_copy = false); | |
feature_type_style& operator=(feature_type_style const& rhs); | |
diff --git a/include/mapnik/rule.hpp b/include/mapnik/rule.hpp | |
index a5f111a..b4a5e3f 100644 | |
--- a/include/mapnik/rule.hpp | |
+++ b/include/mapnik/rule.hpp | |
@@ -36,6 +36,7 @@ | |
#include <mapnik/glyph_symbolizer.hpp> | |
#include <mapnik/feature.hpp> | |
#include <mapnik/filter_factory.hpp> | |
+#include <mapnik/expression_string.hpp> | |
// boost | |
#include <boost/shared_ptr.hpp> | |
@@ -164,7 +165,7 @@ public: | |
else_filter_(false), | |
also_filter_(false) {} | |
- rule(const rule& rhs) | |
+ rule(const rule& rhs, bool deep_copy = false) | |
: name_(rhs.name_), | |
title_(rhs.title_), | |
abstract_(rhs.abstract_), | |
@@ -173,7 +174,54 @@ public: | |
syms_(rhs.syms_), | |
filter_(rhs.filter_), | |
else_filter_(rhs.else_filter_), | |
- also_filter_(rhs.also_filter_) {} | |
+ also_filter_(rhs.also_filter_) | |
+ { | |
+ if (deep_copy) { | |
+ //std::string expr = to_expression_string(rhs.filter_); | |
+ //filter_ = parse_expression(expr,"utf8"); | |
+ | |
+ symbolizers::iterator it = syms_.begin(), | |
+ end = syms_.end(); | |
+ | |
+ // FIXME - metawriter_ptr? | |
+ | |
+ for(; it != end; ++it) { | |
+ | |
+ /*if (polygon_symbolizer *sym = boost::get<polygon_symbolizer>(&(*it))) { | |
+ // no shared pointers | |
+ } else if (line_symbolizer *sym = boost::get<line_symbolizer>(&(*it))) { | |
+ // no shared pointers | |
+ } else if (building_symbolizer *sym = boost::get<building_symbolizer>(&(*it))) { | |
+ // no shared pointers | |
+ }*/ | |
+ | |
+ if (markers_symbolizer *sym = boost::get<markers_symbolizer>(&(*it))) { | |
+ copy_path_ptr(sym); | |
+ } else if (point_symbolizer *sym = boost::get<point_symbolizer>(&(*it))) { | |
+ copy_path_ptr(sym); | |
+ } else if (polygon_pattern_symbolizer *sym = boost::get<polygon_pattern_symbolizer>(&(*it))) { | |
+ copy_path_ptr(sym); | |
+ } else if (line_pattern_symbolizer *sym = boost::get<line_pattern_symbolizer>(&(*it))) { | |
+ copy_path_ptr(sym); | |
+ } else if (raster_symbolizer *sym = boost::get<raster_symbolizer>(&(*it))) { | |
+ raster_colorizer_ptr old_colorizer = sym->get_colorizer(), | |
+ new_colorizer = raster_colorizer_ptr(); | |
+ | |
+ new_colorizer->set_stops( old_colorizer->get_stops()); | |
+ new_colorizer->set_default_mode( old_colorizer->get_default_mode() ); | |
+ new_colorizer->set_default_color( old_colorizer->get_default_color() ); | |
+ new_colorizer->set_epsilon( old_colorizer->get_epsilon() ); | |
+ | |
+ sym->set_colorizer(new_colorizer); | |
+ } else if (shield_symbolizer *sym = boost::get<shield_symbolizer>(&(*it))) { | |
+ copy_path_ptr(sym); | |
+ copy_text_ptr(sym); | |
+ } else if (text_symbolizer *sym = boost::get<text_symbolizer>(&(*it))) { | |
+ copy_text_ptr(sym); | |
+ } | |
+ } | |
+ } | |
+ } | |
rule& operator=(rule const& rhs) | |
{ | |
@@ -323,6 +371,39 @@ private: | |
else_filter_=rhs.else_filter_; | |
also_filter_=rhs.also_filter_; | |
} | |
+ | |
+ template <class T> | |
+ void copy_path_ptr(T* sym) | |
+ { | |
+ std::string path = path_processor_type::to_string(*sym->get_filename()); | |
+ sym->set_filename( parse_path(path) ); | |
+ } | |
+ | |
+ template <class T> | |
+ void copy_text_ptr(T* sym) | |
+ { | |
+ std::string name = to_expression_string(*sym->get_name()); | |
+ sym->set_name( parse_expression(name) ); | |
+ | |
+ // FIXME - orientation doesn't appear to be initialized in constructor? | |
+ //std::string orientation = to_expression_string(*sym->get_orientation()); | |
+ //sym->set_orientation( parse_expression(orientation) ); | |
+ | |
+ unsigned text_size = sym->get_text_size(); | |
+ position displace = sym->get_displacement(); | |
+ vertical_alignment_e valign = sym->get_vertical_alignment(); | |
+ horizontal_alignment_e halign = sym->get_horizontal_alignment(); | |
+ justify_alignment_e jalign = sym->get_justify_alignment(); | |
+ | |
+ text_placements_ptr placements = text_placements_ptr(boost::make_shared<text_placements_dummy>()); | |
+ sym->set_placement_options( placements ); | |
+ | |
+ sym->set_text_size(text_size); | |
+ sym->set_displacement(displace); | |
+ sym->set_vertical_alignment(valign); | |
+ sym->set_horizontal_alignment(halign); | |
+ sym->set_justify_alignment(jalign); | |
+ } | |
}; | |
} | |
diff --git a/src/feature_type_style.cpp b/src/feature_type_style.cpp | |
index b4d1d59..b44a1b5 100644 | |
--- a/src/feature_type_style.cpp | |
+++ b/src/feature_type_style.cpp | |
@@ -37,9 +37,19 @@ IMPLEMENT_ENUM( filter_mode_e, filter_mode_strings ) | |
feature_type_style::feature_type_style() | |
: filter_mode_(FILTER_ALL) {} | |
-feature_type_style::feature_type_style(feature_type_style const& rhs) | |
- : rules_(rhs.rules_), | |
- filter_mode_(rhs.filter_mode_) {} | |
+feature_type_style::feature_type_style(feature_type_style const& rhs, bool deep_copy) | |
+ : filter_mode_(rhs.filter_mode_) | |
+{ | |
+ if (!deep_copy) { | |
+ rules_ = rhs.rules_; | |
+ } else { | |
+ rules::const_iterator it = rhs.rules_.begin(), | |
+ end = rhs.rules_.end(); | |
+ for(; it != end; ++it) { | |
+ rules_.push_back(rule(*it, deep_copy)); | |
+ } | |
+ } | |
+} | |
feature_type_style& feature_type_style::operator=(feature_type_style const& rhs) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/include/mapnik/text_symbolizer.hpp b/include/mapnik/text_symbolizer.hpp | |
index f3556cb..46f1211 100644 | |
--- a/include/mapnik/text_symbolizer.hpp | |
+++ b/include/mapnik/text_symbolizer.hpp | |
@@ -103,6 +103,7 @@ struct MAPNIK_DECL text_symbolizer : public symbolizer_base | |
void set_anchor(double x, double y); | |
position const& get_anchor() const; | |
void set_displacement(double x, double y); | |
+ void set_displacement(position const& p); | |
position const& get_displacement() const; | |
void set_avoid_edges(bool avoid); | |
bool get_avoid_edges() const; | |
diff --git a/src/text_symbolizer.cpp b/src/text_symbolizer.cpp | |
index dd6953d..f06ad03 100644 | |
--- a/src/text_symbolizer.cpp | |
+++ b/src/text_symbolizer.cpp | |
@@ -438,11 +438,16 @@ position const& text_symbolizer::get_anchor() const | |
return anchor_; | |
} | |
-void text_symbolizer::set_displacement(double x, double y) | |
+void text_symbolizer::set_displacement(double x, double y) | |
{ | |
placement_options_->set_default_displacement(boost::make_tuple(x,y)); | |
} | |
+void text_symbolizer::set_displacement(position const& p) | |
+{ | |
+ placement_options_->set_default_displacement(p); | |
+} | |
+ | |
position const& text_symbolizer::get_displacement() const | |
{ | |
return placement_options_->get_default_displacement(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/include/mapnik/raster_colorizer.hpp b/include/mapnik/raster_colorizer.hpp | |
index 7b09a76..c81b3aa 100644 | |
--- a/include/mapnik/raster_colorizer.hpp | |
+++ b/include/mapnik/raster_colorizer.hpp | |
@@ -169,6 +169,10 @@ public: | |
//! \return True if added, false if error | |
bool add_stop(const colorizer_stop & stop); | |
+ //! \brief Set the list of stops | |
+ //! \param[in] stops The list of stops | |
+ void set_stops(colorizer_stops const& stops) { stops_ = stops; }; | |
+ | |
//! \brief Get the list of stops | |
//! \return The list of stops | |
const colorizer_stops& get_stops(void) const {return stops_; }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment