From 26ea5f4351658a38de0e266640ae540c5fb30ea7 Mon Sep 17 00:00:00 2001 From: Constantin Shalnev Date: Wed, 7 Oct 2015 12:42:52 +0300 Subject: [PATCH] Added selector: envelope_area --- data/mapcss-dynamic.txt | 1 + indexer/drules_selector.cpp | 33 ++++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/data/mapcss-dynamic.txt b/data/mapcss-dynamic.txt index e06685ad1e..828f6c5048 100644 --- a/data/mapcss-dynamic.txt +++ b/data/mapcss-dynamic.txt @@ -1,2 +1,3 @@ population name +envelope_area diff --git a/indexer/drules_selector.cpp b/indexer/drules_selector.cpp index 3fb4d1ab09..f838223991 100644 --- a/indexer/drules_selector.cpp +++ b/indexer/drules_selector.cpp @@ -1,6 +1,7 @@ #include "indexer/drules_selector.hpp" #include "indexer/drules_selector_parser.hpp" #include "indexer/ftypes_matcher.hpp" +#include "indexer/scales.hpp" #include "base/assert.hpp" #include "base/logging.hpp" @@ -110,6 +111,18 @@ bool GetName(FeatureType const & ft, string & name) return true; } +// Feature tag value evaluator for tag 'envelope_area' (envelope area in sq.meters) +bool GetEnvelopeArea(FeatureType const & ft, double & sqM) +{ + if (feature::GEOM_AREA != ft.GetFeatureType()) + return false; + + m2::RectD const rect = ft.GetLimitRect(scales::GetUpperScale()); + + sqM = MercatorBounds::AreaOnEarth(rect.LeftTop(), rect.LeftBottom(), rect.RightBottom()) + + MercatorBounds::AreaOnEarth(rect.LeftTop(), rect.RightTop(), rect.RightBottom()); + return true; +} // Add new tag value evaluator here @@ -121,18 +134,17 @@ unique_ptr ParseSelector(string const & str) if (!ParseSelector(str, e)) { // bad string format - LOG(LDEBUG, ("Invalid selector format: ", str)); + LOG(LDEBUG, ("Invalid selector format:", str)); return unique_ptr(); } - // Tag 'population' if (e.m_tag == "population") { int value = 0; if (!e.m_value.empty() && (!strings::to_int(e.m_value, value) || value < 0)) { // bad string format - LOG(LDEBUG, ("Invalid selector: ", str)); + LOG(LDEBUG, ("Invalid selector:", str)); return unique_ptr(); } return make_unique>(&GetPopulation, e.m_operator, static_cast(value)); @@ -141,11 +153,22 @@ unique_ptr ParseSelector(string const & str) { return make_unique>(&GetName, e.m_operator, e.m_value); } + else if (e.m_tag == "envelope_area") + { + double value = 0; + if (!e.m_value.empty() && (!strings::to_double(e.m_value, value) || value < 0)) + { + // bad string format + LOG(LDEBUG, ("Invalid selector:", str)); + return unique_ptr(); + } + return make_unique>(&GetEnvelopeArea, e.m_operator, value); + } // Add new tag here // unrecognized selector - LOG(LDEBUG, ("Unrecognized selector: ", str)); + LOG(LDEBUG, ("Unrecognized selector:", str)); return unique_ptr(); } @@ -158,7 +181,7 @@ unique_ptr ParseSelector(vector const & strs) unique_ptr s = ParseSelector(str); if (nullptr == s) { - LOG(LDEBUG, ("Invalid composite selector: ", str)); + LOG(LDEBUG, ("Invalid composite selector:", str)); return unique_ptr(); } cs->Add(move(s));