diff options
author | zmiao <zmiao.jamie@gmail.com> | 2019-08-12 16:59:29 +0300 |
---|---|---|
committer | zmiao <zmiao.jamie@gmail.com> | 2019-08-12 16:59:29 +0300 |
commit | 48b4846f18f46e37c10bd3c88d73fe4b5d2e66d3 (patch) | |
tree | 31c60ad1ec7e21081f2df5498dcc12759a27bbdb | |
parent | 3f2bec649856f123bb93e818c0546037a55b671b (diff) | |
download | qtlocation-mapboxgl-48b4846f18f46e37c10bd3c88d73fe4b5d2e66d3.tar.gz |
update geojson_option conversion
-rw-r--r-- | src/mbgl/style/conversion/geojson_options.cpp | 31 | ||||
-rw-r--r-- | test/style/conversion/geojson_options.test.cpp | 2 |
2 files changed, 20 insertions, 13 deletions
diff --git a/src/mbgl/style/conversion/geojson_options.cpp b/src/mbgl/style/conversion/geojson_options.cpp index a7cb2239e7..7be6ae6e5f 100644 --- a/src/mbgl/style/conversion/geojson_options.cpp +++ b/src/mbgl/style/conversion/geojson_options.cpp @@ -104,23 +104,30 @@ optional<GeoJSONOptions> Converter<GeoJSONOptions>::operator()(const Convertible [&](const std::string& k, const mbgl::style::conversion::Convertible& v) -> optional<conversion::Error> { // Each property shall be formed as ["key" : [operator, [mapExpression]]] + // or ["key" : [[operator, ['accumulated'], ['get', key]], [mapExpression]]] if (!isArray(v) || arrayLength(v) != 2) { error.message = - "GeoJSON source clusterProperties member must be an array with length of 2"; - return {}; - } - auto reduceOp = toString(arrayMember(v, 0)); - if (!reduceOp) { - error.message = - "GeoJSON source clusterProperties member must contain a valid operator"; + "GeoJSON source clusterProperties member must be an array with length of 2"; return {}; } auto map = expression::dsl::createExpression(arrayMember(v, 1)); - std::stringstream ss; - // 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()); + std::unique_ptr<expression::Expression> reduce; + if(isArray(arrayMember(v, 0))){ + reduce = expression::dsl::createExpression(arrayMember(v, 0)); + } + else{ + auto reduceOp = toString(arrayMember(v, 0)); + if (!reduceOp) { + error.message = + "GeoJSON source clusterProperties member must contain a valid operator"; + return {}; + } + std::stringstream ss; + // Reformulate reduce expression to [operator, ['accumulated'], ['get', key]] + ss << std::string(R"([")") << *reduceOp + << std::string(R"(", ["accumulated"], ["get", ")") << k << std::string(R"("]])"); + reduce = expression::dsl::createExpression(ss.str().c_str()); + } if (map && reduce) { result.emplace(k, std::make_pair(std::move(map), std::move(reduce))); } else { diff --git a/test/style/conversion/geojson_options.test.cpp b/test/style/conversion/geojson_options.test.cpp index b50707bbe6..aa84686dce 100644 --- a/test/style/conversion/geojson_options.test.cpp +++ b/test/style/conversion/geojson_options.test.cpp @@ -53,7 +53,7 @@ TEST(GeoJSONOptions, FullConversion) { "lineMetrics": true, "clusterProperties": { "max": ["max", ["get", "scalerank"]], - "sum": ["+", ["get", "scalerank"]], + "sum": [["+", ["accumulated"], ["get", "sum"]], ["get", "scalerank"]], "has_island": ["any", ["==", ["get", "featureclass"], "island"]] } })JSON", error); |