This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Merged
Heatmap layer #11046
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
include/mbgl/style/conversion/heatmap_color_property_value.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#pragma once | ||
|
||
#include <mbgl/style/heatmap_color_property_value.hpp> | ||
#include <mbgl/style/conversion.hpp> | ||
#include <mbgl/style/conversion/constant.hpp> | ||
#include <mbgl/style/conversion/function.hpp> | ||
#include <mbgl/style/conversion/expression.hpp> | ||
#include <mbgl/style/expression/value.hpp> | ||
#include <mbgl/style/expression/is_constant.hpp> | ||
#include <mbgl/style/expression/is_expression.hpp> | ||
#include <mbgl/style/expression/find_zoom_curve.hpp> | ||
|
||
namespace mbgl { | ||
namespace style { | ||
namespace conversion { | ||
|
||
template <> | ||
struct Converter<HeatmapColorPropertyValue> { | ||
optional<HeatmapColorPropertyValue> operator()(const Convertible& value, Error& error) const { | ||
if (isUndefined(value)) { | ||
return HeatmapColorPropertyValue(); | ||
} else if (isExpression(value)) { | ||
optional<std::unique_ptr<Expression>> expression = convert<std::unique_ptr<Expression>>(value, error, expression::type::Color); | ||
if (!expression) { | ||
return {}; | ||
} | ||
assert(*expression); | ||
if (!isFeatureConstant(**expression)) { | ||
error = { "property expressions not supported" }; | ||
return {}; | ||
} | ||
if (!isZoomConstant(**expression)) { | ||
error = { "zoom expressions not supported" }; | ||
return {}; | ||
} | ||
return {HeatmapColorPropertyValue(std::move(*expression))}; | ||
} else { | ||
error = { "heatmap-color must be an expression" }; | ||
return {}; | ||
} | ||
} | ||
}; | ||
|
||
} // namespace conversion | ||
} // namespace style | ||
} // namespace mbgl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
|
||
#include <mbgl/util/variant.hpp> | ||
#include <mbgl/style/undefined.hpp> | ||
#include <mbgl/style/function/camera_function.hpp> | ||
|
||
namespace mbgl { | ||
namespace style { | ||
|
||
/* | ||
* Special-case implementation of (a subset of) the PropertyValue<T> interface | ||
* used for building the HeatmapColor paint property traits class. | ||
*/ | ||
class HeatmapColorPropertyValue { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of naming this after heatmaps, can we find a more generic name for this in light of other code that might use these color ramps too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes! In fact @lbud's line gradient branch, which reuses it, renames it to |
||
private: | ||
std::shared_ptr<expression::Expression> value; | ||
|
||
friend bool operator==(const HeatmapColorPropertyValue& lhs, const HeatmapColorPropertyValue& rhs) { | ||
return (lhs.isUndefined() && rhs.isUndefined()) || (lhs.value && rhs.value && *(lhs.value) == *(rhs.value)); | ||
} | ||
|
||
friend bool operator!=(const HeatmapColorPropertyValue& lhs, const HeatmapColorPropertyValue& rhs) { | ||
return !(lhs == rhs); | ||
} | ||
|
||
public: | ||
HeatmapColorPropertyValue() : value(nullptr) {} | ||
HeatmapColorPropertyValue(std::shared_ptr<expression::Expression> value_) : value(std::move(value_)) {} | ||
|
||
bool isUndefined() const { return value.get() == nullptr; } | ||
|
||
// noop, needed for batch evaluation of paint property values to compile | ||
template <typename Evaluator> | ||
Color evaluate(const Evaluator&, TimePoint = {}) const { return {}; } | ||
|
||
Color evaluate(double heatmapDensity) const { | ||
const auto result = value->evaluate(expression::EvaluationContext({}, nullptr, {heatmapDensity})); | ||
return *expression::fromExpressionValue<Color>(*result); | ||
} | ||
|
||
bool isDataDriven() const { return false; } | ||
bool hasDataDrivenPropertyDifference(const HeatmapColorPropertyValue&) const { return false; } | ||
|
||
const expression::Expression& getExpression() const { return *value; } | ||
}; | ||
|
||
|
||
} // namespace style | ||
} // namespace mbgl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ enum class LayerType { | |
Background, | ||
Custom, | ||
FillExtrusion, | ||
Heatmap, | ||
}; | ||
|
||
} // namespace style | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// This file is generated. Do not edit. | ||
|
||
#pragma once | ||
|
||
#include <mbgl/style/layer.hpp> | ||
#include <mbgl/style/filter.hpp> | ||
#include <mbgl/style/property_value.hpp> | ||
#include <mbgl/style/data_driven_property_value.hpp> | ||
#include <mbgl/style/heatmap_color_property_value.hpp> | ||
|
||
#include <mbgl/util/color.hpp> | ||
|
||
namespace mbgl { | ||
namespace style { | ||
|
||
class TransitionOptions; | ||
|
||
class HeatmapLayer : public Layer { | ||
public: | ||
HeatmapLayer(const std::string& layerID, const std::string& sourceID); | ||
~HeatmapLayer() final; | ||
|
||
// Source | ||
const std::string& getSourceID() const; | ||
const std::string& getSourceLayer() const; | ||
void setSourceLayer(const std::string& sourceLayer); | ||
|
||
void setFilter(const Filter&); | ||
const Filter& getFilter() const; | ||
|
||
// Visibility | ||
void setVisibility(VisibilityType) final; | ||
|
||
// Zoom range | ||
void setMinZoom(float) final; | ||
void setMaxZoom(float) final; | ||
|
||
// Paint properties | ||
|
||
static DataDrivenPropertyValue<float> getDefaultHeatmapRadius(); | ||
DataDrivenPropertyValue<float> getHeatmapRadius() const; | ||
void setHeatmapRadius(DataDrivenPropertyValue<float>); | ||
void setHeatmapRadiusTransition(const TransitionOptions&); | ||
TransitionOptions getHeatmapRadiusTransition() const; | ||
|
||
static DataDrivenPropertyValue<float> getDefaultHeatmapWeight(); | ||
DataDrivenPropertyValue<float> getHeatmapWeight() const; | ||
void setHeatmapWeight(DataDrivenPropertyValue<float>); | ||
void setHeatmapWeightTransition(const TransitionOptions&); | ||
TransitionOptions getHeatmapWeightTransition() const; | ||
|
||
static PropertyValue<float> getDefaultHeatmapIntensity(); | ||
PropertyValue<float> getHeatmapIntensity() const; | ||
void setHeatmapIntensity(PropertyValue<float>); | ||
void setHeatmapIntensityTransition(const TransitionOptions&); | ||
TransitionOptions getHeatmapIntensityTransition() const; | ||
|
||
static HeatmapColorPropertyValue getDefaultHeatmapColor(); | ||
HeatmapColorPropertyValue getHeatmapColor() const; | ||
void setHeatmapColor(HeatmapColorPropertyValue); | ||
void setHeatmapColorTransition(const TransitionOptions&); | ||
TransitionOptions getHeatmapColorTransition() const; | ||
|
||
static PropertyValue<float> getDefaultHeatmapOpacity(); | ||
PropertyValue<float> getHeatmapOpacity() const; | ||
void setHeatmapOpacity(PropertyValue<float>); | ||
void setHeatmapOpacityTransition(const TransitionOptions&); | ||
TransitionOptions getHeatmapOpacityTransition() const; | ||
|
||
// Private implementation | ||
|
||
class Impl; | ||
const Impl& impl() const; | ||
|
||
Mutable<Impl> mutableImpl() const; | ||
HeatmapLayer(Immutable<Impl>); | ||
std::unique_ptr<Layer> cloneRef(const std::string& id) const final; | ||
}; | ||
|
||
template <> | ||
inline bool Layer::is<HeatmapLayer>() const { | ||
return getType() == LayerType::Heatmap; | ||
} | ||
|
||
} // namespace style | ||
} // namespace mbgl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule mapbox-gl-js
updated
55 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the
unique_ptr
in this optional be ever be empty? If so, we should check for that to avoid null dereferences further down.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should never be null (we use the optional to represent parsing failure). It's a bug rather than a recoverable failure if the pointer is null, so if we want to check here, it should be with an
assert