diff --git a/include/mapnik/feature_style_processor_impl.hpp b/include/mapnik/feature_style_processor_impl.hpp index 144e8d86e..3de36ad75 100644 --- a/include/mapnik/feature_style_processor_impl.hpp +++ b/include/mapnik/feature_style_processor_impl.hpp @@ -257,16 +257,11 @@ void feature_style_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(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 query_ext = extent; // unbuffered box2d buffered_query_ext(query_ext); // buffered @@ -508,17 +503,11 @@ void feature_style_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(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(); diff --git a/include/mapnik/map.hpp b/include/mapnik/map.hpp index e3837ee9d..dabb8653d 100644 --- a/include/mapnik/map.hpp +++ b/include/mapnik/map.hpp @@ -105,7 +105,7 @@ private: boost::optional 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::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 const& layers() const; - /*! \brief Get all layers. - * @return Non-constant layers. - */ - std::vector & 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_; } diff --git a/src/map.cpp b/src/map.cpp index 22bd01f8f..8e943bbf1 100644 --- a/src/map.cpp +++ b/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(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(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 const& Map::layers() const { return layers_; } -std::vector & 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(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 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(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)) diff --git a/test/unit/renderer/feature_style_processor.cpp b/test/unit/renderer/feature_style_processor.cpp index 03b9b344d..ed125bf52 100644 --- a/test/unit/renderer/feature_style_processor.cpp +++ b/test/unit/renderer/feature_style_processor.cpp @@ -195,7 +195,7 @@ SECTION("test_renderer - apply() with single layer") { rendering_result result; test_renderer renderer(map, result); std::set 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 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,