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

Heatmap layer #11046

Merged
merged 3 commits into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions cmake/core-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ set(MBGL_CORE_FILES
src/mbgl/programs/fill_extrusion_program.hpp
src/mbgl/programs/fill_program.cpp
src/mbgl/programs/fill_program.hpp
src/mbgl/programs/heatmap_program.cpp
src/mbgl/programs/heatmap_program.hpp
src/mbgl/programs/heatmap_texture_program.cpp
src/mbgl/programs/heatmap_texture_program.hpp
src/mbgl/programs/hillshade_prepare_program.cpp
src/mbgl/programs/hillshade_prepare_program.hpp
src/mbgl/programs/hillshade_program.cpp
Expand Down Expand Up @@ -225,6 +229,8 @@ set(MBGL_CORE_FILES
src/mbgl/renderer/buckets/fill_bucket.hpp
src/mbgl/renderer/buckets/fill_extrusion_bucket.cpp
src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp
src/mbgl/renderer/buckets/heatmap_bucket.cpp
src/mbgl/renderer/buckets/heatmap_bucket.hpp
src/mbgl/renderer/buckets/hillshade_bucket.cpp
src/mbgl/renderer/buckets/hillshade_bucket.hpp
src/mbgl/renderer/buckets/line_bucket.cpp
Expand All @@ -245,6 +251,8 @@ set(MBGL_CORE_FILES
src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp
src/mbgl/renderer/layers/render_fill_layer.cpp
src/mbgl/renderer/layers/render_fill_layer.hpp
src/mbgl/renderer/layers/render_heatmap_layer.cpp
src/mbgl/renderer/layers/render_heatmap_layer.hpp
src/mbgl/renderer/layers/render_hillshade_layer.cpp
src/mbgl/renderer/layers/render_hillshade_layer.hpp
src/mbgl/renderer/layers/render_line_layer.cpp
Expand Down Expand Up @@ -297,6 +305,10 @@ set(MBGL_CORE_FILES
src/mbgl/shaders/fill_outline_pattern.hpp
src/mbgl/shaders/fill_pattern.cpp
src/mbgl/shaders/fill_pattern.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/hillshade.cpp
src/mbgl/shaders/hillshade.hpp
src/mbgl/shaders/hillshade_prepare.cpp
Expand Down Expand Up @@ -349,6 +361,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 +414,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 @@ -495,6 +509,7 @@ set(MBGL_CORE_FILES
include/mbgl/style/layers/custom_layer.hpp
include/mbgl/style/layers/fill_extrusion_layer.hpp
include/mbgl/style/layers/fill_layer.hpp
include/mbgl/style/layers/heatmap_layer.hpp
include/mbgl/style/layers/hillshade_layer.hpp
include/mbgl/style/layers/line_layer.hpp
include/mbgl/style/layers/raster_layer.hpp
Expand Down Expand Up @@ -522,6 +537,11 @@ set(MBGL_CORE_FILES
src/mbgl/style/layers/fill_layer_impl.hpp
src/mbgl/style/layers/fill_layer_properties.cpp
src/mbgl/style/layers/fill_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/hillshade_layer.cpp
src/mbgl/style/layers/hillshade_layer_impl.cpp
src/mbgl/style/layers/hillshade_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);
Copy link
Contributor

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.

Copy link
Contributor

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

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
49 changes: 49 additions & 0 deletions include/mbgl/style/heatmap_color_property_value.hpp
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The 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 ColorRampPropertyValue. However I'd leave it as is for now to be consistent with GL JS, and only rename when we land another feature that uses it such as line gradients.

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
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
2 changes: 1 addition & 1 deletion mapbox-gl-js
Submodule mapbox-gl-js updated 55 files
+3 −0 .circleci/deploy.sh
+2 −1 bench/README.md
+23 −8 bench/index.html
+2 −2 package.json
+3 −5 src/data/feature_index.js
+9 −2 src/geo/transform.js
+1 −1 src/source/query_features.js
+1 −1 src/source/tile.js
+42 −6 src/style-spec/reference/v8.json
+5 −0 src/style/pauseable_placement.js
+17 −16 src/style/style.js
+15 −11 src/symbol/placement.js
+1 −1 src/ui/hash.js
+21 −0 src/ui/map.js
+37 −22 test/integration/lib/render.js
+2 −1 test/integration/package.json
+13 −0 test/integration/query-tests/regressions/mapbox-gl-js#6075/expected.json
+51 −0 test/integration/query-tests/regressions/mapbox-gl-js#6075/style.json
+ test/integration/render-tests/heatmap-color/default/expected-half-float.png
+2 −1 test/integration/render-tests/heatmap-color/default/style.json
+ test/integration/render-tests/heatmap-color/expression/expected-half-float.png
+2 −1 test/integration/render-tests/heatmap-color/expression/style.json
+ test/integration/render-tests/heatmap-intensity/default/expected-half-float.png
+2 −1 test/integration/render-tests/heatmap-intensity/default/style.json
+ test/integration/render-tests/heatmap-intensity/function/expected-half-float.png
+2 −1 test/integration/render-tests/heatmap-intensity/function/style.json
+ test/integration/render-tests/heatmap-intensity/literal/expected-half-float.png
+2 −1 test/integration/render-tests/heatmap-intensity/literal/style.json
+ test/integration/render-tests/heatmap-opacity/default/expected-half-float.png
+2 −1 test/integration/render-tests/heatmap-opacity/default/style.json
+ test/integration/render-tests/heatmap-opacity/function/expected-half-float.png
+2 −1 test/integration/render-tests/heatmap-opacity/function/style.json
+ test/integration/render-tests/heatmap-opacity/literal/expected-half-float.png
+2 −1 test/integration/render-tests/heatmap-opacity/literal/style.json
+ test/integration/render-tests/heatmap-radius/antimeridian/expected-half-float.png
+2 −1 test/integration/render-tests/heatmap-radius/antimeridian/style.json
+ test/integration/render-tests/heatmap-radius/data-expression/expected-half-float.png
+2 −1 test/integration/render-tests/heatmap-radius/data-expression/style.json
+ test/integration/render-tests/heatmap-radius/default/expected-half-float.png
+2 −1 test/integration/render-tests/heatmap-radius/default/style.json
+ test/integration/render-tests/heatmap-radius/function/expected-half-float.png
+2 −1 test/integration/render-tests/heatmap-radius/function/style.json
+ test/integration/render-tests/heatmap-radius/literal/expected-half-float.png
+2 −1 test/integration/render-tests/heatmap-radius/literal/style.json
+ test/integration/render-tests/heatmap-radius/pitch30/expected-half-float.png
+2 −1 test/integration/render-tests/heatmap-radius/pitch30/style.json
+ test/integration/render-tests/heatmap-weight/default/expected-half-float.png
+2 −1 test/integration/render-tests/heatmap-weight/default/style.json
+ test/integration/render-tests/heatmap-weight/identity-property-function/expected-half-float.png
+2 −1 test/integration/render-tests/heatmap-weight/identity-property-function/style.json
+ test/integration/render-tests/heatmap-weight/literal/expected-half-float.png
+2 −1 test/integration/render-tests/heatmap-weight/literal/style.json
+1 −3 test/unit/style/style.test.js
+48 −0 test/unit/ui/map.test.js
+61 −106 yarn.lock
4 changes: 4 additions & 0 deletions platform/android/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Mapbox welcomes participation and contributions from everyone. If you'd like to do so please see the [`Contributing Guide`](https://github.com/mapbox/mapbox-gl-native/blob/master/CONTRIBUTING.md) first to get started.

## master

- HeatmapLayer [#11046](https://github.com/mapbox/mapbox-gl-native/pull/11046)

## 6.0.0-beta.2 - February 13, 2018
- Deprecate LocationEngine [#11185](https://github.com/mapbox/mapbox-gl-native/pull/11185)
- Remove LOST from SDK [11186](https://github.com/mapbox/mapbox-gl-native/pull/11186)
Expand Down
Loading