[core, ios, macos, android, node] Heatmap layer (#11046)

Co-Authored-By: Konstantin Käfer <mail@kkaefer.com>
Co-Authored-By: Anand Thakker <anandthakker@users.noreply.github.com>
Co-Authored-By: Minh Nguyễn <1ec5@users.noreply.github.com>
This commit is contained in:
Vladimir Agafonkin
2018-02-15 17:38:23 +02:00
committed by GitHub
parent 1fdec7a5c1
commit 82de856c94
90 changed files with 4570 additions and 61 deletions

View File

@@ -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

View File

@@ -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 {
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

View File

@@ -23,6 +23,7 @@ class HillshadeLayer;
class BackgroundLayer;
class CustomLayer;
class FillExtrusionLayer;
class HeatmapLayer;
class LayerObserver;
/**
@@ -93,6 +94,8 @@ public:
return std::forward<V>(visitor)(*as<CustomLayer>());
case LayerType::FillExtrusion:
return std::forward<V>(visitor)(*as<FillExtrusionLayer>());
case LayerType::Heatmap:
return std::forward<V>(visitor)(*as<HeatmapLayer>());
}

View File

@@ -13,6 +13,7 @@ enum class LayerType {
Background,
Custom,
FillExtrusion,
Heatmap,
};
} // namespace style

View File

@@ -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

View File

@@ -11,6 +11,9 @@
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>
#include <mbgl/style/data_driven_property_value.hpp>
<% if (type === 'heatmap') { -%>
#include <mbgl/style/heatmap_color_property_value.hpp>
<% } -%>
#include <mbgl/util/color.hpp>