summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzmiao <zmiao.jamie@gmail.com>2019-08-01 00:08:04 +0300
committerzmiao <zmiao.jamie@gmail.com>2019-08-01 00:08:04 +0300
commit701236add81a2925a695af149dd6e188985f53c8 (patch)
tree1f80133609482ed2df93406b1957f2908fde13e5
parent7f36cd2b5692d2ee861d080149ce2edd0a95de48 (diff)
downloadqtlocation-mapboxgl-701236add81a2925a695af149dd6e188985f53c8.tar.gz
refactory code
-rw-r--r--include/mbgl/style/expression/dsl.hpp4
-rw-r--r--include/mbgl/style/expression/expression.hpp4
-rw-r--r--include/mbgl/style/property_expression.hpp12
-rw-r--r--src/mbgl/style/conversion/geojson_options.cpp8
-rw-r--r--src/mbgl/style/expression/compound_expression.cpp2
-rw-r--r--src/mbgl/style/expression/expression.cpp17
-rw-r--r--src/mbgl/style/property_expression.cpp2
-rw-r--r--src/mbgl/style/sources/geojson_source_impl.cpp19
-rw-r--r--src/mbgl/style/sources/geojson_source_impl.hpp2
9 files changed, 32 insertions, 38 deletions
diff --git a/include/mbgl/style/expression/dsl.hpp b/include/mbgl/style/expression/dsl.hpp
index 9c117d4d9b..7aae02a05a 100644
--- a/include/mbgl/style/expression/dsl.hpp
+++ b/include/mbgl/style/expression/dsl.hpp
@@ -33,7 +33,8 @@ std::unique_ptr<Expression> literal(std::initializer_list<double> value);
std::unique_ptr<Expression> literal(std::initializer_list<const char*> value);
std::unique_ptr<Expression>
-assertion(type::Type, std::unique_ptr<Expression>, std::unique_ptr<Expression> def = nullptr);
+assertion(type::Type, std::unique_ptr<Expression>,
+ std::unique_ptr<Expression> def = nullptr);
std::unique_ptr<Expression> number(std::unique_ptr<Expression>,
std::unique_ptr<Expression> def = nullptr);
std::unique_ptr<Expression> string(std::unique_ptr<Expression>,
@@ -83,7 +84,6 @@ std::unique_ptr<Expression> interpolate(Interpolator interpolator,
double input3, std::unique_ptr<Expression> output3);
std::unique_ptr<Expression> concat(std::vector<std::unique_ptr<Expression>> inputs);
-
std::unique_ptr<Expression> format(const char* value);
std::unique_ptr<Expression> format(std::unique_ptr<Expression>);
diff --git a/include/mbgl/style/expression/expression.hpp b/include/mbgl/style/expression/expression.hpp
index 7168128b91..5094989d86 100644
--- a/include/mbgl/style/expression/expression.hpp
+++ b/include/mbgl/style/expression/expression.hpp
@@ -23,8 +23,7 @@ class EvaluationError {
public:
std::string message;
};
-
-
+
class EvaluationContext {
public:
EvaluationContext() = default;
@@ -49,7 +48,6 @@ public:
optional<mbgl::Value> accumulated;
GeometryTileFeature const * feature = nullptr;
optional<double> colorRampParameter;
-
// Contains formatted section object, std::unordered_map<std::string, Value>.
const Value* formattedSection = nullptr;
};
diff --git a/include/mbgl/style/property_expression.hpp b/include/mbgl/style/property_expression.hpp
index 5fbd402579..917cc1b47a 100644
--- a/include/mbgl/style/property_expression.hpp
+++ b/include/mbgl/style/property_expression.hpp
@@ -1,11 +1,10 @@
#pragma once
#include <mbgl/style/expression/expression.hpp>
-#include <mbgl/style/expression/find_zoom_curve.hpp>
-#include <mbgl/style/expression/interpolate.hpp>
#include <mbgl/style/expression/is_constant.hpp>
+#include <mbgl/style/expression/interpolate.hpp>
#include <mbgl/style/expression/step.hpp>
-#include <mbgl/util/range.hpp>
+#include <mbgl/style/expression/find_zoom_curve.hpp>
namespace mbgl {
namespace style {
@@ -34,8 +33,7 @@ template <class T>
class PropertyExpression final : public PropertyExpressionBase {
public:
// Second parameter to be used only for conversions from legacy functions.
- PropertyExpression(std::unique_ptr<expression::Expression> expression_,
- optional<T> defaultValue_ = nullopt)
+ PropertyExpression(std::unique_ptr<expression::Expression> expression_, optional<T> defaultValue_ = nullopt)
: PropertyExpressionBase(std::move(expression_)), defaultValue(std::move(defaultValue_)) {
}
T evaluate(const expression::EvaluationContext& context, T finalDefaultValue = T()) const {
@@ -52,7 +50,6 @@ public:
return evaluate(expression::EvaluationContext(zoom));
}
-
T evaluate(const GeometryTileFeature& feature, T finalDefaultValue) const {
return evaluate(expression::EvaluationContext(&feature), finalDefaultValue);
}
@@ -65,7 +62,8 @@ public:
return expression::fromExpressionValues<T>(expression->possibleOutputs());
}
- friend bool operator==(const PropertyExpression& lhs, const PropertyExpression& rhs) {
+ friend bool operator==(const PropertyExpression& lhs,
+ const PropertyExpression& rhs) {
return *lhs.expression == *rhs.expression;
}
diff --git a/src/mbgl/style/conversion/geojson_options.cpp b/src/mbgl/style/conversion/geojson_options.cpp
index 6bcc325da2..4591e2758b 100644
--- a/src/mbgl/style/conversion/geojson_options.cpp
+++ b/src/mbgl/style/conversion/geojson_options.cpp
@@ -2,14 +2,12 @@
#include <mbgl/style/conversion_impl.hpp>
#include <mbgl/style/expression/dsl.hpp>
#include <sstream>
-#include <utility>
namespace mbgl {
namespace style {
namespace conversion {
-optional<GeoJSONOptions> Converter<GeoJSONOptions>::operator()(const Convertible& value,
- Error& error) const {
+optional<GeoJSONOptions> Converter<GeoJSONOptions>::operator()(const Convertible& value, Error& error) const {
GeoJSONOptions options;
const auto minzoomValue = objectMember(value, "minzoom");
@@ -103,7 +101,7 @@ optional<GeoJSONOptions> Converter<GeoJSONOptions>::operator()(const Convertible
*clusterProperties,
[&](const std::string& k,
const mbgl::style::conversion::Convertible& v) -> optional<conversion::Error> {
- // "key" : [operator, [mapExpression]]
+ // Each property shall be formed as ["key" : [operator, [mapExpression]]]
if (!isArray(v) || arrayLength(v) != 2) {
error.message =
"GeoJSON source clusterProperties member must be an array with length of 2";
@@ -117,7 +115,7 @@ optional<GeoJSONOptions> Converter<GeoJSONOptions>::operator()(const Convertible
}
auto map = expression::dsl::createExpression(arrayMember(v, 1));
std::stringstream ss;
- // [operator, ['accumulated'], ['get', key]]
+ // Reformulate reduce expression to [operator, ['accumulated'], ['get', key]]
ss << std::string(R"([")") << *reduceOp
<< std::string(R"(", ["accumulated"], ["get", ")") << k << std::string(R"("]])");
auto reduce = expression::dsl::createExpression(ss.str().c_str());
diff --git a/src/mbgl/style/expression/compound_expression.cpp b/src/mbgl/style/expression/compound_expression.cpp
index 6958b1d625..4728e6fd6d 100644
--- a/src/mbgl/style/expression/compound_expression.cpp
+++ b/src/mbgl/style/expression/compound_expression.cpp
@@ -883,7 +883,7 @@ MAPBOX_ETERNAL_CONSTEXPR const auto compoundExpressionRegistry = mapbox::eternal
{ "zoom", zoomCompoundExpression },
{ "heatmap-density", heatmapDensityCompoundExpression },
{ "line-progress", lineProgressCompoundExpression },
- { "accumulated", accumulatedCompoundExpression},
+ { "accumulated", accumulatedCompoundExpression },
{ "has", hasContextCompoundExpression },
{ "has", hasObjectCompoundExpression },
{ "get", getContextCompoundExpression },
diff --git a/src/mbgl/style/expression/expression.cpp b/src/mbgl/style/expression/expression.cpp
index eedc706633..6bfda99064 100644
--- a/src/mbgl/style/expression/expression.cpp
+++ b/src/mbgl/style/expression/expression.cpp
@@ -5,13 +5,13 @@
namespace mbgl {
namespace style {
namespace expression {
-
+
class GeoJSONFeature : public GeometryTileFeature {
public:
const Feature& feature;
-
- GeoJSONFeature( const Feature& feature_) : feature(feature_) {}
-
+
+ GeoJSONFeature(const Feature& feature_) : feature(feature_) {}
+
FeatureType getType() const override {
return apply_visitor(ToFeatureType(), feature.geometry);
}
@@ -25,16 +25,15 @@ public:
return optional<mbgl::Value>();
}
};
-
-
+
EvaluationResult Expression::evaluate(optional<float> zoom, const Feature& feature, optional<double> colorRampParameter) const {
GeoJSONFeature f(feature);
- return this->evaluate(EvaluationContext(zoom, &f, colorRampParameter));
+ return this->evaluate(EvaluationContext(zoom, &f, colorRampParameter));
}
- EvaluationResult Expression::evaluate(optional<mbgl::Value> accumulated, const Feature& feature) const{
+EvaluationResult Expression::evaluate(optional<mbgl::Value> accumulated, const Feature& feature) const {
GeoJSONFeature f(feature);
- return this->evaluate(EvaluationContext(accumulated,&f));
+ return this->evaluate(EvaluationContext(accumulated, &f));
}
} // namespace expression
diff --git a/src/mbgl/style/property_expression.cpp b/src/mbgl/style/property_expression.cpp
index e438b4ee60..9ebecc4b40 100644
--- a/src/mbgl/style/property_expression.cpp
+++ b/src/mbgl/style/property_expression.cpp
@@ -9,7 +9,7 @@ PropertyExpressionBase::PropertyExpressionBase(std::unique_ptr<expression::Expre
isZoomConstant_ = expression::isZoomConstant(*expression);
isFeatureConstant_ = expression::isFeatureConstant(*expression);
}
-
+
bool PropertyExpressionBase::isZoomConstant() const noexcept {
return isZoomConstant_;
}
diff --git a/src/mbgl/style/sources/geojson_source_impl.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp
index ba26115957..b362496e29 100644
--- a/src/mbgl/style/sources/geojson_source_impl.cpp
+++ b/src/mbgl/style/sources/geojson_source_impl.cpp
@@ -4,8 +4,6 @@
#include <mbgl/util/string.hpp>
#include <mapbox/geojsonvt.hpp>
-#include <mbgl/style/conversion/json.hpp>
-#include <rapidjson/document.h>
#include <supercluster.hpp>
#include <cmath>
@@ -15,7 +13,8 @@ namespace style {
class GeoJSONVTData : public GeoJSONData {
public:
- GeoJSONVTData(const GeoJSON& geoJSON, const mapbox::geojsonvt::Options& options)
+ GeoJSONVTData(const GeoJSON& geoJSON,
+ const mapbox::geojsonvt::Options& options)
: impl(geoJSON, options) {
}
@@ -28,7 +27,9 @@ public:
}
mapbox::feature::feature_collection<double>
- getLeaves(const std::uint32_t, const std::uint32_t, const std::uint32_t) final {
+ getLeaves(const std::uint32_t,
+ const std::uint32_t,
+ const std::uint32_t) final {
return {};
}
@@ -44,8 +45,7 @@ class SuperclusterData : public GeoJSONData {
public:
SuperclusterData(const mapbox::feature::feature_collection<double>& features,
const mapbox::supercluster::Options& options)
- : impl(features, options) {
- }
+ : impl(features, options) {}
mapbox::feature::feature_collection<int16_t> getTile(const CanonicalTileID& tileID) final {
return impl.getTile(tileID.z, tileID.x, tileID.y);
@@ -96,7 +96,6 @@ GeoJSONSource::Impl::Impl(const Impl& other, const GeoJSON& geoJSON) : Source::I
clusterOptions.maxZoom = options.clusterMaxZoom;
clusterOptions.extent = util::EXTENT;
clusterOptions.radius = ::round(scale * options.clusterRadius);
-
clusterOptions.map =
[&](const mapbox::feature::property_map& properties) -> mapbox::feature::property_map {
mapbox::feature::property_map ret{};
@@ -110,11 +109,13 @@ GeoJSONSource::Impl::Impl(const Impl& other, const GeoJSON& geoJSON) : Source::I
clusterOptions.reduce = [&](mapbox::feature::property_map& toReturn,
const mapbox::feature::property_map& toFill) {
for (const auto& p : options.clusterProperties) {
+ if(toFill.count(p.first) == 0){
+ continue;
+ }
auto feature = mapbox::feature::feature<double>();
feature.properties = toFill;
optional<mapbox::feature::value> accumulated(toReturn[p.first]);
- toReturn[p.first] = EvaluateFeature<mapbox::feature::value>(accumulated, feature, p.second.second);
-
+ toReturn[p.first] = EvaluateFeature<mapbox::feature::value>(accumulated, feature, p.second.second);
}
};
data = std::make_shared<SuperclusterData>(
diff --git a/src/mbgl/style/sources/geojson_source_impl.hpp b/src/mbgl/style/sources/geojson_source_impl.hpp
index 50528a01d1..26b9d95a39 100644
--- a/src/mbgl/style/sources/geojson_source_impl.hpp
+++ b/src/mbgl/style/sources/geojson_source_impl.hpp
@@ -29,7 +29,7 @@ public:
Impl(std::string id, optional<GeoJSONOptions>);
Impl(const GeoJSONSource::Impl&, const GeoJSON&);
~Impl() final;
-
+
Range<uint8_t> getZoomRange() const;
std::weak_ptr<GeoJSONData> getData() const;