Skip to content

Instantly share code, notes, and snippets.

@springmeyer
Created March 1, 2011 16:35
Show Gist options
  • Save springmeyer/849405 to your computer and use it in GitHub Desktop.
Save springmeyer/849405 to your computer and use it in GitHub Desktop.
Index: include/mapnik/layer.hpp
===================================================================
--- include/mapnik/layer.hpp (revision 2628)
+++ include/mapnik/layer.hpp (working copy)
@@ -170,8 +170,18 @@
* @return whether this layer's labels are cached.
*/
bool clear_label_cache() const;
+
+ /*!
+ * @param clear_cache Set whether this layer's features should be cached if used by multiple styles.
+ */
+ void cache_features(bool cache_features);
/*!
+ * @return whether this layer's features will be cached if used by multiple styles
+ */
+ bool cache_features() const;
+
+ /*!
* @brief Attach a datasource for this layer.
*
* @param ds The datasource to attach.
@@ -202,6 +212,7 @@
bool active_;
bool queryable_;
bool clear_label_cache_;
+ bool cache_features_;
std::vector<std::string> styles_;
datasource_ptr ds_;
};
Index: src/load_map.cpp
===================================================================
--- src/load_map.cpp (revision 2628)
+++ src/load_map.cpp (working copy)
@@ -550,7 +550,14 @@
lyr.set_clear_label_cache( * clear_cache );
}
+ optional<boolean> cache_features =
+ get_opt_attr<boolean>(lay, "cache-features");
+ if (cache_features)
+ {
+ lyr.cache_features( * cache_features );
+ }
+
ptree::const_iterator itr2 = lay.begin();
ptree::const_iterator end2 = lay.end();
Index: src/layer.cpp
===================================================================
--- src/layer.cpp (revision 2628)
+++ src/layer.cpp (working copy)
@@ -49,6 +49,7 @@
active_(true),
queryable_(false),
clear_label_cache_(false),
+ cache_features_(false),
ds_() {}
layer::layer(const layer& rhs)
@@ -61,6 +62,7 @@
active_(rhs.active_),
queryable_(rhs.queryable_),
clear_label_cache_(rhs.clear_label_cache_),
+ cache_features_(rhs.cache_features_),
styles_(rhs.styles_),
ds_(rhs.ds_) {}
@@ -87,6 +89,7 @@
active_=rhs.active_;
queryable_=rhs.queryable_;
clear_label_cache_ = rhs.clear_label_cache_;
+ cache_features_ = rhs.cache_features_;
styles_=rhs.styles_;
ds_=rhs.ds_;
}
@@ -218,4 +221,15 @@
{
return clear_label_cache_;
}
+
+void layer::cache_features(bool cache_features)
+{
+ cache_features_ = cache_features;
}
+
+bool layer::cache_features() const
+{
+ return cache_features_;
+}
+
+}
Index: include/mapnik/feature_style_processor.hpp
===================================================================
--- include/mapnik/feature_style_processor.hpp (revision 2628)
+++ include/mapnik/feature_style_processor.hpp (working copy)
@@ -238,7 +238,7 @@
}
memory_datasource cache;
- bool cache_features = style_names.size()>1?true:false;
+ bool cache_features = lay.cache_features() && style_names.size()>1?true:false;
bool first = true;
BOOST_FOREACH (feature_type_style * style, active_styles)
@@ -282,11 +282,13 @@
featureset_ptr fs;
if (first)
{
- first = false;
+ if (cache_features)
+ first = false;
fs = ds->features(q);
}
else
{
+ std::clog << "caching \n";
fs = cache.features(q);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment