Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] add heatmap layer
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Jan 25, 2018
1 parent a4546a8 commit ca99c40
Show file tree
Hide file tree
Showing 55 changed files with 4,027 additions and 32 deletions.
18 changes: 18 additions & 0 deletions cmake/core-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ set(MBGL_CORE_FILES
src/mbgl/programs/hillshade_prepare_program.hpp
src/mbgl/programs/hillshade_program.cpp
src/mbgl/programs/hillshade_program.hpp
src/mbgl/programs/heatmap_program.cpp
src/mbgl/programs/heatmap_program.hpp
src/mbgl/programs/line_program.cpp
src/mbgl/programs/line_program.hpp
src/mbgl/programs/program.hpp
Expand Down Expand Up @@ -227,6 +229,8 @@ set(MBGL_CORE_FILES
src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp
src/mbgl/renderer/buckets/hillshade_bucket.cpp
src/mbgl/renderer/buckets/hillshade_bucket.hpp
src/mbgl/renderer/buckets/heatmap_bucket.cpp
src/mbgl/renderer/buckets/heatmap_bucket.hpp
src/mbgl/renderer/buckets/line_bucket.cpp
src/mbgl/renderer/buckets/line_bucket.hpp
src/mbgl/renderer/buckets/raster_bucket.cpp
Expand All @@ -247,6 +251,8 @@ set(MBGL_CORE_FILES
src/mbgl/renderer/layers/render_fill_layer.hpp
src/mbgl/renderer/layers/render_hillshade_layer.cpp
src/mbgl/renderer/layers/render_hillshade_layer.hpp
src/mbgl/renderer/layers/render_heatmap_layer.cpp
src/mbgl/renderer/layers/render_heatmap_layer.hpp
src/mbgl/renderer/layers/render_line_layer.cpp
src/mbgl/renderer/layers/render_line_layer.hpp
src/mbgl/renderer/layers/render_raster_layer.cpp
Expand Down Expand Up @@ -301,6 +307,10 @@ set(MBGL_CORE_FILES
src/mbgl/shaders/hillshade.hpp
src/mbgl/shaders/hillshade_prepare.cpp
src/mbgl/shaders/hillshade_prepare.hpp
src/mbgl/shaders/heatmap.cpp
src/mbgl/shaders/heatmap.hpp
src/mbgl/shaders/heatmap_texture.cpp
src/mbgl/shaders/heatmap_texture.hpp
src/mbgl/shaders/line.cpp
src/mbgl/shaders/line.hpp
src/mbgl/shaders/line_pattern.cpp
Expand Down Expand Up @@ -349,6 +359,7 @@ set(MBGL_CORE_FILES
include/mbgl/style/data_driven_property_value.hpp
include/mbgl/style/filter.hpp
include/mbgl/style/filter_evaluator.hpp
include/mbgl/style/heatmap_color_property_value.hpp
include/mbgl/style/image.hpp
include/mbgl/style/layer.hpp
include/mbgl/style/layer_type.hpp
Expand Down Expand Up @@ -401,6 +412,7 @@ set(MBGL_CORE_FILES
include/mbgl/style/conversion/geojson.hpp
include/mbgl/style/conversion/geojson_options.hpp
include/mbgl/style/conversion/get_json_type.hpp
include/mbgl/style/conversion/heatmap_color_property_value.hpp
include/mbgl/style/conversion/layer.hpp
include/mbgl/style/conversion/light.hpp
include/mbgl/style/conversion/position.hpp
Expand Down Expand Up @@ -496,6 +508,7 @@ set(MBGL_CORE_FILES
include/mbgl/style/layers/fill_extrusion_layer.hpp
include/mbgl/style/layers/fill_layer.hpp
include/mbgl/style/layers/hillshade_layer.hpp
include/mbgl/style/layers/heatmap_layer.hpp
include/mbgl/style/layers/line_layer.hpp
include/mbgl/style/layers/raster_layer.hpp
include/mbgl/style/layers/symbol_layer.hpp
Expand Down Expand Up @@ -527,6 +540,11 @@ set(MBGL_CORE_FILES
src/mbgl/style/layers/hillshade_layer_impl.hpp
src/mbgl/style/layers/hillshade_layer_properties.cpp
src/mbgl/style/layers/hillshade_layer_properties.hpp
src/mbgl/style/layers/heatmap_layer.cpp
src/mbgl/style/layers/heatmap_layer_impl.cpp
src/mbgl/style/layers/heatmap_layer_impl.hpp
src/mbgl/style/layers/heatmap_layer_properties.cpp
src/mbgl/style/layers/heatmap_layer_properties.hpp
src/mbgl/style/layers/line_layer.cpp
src/mbgl/style/layers/line_layer_impl.cpp
src/mbgl/style/layers/line_layer_impl.hpp
Expand Down
46 changes: 46 additions & 0 deletions include/mbgl/style/conversion/heatmap_color_property_value.hpp
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 {};
}
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

47 changes: 47 additions & 0 deletions include/mbgl/style/heatmap_color_property_value.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#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.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; }
};


} // namespace style
} // namespace mbgl
3 changes: 3 additions & 0 deletions include/mbgl/style/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class HillshadeLayer;
class BackgroundLayer;
class CustomLayer;
class FillExtrusionLayer;
class HeatmapLayer;
class LayerObserver;

/**
Expand Down Expand Up @@ -93,6 +94,8 @@ class Layer : public mbgl::util::noncopyable {
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>());
}


Expand Down
1 change: 1 addition & 0 deletions include/mbgl/style/layer_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum class LayerType {
Background,
Custom,
FillExtrusion,
Heatmap
};

} // namespace style
Expand Down
86 changes: 86 additions & 0 deletions include/mbgl/style/layers/heatmap_layer.hpp
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
3 changes: 3 additions & 0 deletions include/mbgl/style/layers/layer.hpp.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Loading

0 comments on commit ca99c40

Please sign in to comment.