diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-04-12 12:31:51 +0300 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2017-04-19 17:21:28 -0700 |
commit | 7ddca3b6116903bae9ecde1d49d29a8f1fedcec3 (patch) | |
tree | efbdeda27dca8238965f6b7e1c263938ebe800d0 /src/mbgl/style | |
parent | d752235ec790f8c2d4e646c32648253ec64a60c4 (diff) | |
download | qtlocation-mapboxgl-7ddca3b6116903bae9ecde1d49d29a8f1fedcec3.tar.gz |
[core] account for property functions in query rendered features
Diffstat (limited to 'src/mbgl/style')
-rw-r--r-- | src/mbgl/style/layer_impl.hpp | 6 | ||||
-rw-r--r-- | src/mbgl/style/layers/circle_layer_impl.cpp | 21 | ||||
-rw-r--r-- | src/mbgl/style/layers/circle_layer_impl.hpp | 12 | ||||
-rw-r--r-- | src/mbgl/style/layers/fill_layer_impl.cpp | 12 | ||||
-rw-r--r-- | src/mbgl/style/layers/fill_layer_impl.hpp | 12 | ||||
-rw-r--r-- | src/mbgl/style/layers/line_layer_impl.cpp | 31 | ||||
-rw-r--r-- | src/mbgl/style/layers/line_layer_impl.hpp | 14 | ||||
-rw-r--r-- | src/mbgl/style/possibly_evaluated_property_value.hpp | 15 | ||||
-rw-r--r-- | src/mbgl/style/style.cpp | 12 | ||||
-rw-r--r-- | src/mbgl/style/style.hpp | 2 |
10 files changed, 65 insertions, 72 deletions
diff --git a/src/mbgl/style/layer_impl.hpp b/src/mbgl/style/layer_impl.hpp index 9b2bfe4d2c..5179192c94 100644 --- a/src/mbgl/style/layer_impl.hpp +++ b/src/mbgl/style/layer_impl.hpp @@ -69,10 +69,10 @@ public: // Checks whether this layer can be rendered. bool needsRendering(float zoom) const; - virtual float getQueryRadius() const { return 0; } - virtual bool queryIntersectsGeometry( + virtual bool queryIntersectsFeature( const GeometryCoordinates&, - const GeometryCollection&, + const GeometryTileFeature&, + const float, const float, const float) const { return false; }; diff --git a/src/mbgl/style/layers/circle_layer_impl.cpp b/src/mbgl/style/layers/circle_layer_impl.cpp index ea1d4eeb65..2dde632f6e 100644 --- a/src/mbgl/style/layers/circle_layer_impl.cpp +++ b/src/mbgl/style/layers/circle_layer_impl.cpp @@ -29,25 +29,24 @@ std::unique_ptr<Bucket> CircleLayer::Impl::createBucket(const BucketParameters& return std::make_unique<CircleBucket>(parameters, layers); } -float CircleLayer::Impl::getQueryRadius() const { - const std::array<float, 2>& translate = paint.evaluated.get<CircleTranslate>(); - return paint.evaluated.get<CircleRadius>().constantOr(CircleRadius::defaultValue()) - + util::length(translate[0], translate[1]); -} - -bool CircleLayer::Impl::queryIntersectsGeometry( +bool CircleLayer::Impl::queryIntersectsFeature( const GeometryCoordinates& queryGeometry, - const GeometryCollection& geometry, + const GeometryTileFeature& feature, + const float zoom, const float bearing, const float pixelsToTileUnits) const { + // Translate query geometry auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( queryGeometry, paint.evaluated.get<CircleTranslate>(), paint.evaluated.get<CircleTranslateAnchor>(), bearing, pixelsToTileUnits); - auto circleRadius = paint.evaluated.get<CircleRadius>().constantOr(CircleRadius::defaultValue()) * pixelsToTileUnits; + // Evaluate function + auto circleRadius = paint.evaluated.get<CircleRadius>() + .evaluate(feature, zoom, CircleRadius::defaultValue()) + * pixelsToTileUnits; - return util::polygonIntersectsBufferedMultiPoint( - translatedQueryGeometry.value_or(queryGeometry), geometry, circleRadius); + // Test intersection + return util::polygonIntersectsBufferedMultiPoint(translatedQueryGeometry.value_or(queryGeometry), feature.getGeometries(), circleRadius); } } // namespace style diff --git a/src/mbgl/style/layers/circle_layer_impl.hpp b/src/mbgl/style/layers/circle_layer_impl.hpp index 0f9611d589..2e3f37e1f9 100644 --- a/src/mbgl/style/layers/circle_layer_impl.hpp +++ b/src/mbgl/style/layers/circle_layer_impl.hpp @@ -18,12 +18,12 @@ public: std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const override; - float getQueryRadius() const override; - bool queryIntersectsGeometry( - const GeometryCoordinates& queryGeometry, - const GeometryCollection& geometry, - const float bearing, - const float pixelsToTileUnits) const override; + bool queryIntersectsFeature( + const GeometryCoordinates&, + const GeometryTileFeature&, + const float, + const float, + const float) const override; CirclePaintProperties paint; }; diff --git a/src/mbgl/style/layers/fill_layer_impl.cpp b/src/mbgl/style/layers/fill_layer_impl.cpp index c7c89f8c20..19675ca9fb 100644 --- a/src/mbgl/style/layers/fill_layer_impl.cpp +++ b/src/mbgl/style/layers/fill_layer_impl.cpp @@ -39,21 +39,17 @@ std::unique_ptr<Bucket> FillLayer::Impl::createBucket(const BucketParameters& pa return std::make_unique<FillBucket>(parameters, layers); } -float FillLayer::Impl::getQueryRadius() const { - const std::array<float, 2>& translate = paint.evaluated.get<FillTranslate>(); - return util::length(translate[0], translate[1]); -} - -bool FillLayer::Impl::queryIntersectsGeometry( +bool FillLayer::Impl::queryIntersectsFeature( const GeometryCoordinates& queryGeometry, - const GeometryCollection& geometry, + const GeometryTileFeature& feature, + const float, const float bearing, const float pixelsToTileUnits) const { auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( queryGeometry, paint.evaluated.get<FillTranslate>(), paint.evaluated.get<FillTranslateAnchor>(), bearing, pixelsToTileUnits); - return util::polygonIntersectsMultiPolygon(translatedQueryGeometry.value_or(queryGeometry), geometry); + return util::polygonIntersectsMultiPolygon(translatedQueryGeometry.value_or(queryGeometry), feature.getGeometries()); } } // namespace style diff --git a/src/mbgl/style/layers/fill_layer_impl.hpp b/src/mbgl/style/layers/fill_layer_impl.hpp index bd25a8bebf..712cb0a6e0 100644 --- a/src/mbgl/style/layers/fill_layer_impl.hpp +++ b/src/mbgl/style/layers/fill_layer_impl.hpp @@ -18,12 +18,12 @@ public: std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const override; - float getQueryRadius() const override; - bool queryIntersectsGeometry( - const GeometryCoordinates& queryGeometry, - const GeometryCollection& geometry, - const float bearing, - const float pixelsToTileUnits) const override; + bool queryIntersectsFeature( + const GeometryCoordinates&, + const GeometryTileFeature&, + const float, + const float, + const float) const override; FillPaintProperties paint; }; diff --git a/src/mbgl/style/layers/line_layer_impl.cpp b/src/mbgl/style/layers/line_layer_impl.cpp index ef0131e3d5..d283292914 100644 --- a/src/mbgl/style/layers/line_layer_impl.cpp +++ b/src/mbgl/style/layers/line_layer_impl.cpp @@ -32,9 +32,10 @@ std::unique_ptr<Bucket> LineLayer::Impl::createBucket(const BucketParameters& pa return std::make_unique<LineBucket>(parameters, layers, layout); } -float LineLayer::Impl::getLineWidth() const { +float LineLayer::Impl::getLineWidth(const GeometryTileFeature& feature, const float zoom) const { float lineWidth = paint.evaluated.get<LineWidth>(); - float gapWidth = paint.evaluated.get<LineGapWidth>().constantOr(0); + float gapWidth = paint.evaluated.get<LineGapWidth>() + .evaluate(feature, zoom, LineGapWidth::defaultValue()); if (gapWidth) { return gapWidth + 2 * lineWidth; } else { @@ -72,29 +73,29 @@ optional<GeometryCollection> offsetLine(const GeometryCollection& rings, const d return newRings; } -float LineLayer::Impl::getQueryRadius() const { - const std::array<float, 2>& translate = paint.evaluated.get<LineTranslate>(); - auto offset = paint.evaluated.get<LineOffset>().constantOr(LineOffset::defaultValue()); - return getLineWidth() / 2.0 + std::abs(offset) + util::length(translate[0], translate[1]); -} - -bool LineLayer::Impl::queryIntersectsGeometry( +bool LineLayer::Impl::queryIntersectsFeature( const GeometryCoordinates& queryGeometry, - const GeometryCollection& geometry, + const GeometryTileFeature& feature, + const float zoom, const float bearing, const float pixelsToTileUnits) const { - const float halfWidth = getLineWidth() / 2.0 * pixelsToTileUnits; - + // Translate query geometry auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( queryGeometry, paint.evaluated.get<LineTranslate>(), paint.evaluated.get<LineTranslateAnchor>(), bearing, pixelsToTileUnits); - auto offset = paint.evaluated.get<LineOffset>().constantOr(LineOffset::defaultValue()); - auto offsetGeometry = offsetLine(geometry, offset * pixelsToTileUnits); + // Evaluate function + auto offset = paint.evaluated.get<LineOffset>().evaluate(feature, zoom, LineOffset::defaultValue()) * pixelsToTileUnits; + + // Apply offset to geometry + auto offsetGeometry = offsetLine(feature.getGeometries(), offset); + + // Test intersection + const float halfWidth = getLineWidth(feature, zoom) / 2.0 * pixelsToTileUnits; return util::polygonIntersectsBufferedMultiLine( translatedQueryGeometry.value_or(queryGeometry), - offsetGeometry.value_or(geometry), + offsetGeometry.value_or(feature.getGeometries()), halfWidth); } diff --git a/src/mbgl/style/layers/line_layer_impl.hpp b/src/mbgl/style/layers/line_layer_impl.hpp index 67e793f2ea..b25ece3100 100644 --- a/src/mbgl/style/layers/line_layer_impl.hpp +++ b/src/mbgl/style/layers/line_layer_impl.hpp @@ -18,12 +18,12 @@ public: std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const Layer*>&) const override; - float getQueryRadius() const override; - bool queryIntersectsGeometry( - const GeometryCoordinates& queryGeometry, - const GeometryCollection& geometry, - const float bearing, - const float pixelsToTileUnits) const override; + bool queryIntersectsFeature( + const GeometryCoordinates&, + const GeometryTileFeature&, + const float, + const float, + const float) const override; LineLayoutProperties layout; LinePaintProperties paint; @@ -32,7 +32,7 @@ public: float dashLineWidth = 1; private: - float getLineWidth() const; + float getLineWidth(const GeometryTileFeature&, const float) const; }; } // namespace style diff --git a/src/mbgl/style/possibly_evaluated_property_value.hpp b/src/mbgl/style/possibly_evaluated_property_value.hpp index 8c3f1780a6..9cb5f6e81b 100644 --- a/src/mbgl/style/possibly_evaluated_property_value.hpp +++ b/src/mbgl/style/possibly_evaluated_property_value.hpp @@ -7,8 +7,6 @@ namespace mbgl { -class GeometryTileFeature; - namespace style { template <class T> @@ -43,6 +41,19 @@ public: auto match(Ts&&... ts) const { return value.match(std::forward<Ts>(ts)...); } + + template <class Feature> + T evaluate(const Feature& feature, float zoom, T defaultValue) const { + return this->match( + [&] (const T& constant) { return constant; }, + [&] (const SourceFunction<T>& function) { + return function.evaluate(feature, defaultValue); + }, + [&] (const CompositeFunction<T>& function) { + return function.evaluate(zoom, feature, defaultValue); + } + ); + } }; } // namespace style diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 4c3ea207f5..1e18709391 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -541,18 +541,6 @@ std::vector<Feature> Style::queryRenderedFeatures(const ScreenLineString& geomet return result; } -float Style::getQueryRadius() const { - float additionalRadius = 0; - for (auto& layer : layers) { - if (!layer->baseImpl->needsRendering(zoomHistory.lastZoom)) { - continue; - } - additionalRadius = util::max(additionalRadius, layer->baseImpl->getQueryRadius()); - } - return additionalRadius; -} - - void Style::setSourceTileCacheSize(size_t size) { for (const auto& source : sources) { source->baseImpl->setCacheSize(size); diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index 817cab5fd5..50c91b8050 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -101,8 +101,6 @@ public: const TransformState& transformState, const RenderedQueryOptions& options) const; - float getQueryRadius() const; - void setSourceTileCacheSize(size_t); void onLowMemory(); |