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

Add and remove layers dynamically #4839

Merged
merged 8 commits into from
Jun 2, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ tidy: compdb

#### Miscellaneous targets #####################################################

style-code:
node scripts/generate-style-code.js

clean:
-find ./deps/gyp -name "*.pyc" -exec rm {} \;
-rm -rf ./build \
Expand Down
3 changes: 1 addition & 2 deletions include/mbgl/annotation/annotation.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#pragma once

#include <mbgl/style/types.hpp>

#include <mbgl/util/geometry.hpp>
#include <mbgl/util/variant.hpp>
#include <mbgl/util/color.hpp>

#include <cstdint>
#include <vector>
Expand Down
22 changes: 10 additions & 12 deletions include/mbgl/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
#include <mbgl/util/feature.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/annotation/annotation.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/style/property_transition.hpp>
#include <mbgl/style/transition_options.hpp>

#include <cstdint>
#include <string>
Expand All @@ -26,6 +25,10 @@ class SpriteImage;
struct CameraOptions;
struct AnimationOptions;

namespace style {
class Layer;
}

class Map : private util::noncopyable {
public:
explicit Map(View&, FileSource&,
Expand All @@ -47,9 +50,9 @@ class Map : private util::noncopyable {
void update(Update update);

// Styling
void addClass(const std::string&, const PropertyTransition& = {});
void removeClass(const std::string&, const PropertyTransition& = {});
void setClasses(const std::vector<std::string>&, const PropertyTransition& = {});
void addClass(const std::string&, const style::TransitionOptions& = {});
void removeClass(const std::string&, const style::TransitionOptions& = {});
void setClasses(const std::vector<std::string>&, const style::TransitionOptions& = {});

bool hasClass(const std::string&) const;
std::vector<std::string> getClasses() const;
Expand Down Expand Up @@ -146,13 +149,8 @@ class Map : private util::noncopyable {

AnnotationIDs getPointAnnotationsInBounds(const LatLngBounds&);

void addCustomLayer(const std::string& id,
CustomLayerInitializeFunction,
CustomLayerRenderFunction,
CustomLayerDeinitializeFunction,
void* context,
const char* before = nullptr);
void removeCustomLayer(const std::string& id);
void addLayer(std::unique_ptr<style::Layer>, const optional<std::string>& beforeLayerID = {});
void removeLayer(const std::string& layerID);

// Feature queries
std::vector<Feature> queryRenderedFeatures(const ScreenCoordinate&, const optional<std::vector<std::string>>& layerIDs = {});
Expand Down
4 changes: 2 additions & 2 deletions include/mbgl/map/view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class View {
// as a matched pair, in four situations:
//
// 1. When releasing GL resources during Map destruction
// 2. When calling a CustomLayerInitializeFunction, during Map::addCustomLayer
// 3. When calling a CustomLayerDeinitializeFunction, during Map::removeCustomLayer
// 2. When calling a CustomLayerInitializeFunction, during Map::addLayer
// 3. When calling a CustomLayerDeinitializeFunction, during Map::removeLayer
// 4. When rendering for Map::renderStill
//
// They are *not* called for Map::render; it is assumed that the correct context is already
Expand Down
4 changes: 2 additions & 2 deletions include/mbgl/storage/offline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace mbgl {

class TileID;
class SourceInfo;
class Tileset;

/*
* An offline region defined by a style URL, geographic bounding box, zoom range, and
Expand All @@ -30,7 +30,7 @@ class OfflineTilePyramidRegionDefinition {
OfflineTilePyramidRegionDefinition(const std::string&, const LatLngBounds&, double, double, float);

/* Private */
std::vector<CanonicalTileID> tileCover(SourceType, uint16_t tileSize, const SourceInfo&) const;
std::vector<CanonicalTileID> tileCover(SourceType, uint16_t tileSize, const Tileset&) const;

const std::string styleURL;
const LatLngBounds bounds;
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/storage/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <mbgl/storage/response.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/util/font_stack.hpp>

#include <string>

Expand Down
2 changes: 2 additions & 0 deletions src/mbgl/style/filter.hpp → include/mbgl/style/filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <vector>

namespace mbgl {
namespace style {

typedef variant<
class NullFilter,
Expand Down Expand Up @@ -100,4 +101,5 @@ class NotHasFilter {
std::string key;
};

} // namespace style
} // namespace mbgl
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
#include <utility>

namespace mbgl {
namespace style {

template <typename T>
class Function {
public:
using Stop = std::pair<float, T>;
using Stops = std::vector<Stop>;

explicit Function(const T& constant)
: stops({{ 0, constant }}) {}

explicit Function(const Stops& stops_, float base_)
: base(base_), stops(stops_) {}

Expand All @@ -25,4 +23,5 @@ class Function {
std::vector<std::pair<float, T>> stops;
};

} // namespace style
} // namespace mbgl
83 changes: 83 additions & 0 deletions include/mbgl/style/layer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#pragma once

#include <mbgl/util/noncopyable.hpp>
#include <mbgl/style/types.hpp>

#include <memory>

namespace mbgl {
namespace style {

/**
* The runtime representation of a [layer](https://www.mapbox.com/mapbox-gl-style-spec/#layers) from the Mapbox Style
* Specification.
*
* `Layer` is an abstract base class; concrete derived classes are provided for each layer type. `Layer` contains
* functionality that is common to all layer types:
*
* * Runtime type information: type predicates and casting
* * Accessors for properties common to all layer types: ID, visibility, etc.
* * Cloning and copying
*
* All other functionality lives in the derived classes. To instantiate a layer, create an instance of the desired
* type, passing the ID:
*
* auto circleLayer = std::make_unique<CircleLayer>("my-circle-layer");
*/
class Layer : public mbgl::util::noncopyable {
public:
virtual ~Layer();

// Check whether this layer is of the given subtype.
template <class T>
bool is() const;

// Dynamically cast this layer to the given subtype.
template <class T>
T* as() {
return is<T>() ? reinterpret_cast<T*>(this) : nullptr;
}

template <class T>
const T* as() const {
return is<T>() ? reinterpret_cast<const T*>(this) : nullptr;
}

const std::string& getID() const;

// Visibility
VisibilityType getVisibility() const;
void setVisibility(VisibilityType);

// Zoom range
float getMinZoom() const;
void setMinZoom(float) const;
float getMaxZoom() const;
void setMaxZoom(float) const;

// Create a new layer with the specified `id` and `ref`. All other properties
// are copied from this layer.
std::unique_ptr<Layer> copy(const std::string& id,
const std::string& ref) const;

// Private implementation
class Impl;
const std::unique_ptr<Impl> baseImpl;

protected:
enum class Type {
Fill,
Line,
Circle,
Symbol,
Raster,
Background,
Custom,
};

const Type type;
Layer(Type, std::unique_ptr<Impl>);
};

} // namespace style
} // namespace mbgl
45 changes: 45 additions & 0 deletions include/mbgl/style/layers/background_layer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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/util/color.hpp>

namespace mbgl {
namespace style {

class BackgroundLayer : public Layer {
public:
BackgroundLayer(const std::string& layerID);
~BackgroundLayer() final;

// Paint properties

PropertyValue<Color> getBackgroundColor() const;
void setBackgroundColor(PropertyValue<Color>);

PropertyValue<std::string> getBackgroundPattern() const;
void setBackgroundPattern(PropertyValue<std::string>);

PropertyValue<float> getBackgroundOpacity() const;
void setBackgroundOpacity(PropertyValue<float>);

// Private implementation

class Impl;
Impl* const impl;

BackgroundLayer(const Impl&);
BackgroundLayer(const BackgroundLayer&) = delete;
};

template <>
inline bool Layer::is<BackgroundLayer>() const {
return type == Type::Background;
}

} // namespace style
} // namespace mbgl
63 changes: 63 additions & 0 deletions include/mbgl/style/layers/circle_layer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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/util/color.hpp>

namespace mbgl {
namespace style {

class CircleLayer : public Layer {
public:
CircleLayer(const std::string& layerID);
~CircleLayer() final;

// Source

void setSource(const std::string& sourceID, const std::string& sourceLayer);
const std::string& getSourceID() const;
const std::string& getSourceLayer() const;

void setFilter(const Filter&);
const Filter& getFilter() const;

// Paint properties

PropertyValue<float> getCircleRadius() const;
void setCircleRadius(PropertyValue<float>);

PropertyValue<Color> getCircleColor() const;
void setCircleColor(PropertyValue<Color>);

PropertyValue<float> getCircleBlur() const;
void setCircleBlur(PropertyValue<float>);

PropertyValue<float> getCircleOpacity() const;
void setCircleOpacity(PropertyValue<float>);

PropertyValue<std::array<float, 2>> getCircleTranslate() const;
void setCircleTranslate(PropertyValue<std::array<float, 2>>);

PropertyValue<TranslateAnchorType> getCircleTranslateAnchor() const;
void setCircleTranslateAnchor(PropertyValue<TranslateAnchorType>);

// Private implementation

class Impl;
Impl* const impl;

CircleLayer(const Impl&);
CircleLayer(const CircleLayer&) = delete;
};

template <>
inline bool Layer::is<CircleLayer>() const {
return type == Type::Circle;
}

} // namespace style
} // namespace mbgl
Loading