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

Custom Vector Source (n+1) #9983

Merged
merged 10 commits into from
Nov 22, 2017
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
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ set_source_files_properties(src/mbgl/util/version.cpp PROPERTIES COMPILE_DEFINIT

mason_use(geometry VERSION 0.9.2 HEADER_ONLY)
mason_use(variant VERSION 1.1.4 HEADER_ONLY)
mason_use(any VERSION 8fef1e9 HEADER_ONLY)
mason_use(unique_resource VERSION cba309e HEADER_ONLY)
mason_use(rapidjson VERSION 1.1.0 HEADER_ONLY)
mason_use(boost VERSION 1.62.0 HEADER_ONLY)
Expand Down
13 changes: 12 additions & 1 deletion cmake/core-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ set(MBGL_CORE_FILES
src/mbgl/renderer/layers/render_symbol_layer.hpp

# renderer/sources
src/mbgl/renderer/sources/render_custom_geometry_source.cpp
src/mbgl/renderer/sources/render_custom_geometry_source.hpp
src/mbgl/renderer/sources/render_geojson_source.cpp
src/mbgl/renderer/sources/render_geojson_source.hpp
src/mbgl/renderer/sources/render_image_source.cpp
Expand Down Expand Up @@ -334,6 +336,8 @@ set(MBGL_CORE_FILES
include/mbgl/style/types.hpp
include/mbgl/style/undefined.hpp
src/mbgl/style/collection.hpp
src/mbgl/style/custom_tile_loader.cpp
src/mbgl/style/custom_tile_loader.hpp
src/mbgl/style/image.cpp
src/mbgl/style/image_impl.cpp
src/mbgl/style/image_impl.hpp
Expand Down Expand Up @@ -364,6 +368,7 @@ set(MBGL_CORE_FILES
# style/conversion
include/mbgl/style/conversion/constant.hpp
include/mbgl/style/conversion/coordinate.hpp
include/mbgl/style/conversion/custom_geometry_source_options.hpp
include/mbgl/style/conversion/data_driven_property_value.hpp
include/mbgl/style/conversion/expression.hpp
include/mbgl/style/conversion/filter.hpp
Expand Down Expand Up @@ -506,10 +511,14 @@ set(MBGL_CORE_FILES
src/mbgl/style/layers/symbol_layer_properties.hpp

# style/sources
include/mbgl/style/sources/custom_geometry_source.hpp
include/mbgl/style/sources/geojson_source.hpp
include/mbgl/style/sources/image_source.hpp
include/mbgl/style/sources/raster_source.hpp
include/mbgl/style/sources/vector_source.hpp
src/mbgl/style/sources/custom_geometry_source.cpp
src/mbgl/style/sources/custom_geometry_source_impl.cpp
src/mbgl/style/sources/custom_geometry_source_impl.hpp
src/mbgl/style/sources/geojson_source.cpp
src/mbgl/style/sources/geojson_source_impl.cpp
src/mbgl/style/sources/geojson_source_impl.hpp
Expand Down Expand Up @@ -555,6 +564,8 @@ set(MBGL_CORE_FILES
# tile
include/mbgl/tile/tile_id.hpp
include/mbgl/tile/tile_necessity.hpp
src/mbgl/tile/custom_geometry_tile.cpp
src/mbgl/tile/custom_geometry_tile.hpp
src/mbgl/tile/geojson_tile.cpp
src/mbgl/tile/geojson_tile.hpp
src/mbgl/tile/geojson_tile_data.hpp
Expand Down Expand Up @@ -583,7 +594,6 @@ set(MBGL_CORE_FILES
src/mbgl/tile/vector_tile_data.hpp

# util
include/mbgl/util/any.hpp
include/mbgl/util/async_request.hpp
include/mbgl/util/async_task.hpp
include/mbgl/util/char_array_buffer.hpp
Expand Down Expand Up @@ -620,6 +630,7 @@ set(MBGL_CORE_FILES
include/mbgl/util/timer.hpp
include/mbgl/util/traits.hpp
include/mbgl/util/type_list.hpp
include/mbgl/util/unique_any.hpp
include/mbgl/util/unitbezier.hpp
include/mbgl/util/util.hpp
include/mbgl/util/variant.hpp
Expand Down
1 change: 0 additions & 1 deletion cmake/core.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ target_include_directories(mbgl-core

target_add_mason_package(mbgl-core PUBLIC geometry)
target_add_mason_package(mbgl-core PUBLIC variant)
target_add_mason_package(mbgl-core PUBLIC any)
target_add_mason_package(mbgl-core PRIVATE unique_resource)
target_add_mason_package(mbgl-core PRIVATE rapidjson)
target_add_mason_package(mbgl-core PRIVATE boost)
Expand Down
1 change: 0 additions & 1 deletion cmake/filesource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ add_library(mbgl-filesource STATIC

target_add_mason_package(mbgl-filesource PUBLIC geometry)
target_add_mason_package(mbgl-filesource PUBLIC variant)
target_add_mason_package(mbgl-filesource PUBLIC any)
target_add_mason_package(mbgl-filesource PRIVATE rapidjson)
target_add_mason_package(mbgl-filesource PRIVATE boost)
target_add_mason_package(mbgl-filesource PRIVATE geojson)
Expand Down
3 changes: 3 additions & 0 deletions cmake/test-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(MBGL_TEST_FILES
# api
test/api/annotations.test.cpp
test/api/api_misuse.test.cpp
test/api/custom_geometry_source.test.cpp
test/api/custom_layer.test.cpp
test/api/query.test.cpp
test/api/recycle_map.cpp
Expand Down Expand Up @@ -117,6 +118,7 @@ set(MBGL_TEST_FILES
test/text/quads.test.cpp

# tile
test/tile/custom_geometry_tile.test.cpp
test/tile/geojson_tile.test.cpp
test/tile/geometry_tile_data.test.cpp
test/tile/raster_tile.test.cpp
Expand Down Expand Up @@ -145,5 +147,6 @@ set(MBGL_TEST_FILES
test/util/tile_cover.test.cpp
test/util/timer.test.cpp
test/util/token.test.cpp
test/util/unique_any.test.cpp
test/util/url.test.cpp
)
1 change: 0 additions & 1 deletion cmake/test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ target_link_libraries(mbgl-test

target_add_mason_package(mbgl-test PRIVATE geometry)
target_add_mason_package(mbgl-test PRIVATE variant)
target_add_mason_package(mbgl-test PRIVATE any)
target_add_mason_package(mbgl-test PRIVATE unique_resource)
target_add_mason_package(mbgl-test PRIVATE rapidjson)
target_add_mason_package(mbgl-test PRIVATE gtest)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#pragma once

#include <mbgl/style/conversion.hpp>
#include <mbgl/style/sources/custom_geometry_source.hpp>

namespace mbgl {
namespace style {
namespace conversion {

template <>
struct Converter<CustomGeometrySource::Options> {

template <class V>
optional<CustomGeometrySource::Options> operator()(const V& value, Error& error) const {
CustomGeometrySource::Options options;

const auto minzoomValue = objectMember(value, "minzoom");
if (minzoomValue) {
if (toNumber(*minzoomValue)) {
options.zoomRange.min = static_cast<uint8_t>(*toNumber(*minzoomValue));
} else {
error = { "GeoJSON source minzoom value must be a number" };
return {};
}
}

const auto maxzoomValue = objectMember(value, "maxzoom");
if (maxzoomValue) {
if (toNumber(*maxzoomValue)) {
options.zoomRange.max = static_cast<uint8_t>(*toNumber(*maxzoomValue));
} else {
error = { "GeoJSON source maxzoom value must be a number" };
return {};
}
}

const auto bufferValue = objectMember(value, "buffer");
if (bufferValue) {
if (toNumber(*bufferValue)) {
options.tileOptions.buffer = static_cast<uint16_t>(*toNumber(*bufferValue));
} else {
error = { "GeoJSON source buffer value must be a number" };
return {};
}
}

const auto toleranceValue = objectMember(value, "tolerance");
if (toleranceValue) {
if (toNumber(*toleranceValue)) {
options.tileOptions.tolerance = static_cast<double>(*toNumber(*toleranceValue));
} else {
error = { "GeoJSON source tolerance value must be a number" };
return {};
}
}

return { options };
}

};

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

#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/any.hpp>
#include <mbgl/util/unique_any.hpp>
#include <mbgl/util/immutable.hpp>
#include <mbgl/style/layer_type.hpp>
#include <mbgl/style/types.hpp>
Expand Down Expand Up @@ -126,7 +126,7 @@ class Layer : public mbgl::util::noncopyable {
// For use in SDK bindings, which store a reference to a platform-native peer
// object here, so that separately-obtained references to this object share
// identical platform-native peers.
any peer;
util::unique_any peer;
};

} // namespace style
Expand Down
4 changes: 2 additions & 2 deletions include/mbgl/style/source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/any.hpp>
#include <mbgl/util/unique_any.hpp>
#include <mbgl/util/immutable.hpp>
#include <mbgl/style/types.hpp>

Expand Down Expand Up @@ -76,7 +76,7 @@ class Source : public mbgl::util::noncopyable {
// For use in SDK bindings, which store a reference to a platform-native peer
// object here, so that separately-obtained references to this object share
// identical platform-native peers.
any peer;
util::unique_any peer;
};

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

#include <mbgl/style/source.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/geojson.hpp>
#include <mbgl/util/range.hpp>
#include <mbgl/util/constants.hpp>

namespace mbgl {

class OverscaledTileID;
class CanonicalTileID;
template <class T>
class Actor;

namespace style {

using TileFunction = std::function<void(const CanonicalTileID&)>;

class CustomTileLoader;

class CustomGeometrySource : public Source {
public:
struct TileOptions {
double tolerance = 0.375;
uint16_t tileSize = util::tileSize;
uint16_t buffer = 128;
};

struct Options {
TileFunction fetchTileFunction;
TileFunction cancelTileFunction;
Range<uint8_t> zoomRange = { 0, 18};
TileOptions tileOptions;
};
public:
CustomGeometrySource(std::string id, CustomGeometrySource::Options options);
~CustomGeometrySource() final;
void loadDescription(FileSource&) final;
void setTileData(const CanonicalTileID&, const GeoJSON&);
void invalidateTile(const CanonicalTileID&);
void invalidateRegion(const LatLngBounds&);
// Private implementation
class Impl;
const Impl& impl() const;
private:
std::unique_ptr<Actor<CustomTileLoader>> loader;
};

template <>
inline bool Source::is<CustomGeometrySource>() const {
return getType() == SourceType::CustomVector;
}

} // namespace style
} // namespace mbgl
2 changes: 2 additions & 0 deletions include/mbgl/style/sources/geojson_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <mbgl/style/source.hpp>
#include <mbgl/util/geojson.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/constants.hpp>

namespace mbgl {

Expand All @@ -14,6 +15,7 @@ struct GeoJSONOptions {
// GeoJSON-VT options
uint8_t minzoom = 0;
uint8_t maxzoom = 18;
uint16_t tileSize = util::tileSize;
uint16_t buffer = 128;
double tolerance = 0.375;

Expand Down
3 changes: 2 additions & 1 deletion include/mbgl/style/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ enum class SourceType : uint8_t {
GeoJSON,
Video,
Annotations,
Image
Image,
CustomVector
};

enum class VisibilityType : bool {
Expand Down
10 changes: 0 additions & 10 deletions include/mbgl/util/any.hpp

This file was deleted.

Loading