Move proj_transform initialisation to add_layer
method
This commit is contained in:
parent
e5c182591a
commit
cb75f00780
4 changed files with 38 additions and 63 deletions
|
@ -257,16 +257,11 @@ void feature_style_processor<Processor>::prepare_layer(layer_rendering_material
|
|||
processor_context_ptr current_ctx = ds->get_context(ctx_map);
|
||||
std::string key = mat.proj0_.params() + mat.proj1_.params();
|
||||
auto itr = m_.proj_cache().find(key);
|
||||
proj_transform * proj_trans_ptr;
|
||||
if (itr == m_.proj_cache().end())
|
||||
{
|
||||
proj_trans_ptr = m_.proj_cache().emplace(key,
|
||||
std::make_unique<proj_transform>(mat.proj0_, mat.proj1_)).first->second.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
proj_trans_ptr = itr->second.get();
|
||||
throw std::runtime_error("Failed to initialise projection transform");
|
||||
}
|
||||
proj_transform * proj_trans_ptr = itr->second.get();
|
||||
box2d<double> query_ext = extent; // unbuffered
|
||||
box2d<double> buffered_query_ext(query_ext); // buffered
|
||||
|
||||
|
@ -508,17 +503,11 @@ void feature_style_processor<Processor>::render_material(layer_rendering_materia
|
|||
|
||||
std::string key = mat.proj0_.params() + mat.proj1_.params();
|
||||
auto itr = m_.proj_cache().find(key);
|
||||
proj_transform * proj_trans_ptr;
|
||||
if (itr == m_.proj_cache().end())
|
||||
{
|
||||
proj_trans_ptr = m_.proj_cache().emplace(key,
|
||||
std::make_unique<proj_transform>(mat.proj0_, mat.proj1_)).first->second.get();
|
||||
throw std::runtime_error("Failed to initialize projection transform");
|
||||
}
|
||||
else
|
||||
{
|
||||
proj_trans_ptr = itr->second.get();
|
||||
}
|
||||
|
||||
proj_transform* proj_trans_ptr = itr->second.get();
|
||||
bool cache_features = lay.cache_features() && active_styles.size() > 1;
|
||||
|
||||
datasource_ptr ds = lay.datasource();
|
||||
|
|
|
@ -105,7 +105,7 @@ private:
|
|||
boost::optional<std::string> font_directory_;
|
||||
freetype_engine::font_file_mapping_type font_file_mapping_;
|
||||
freetype_engine::font_memory_cache_type font_memory_cache_;
|
||||
mutable proj_cache_type proj_cache_;
|
||||
proj_cache_type proj_cache_;
|
||||
public:
|
||||
|
||||
using const_style_iterator = std::map<std::string,feature_type_style>::const_iterator;
|
||||
|
@ -261,12 +261,6 @@ public:
|
|||
*/
|
||||
layer const& get_layer(size_t index) const;
|
||||
|
||||
/*! \brief Get a layer.
|
||||
* @param index layer number.
|
||||
* @return Non-constant layer.
|
||||
*/
|
||||
layer& get_layer(size_t index);
|
||||
|
||||
/*! \brief Remove a layer.
|
||||
* @param index layer number.
|
||||
*/
|
||||
|
@ -277,11 +271,6 @@ public:
|
|||
*/
|
||||
std::vector<layer> const& layers() const;
|
||||
|
||||
/*! \brief Get all layers.
|
||||
* @return Non-constant layers.
|
||||
*/
|
||||
std::vector<layer> & layers();
|
||||
|
||||
/*! \brief Remove all layers and styles from the map.
|
||||
*/
|
||||
void remove_all();
|
||||
|
@ -503,7 +492,7 @@ public:
|
|||
{
|
||||
return font_memory_cache_;
|
||||
}
|
||||
proj_cache_type& proj_cache() const
|
||||
proj_cache_type const& proj_cache() const
|
||||
{
|
||||
return proj_cache_;
|
||||
}
|
||||
|
|
63
src/map.cpp
63
src/map.cpp
|
@ -110,8 +110,9 @@ Map::Map(Map const& rhs)
|
|||
extra_params_(rhs.extra_params_),
|
||||
font_directory_(rhs.font_directory_),
|
||||
font_file_mapping_(rhs.font_file_mapping_),
|
||||
// on copy discard memory cache
|
||||
font_memory_cache_() {}
|
||||
// on copy discard memory caches
|
||||
font_memory_cache_(),
|
||||
proj_cache_() {}
|
||||
|
||||
|
||||
Map::Map(Map && rhs)
|
||||
|
@ -133,7 +134,8 @@ Map::Map(Map && rhs)
|
|||
extra_params_(std::move(rhs.extra_params_)),
|
||||
font_directory_(std::move(rhs.font_directory_)),
|
||||
font_file_mapping_(std::move(rhs.font_file_mapping_)),
|
||||
font_memory_cache_(std::move(rhs.font_memory_cache_)) {}
|
||||
font_memory_cache_(std::move(rhs.font_memory_cache_)),
|
||||
proj_cache_(std::move(rhs.proj_cache_)) {}
|
||||
|
||||
Map::~Map() {}
|
||||
|
||||
|
@ -164,7 +166,7 @@ void swap (Map & lhs, Map & rhs)
|
|||
std::swap(lhs.extra_params_, rhs.extra_params_);
|
||||
std::swap(lhs.font_directory_,rhs.font_directory_);
|
||||
std::swap(lhs.font_file_mapping_,rhs.font_file_mapping_);
|
||||
// on assignment discard memory cache
|
||||
// on assignment discard memory caches
|
||||
//std::swap(lhs.font_memory_cache_,rhs.font_memory_cache_);
|
||||
}
|
||||
|
||||
|
@ -323,11 +325,29 @@ size_t Map::layer_count() const
|
|||
|
||||
void Map::add_layer(layer const& l)
|
||||
{
|
||||
std::string key = srs_ + l.srs();
|
||||
auto itr = proj_cache_.find(key);
|
||||
if (itr == proj_cache_.end())
|
||||
{
|
||||
mapnik::projection source(srs_, true);
|
||||
mapnik::projection dest(l.srs(), true);
|
||||
proj_cache_.emplace(key,
|
||||
std::make_unique<proj_transform>(source, dest));
|
||||
}
|
||||
layers_.emplace_back(l);
|
||||
}
|
||||
|
||||
void Map::add_layer(layer && l)
|
||||
{
|
||||
std::string key = srs_ + l.srs();
|
||||
auto itr = proj_cache_.find(key);
|
||||
if (itr == proj_cache_.end())
|
||||
{
|
||||
mapnik::projection source(srs_, true);
|
||||
mapnik::projection dest(l.srs(), true);
|
||||
proj_cache_.emplace(key,
|
||||
std::make_unique<proj_transform>(source, dest));
|
||||
}
|
||||
layers_.push_back(std::move(l));
|
||||
}
|
||||
|
||||
|
@ -350,21 +370,11 @@ layer const& Map::get_layer(size_t index) const
|
|||
return layers_[index];
|
||||
}
|
||||
|
||||
layer& Map::get_layer(size_t index)
|
||||
{
|
||||
return layers_[index];
|
||||
}
|
||||
|
||||
std::vector<layer> const& Map::layers() const
|
||||
{
|
||||
return layers_;
|
||||
}
|
||||
|
||||
std::vector<layer> & Map::layers()
|
||||
{
|
||||
return layers_;
|
||||
}
|
||||
|
||||
unsigned Map::width() const
|
||||
{
|
||||
return width_;
|
||||
|
@ -528,19 +538,12 @@ void Map::zoom_all()
|
|||
|
||||
std::string key = srs_ + layer_srs;
|
||||
auto itr = proj_cache_.find(key);
|
||||
proj_transform * proj_trans_ptr;
|
||||
|
||||
if (itr == proj_cache_.end())
|
||||
{
|
||||
projection proj0(srs_, true);
|
||||
projection proj1(layer_srs, true);
|
||||
proj_trans_ptr = proj_cache_.emplace(key,
|
||||
std::make_unique<proj_transform>(proj0, proj1)).first->second.get();
|
||||
throw std::runtime_error("Failed to initialise projection transform");
|
||||
}
|
||||
else
|
||||
{
|
||||
proj_trans_ptr = itr->second.get();
|
||||
}
|
||||
|
||||
proj_transform* proj_trans_ptr = itr->second.get();
|
||||
box2d<double> layer_ext = layer.envelope();
|
||||
if (proj_trans_ptr->backward(layer_ext, PROJ_ENVELOPE_POINTS))
|
||||
{
|
||||
|
@ -722,18 +725,12 @@ featureset_ptr Map::query_point(unsigned index, double x, double y) const
|
|||
{
|
||||
std::string key = srs_ + layer.srs();
|
||||
auto itr = proj_cache_.find(key);
|
||||
proj_transform * proj_trans_ptr;
|
||||
|
||||
if (itr == proj_cache_.end())
|
||||
{
|
||||
mapnik::projection dest(srs_, true);
|
||||
mapnik::projection source(layer.srs(), true);
|
||||
proj_trans_ptr = proj_cache_.emplace(key,
|
||||
std::make_unique<proj_transform>(source, dest)).first->second.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
proj_trans_ptr = itr->second.get();
|
||||
throw std::runtime_error("Failed to initialise projection transform");
|
||||
}
|
||||
proj_transform * proj_trans_ptr = itr->second.get();
|
||||
|
||||
double z = 0;
|
||||
if (!proj_trans_ptr->equal() && !proj_trans_ptr->backward(x,y,z))
|
||||
|
|
|
@ -195,7 +195,7 @@ SECTION("test_renderer - apply() with single layer") {
|
|||
rendering_result result;
|
||||
test_renderer renderer(map, result);
|
||||
std::set<std::string> attributes;
|
||||
mapnik::layer & layer = map.get_layer(0);
|
||||
mapnik::layer const& layer = map.get_layer(0);
|
||||
renderer.apply(layer, attributes);
|
||||
|
||||
REQUIRE(renderer.painted());
|
||||
|
@ -222,7 +222,7 @@ SECTION("test_renderer - apply_to_layer") {
|
|||
test_renderer renderer(map, result);
|
||||
std::set<std::string> attributes;
|
||||
mapnik::projection map_proj(map.srs(), true);
|
||||
mapnik::layer & layer = map.get_layer(0);
|
||||
mapnik::layer const& layer = map.get_layer(0);
|
||||
renderer.apply_to_layer(layer,
|
||||
renderer,
|
||||
map_proj,
|
||||
|
|
Loading…
Reference in a new issue