[core] Make CustomGeometrySource::TileOptions immutable
This commit is contained in:
@@ -4,27 +4,20 @@
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
|
||||
CustomGeometrySource::Impl::Impl(std::string id_,
|
||||
const CustomGeometrySource::Options options)
|
||||
CustomGeometrySource::Impl::Impl(std::string id_, CustomGeometrySource::Options options)
|
||||
: Source::Impl(SourceType::CustomVector, std::move(id_)),
|
||||
tileOptions(options.tileOptions),
|
||||
tileOptions(makeMutable<CustomGeometrySource::TileOptions>(options.tileOptions)),
|
||||
zoomRange(options.zoomRange),
|
||||
loaderRef({}) {
|
||||
}
|
||||
loaderRef({}) {}
|
||||
|
||||
CustomGeometrySource::Impl::Impl(const Impl& impl, ActorRef<CustomTileLoader> loaderRef_)
|
||||
: Source::Impl(impl),
|
||||
tileOptions(impl.tileOptions),
|
||||
zoomRange(impl.zoomRange),
|
||||
loaderRef(loaderRef_){
|
||||
|
||||
}
|
||||
: Source::Impl(impl), tileOptions(impl.tileOptions), zoomRange(impl.zoomRange), loaderRef(loaderRef_) {}
|
||||
|
||||
optional<std::string> CustomGeometrySource::Impl::getAttribution() const {
|
||||
return {};
|
||||
}
|
||||
|
||||
CustomGeometrySource::TileOptions CustomGeometrySource::Impl::getTileOptions() const {
|
||||
Immutable<CustomGeometrySource::TileOptions> CustomGeometrySource::Impl::getTileOptions() const {
|
||||
return tileOptions;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,12 +15,12 @@ public:
|
||||
|
||||
optional<std::string> getAttribution() const final;
|
||||
|
||||
CustomGeometrySource::TileOptions getTileOptions() const;
|
||||
Immutable<CustomGeometrySource::TileOptions> getTileOptions() const;
|
||||
Range<uint8_t> getZoomRange() const;
|
||||
optional<ActorRef<CustomTileLoader>> getTileLoader() const;
|
||||
|
||||
private:
|
||||
CustomGeometrySource::TileOptions tileOptions;
|
||||
Immutable<CustomGeometrySource::TileOptions> tileOptions;
|
||||
Range<uint8_t> zoomRange;
|
||||
optional<ActorRef<CustomTileLoader>> loaderRef;
|
||||
};
|
||||
|
||||
@@ -13,17 +13,16 @@
|
||||
namespace mbgl {
|
||||
|
||||
CustomGeometryTile::CustomGeometryTile(const OverscaledTileID& overscaledTileID,
|
||||
std::string sourceID_,
|
||||
const TileParameters& parameters,
|
||||
const style::CustomGeometrySource::TileOptions options_,
|
||||
ActorRef<style::CustomTileLoader> loader_)
|
||||
std::string sourceID_,
|
||||
const TileParameters& parameters,
|
||||
Immutable<style::CustomGeometrySource::TileOptions> options_,
|
||||
ActorRef<style::CustomTileLoader> loader_)
|
||||
: GeometryTile(overscaledTileID, sourceID_, parameters),
|
||||
necessity(TileNecessity::Optional),
|
||||
options(options_),
|
||||
loader(std::move(loader_)),
|
||||
mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())),
|
||||
actorRef(*this, mailbox) {
|
||||
}
|
||||
necessity(TileNecessity::Optional),
|
||||
options(std::move(options_)),
|
||||
loader(std::move(loader_)),
|
||||
mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())),
|
||||
actorRef(*this, mailbox) {}
|
||||
|
||||
CustomGeometryTile::~CustomGeometryTile() {
|
||||
loader.invoke(&style::CustomTileLoader::removeTile, id);
|
||||
@@ -33,15 +32,16 @@ void CustomGeometryTile::setTileData(const GeoJSON& geoJSON) {
|
||||
|
||||
auto featureData = mapbox::feature::feature_collection<int16_t>();
|
||||
if (geoJSON.is<FeatureCollection>() && !geoJSON.get<FeatureCollection>().empty()) {
|
||||
const double scale = util::EXTENT / options.tileSize;
|
||||
const double scale = util::EXTENT / options->tileSize;
|
||||
|
||||
mapbox::geojsonvt::TileOptions vtOptions;
|
||||
vtOptions.extent = util::EXTENT;
|
||||
vtOptions.buffer = ::round(scale * options.buffer);
|
||||
vtOptions.tolerance = scale * options.tolerance;
|
||||
featureData = mapbox::geojsonvt::geoJSONToTile(geoJSON,
|
||||
id.canonical.z, id.canonical.x, id.canonical.y,
|
||||
vtOptions, options.wrap, options.clip).features;
|
||||
vtOptions.buffer = ::round(scale * options->buffer);
|
||||
vtOptions.tolerance = scale * options->tolerance;
|
||||
featureData =
|
||||
mapbox::geojsonvt::geoJSONToTile(
|
||||
geoJSON, id.canonical.z, id.canonical.x, id.canonical.y, vtOptions, options->wrap, options->clip)
|
||||
.features;
|
||||
}
|
||||
setData(std::make_unique<GeoJSONTileData>(std::move(featureData)));
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@ class CustomTileLoader;
|
||||
class CustomGeometryTile: public GeometryTile {
|
||||
public:
|
||||
CustomGeometryTile(const OverscaledTileID&,
|
||||
std::string sourceID,
|
||||
const TileParameters&,
|
||||
const style::CustomGeometrySource::TileOptions,
|
||||
ActorRef<style::CustomTileLoader> loader);
|
||||
std::string sourceID,
|
||||
const TileParameters&,
|
||||
Immutable<style::CustomGeometrySource::TileOptions>,
|
||||
ActorRef<style::CustomTileLoader> loader);
|
||||
~CustomGeometryTile() override;
|
||||
|
||||
void setTileData(const GeoJSON& data);
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
private:
|
||||
bool stale = true;
|
||||
TileNecessity necessity;
|
||||
const style::CustomGeometrySource::TileOptions options;
|
||||
Immutable<style::CustomGeometrySource::TileOptions> options;
|
||||
ActorRef<style::CustomTileLoader> loader;
|
||||
std::shared_ptr<Mailbox> mailbox;
|
||||
ActorRef<CustomGeometryTile> actorRef;
|
||||
|
||||
@@ -61,8 +61,11 @@ TEST(CustomGeometryTile, InvokeFetchTile) {
|
||||
auto mb =std::make_shared<Mailbox>(*Scheduler::GetCurrent());
|
||||
ActorRef<CustomTileLoader> loaderActor(loader, mb);
|
||||
|
||||
CustomGeometryTile tile(OverscaledTileID(0, 0, 0), "source", test.tileParameters, CustomGeometrySource::TileOptions(),
|
||||
loaderActor);
|
||||
CustomGeometryTile tile(OverscaledTileID(0, 0, 0),
|
||||
"source",
|
||||
test.tileParameters,
|
||||
makeMutable<CustomGeometrySource::TileOptions>(),
|
||||
loaderActor);
|
||||
|
||||
tile.setNecessity(TileNecessity::Required);
|
||||
|
||||
@@ -86,8 +89,11 @@ TEST(CustomGeometryTile, InvokeCancelTile) {
|
||||
auto mb =std::make_shared<Mailbox>(*Scheduler::GetCurrent());
|
||||
ActorRef<CustomTileLoader> loaderActor(loader, mb);
|
||||
|
||||
CustomGeometryTile tile(OverscaledTileID(0, 0, 0), "source", test.tileParameters, CustomGeometrySource::TileOptions(),
|
||||
loaderActor);
|
||||
CustomGeometryTile tile(OverscaledTileID(0, 0, 0),
|
||||
"source",
|
||||
test.tileParameters,
|
||||
makeMutable<CustomGeometrySource::TileOptions>(),
|
||||
loaderActor);
|
||||
|
||||
tile.setNecessity(TileNecessity::Required);
|
||||
tile.setNecessity(TileNecessity::Optional);
|
||||
@@ -108,8 +114,11 @@ TEST(CustomGeometryTile, InvokeTileChanged) {
|
||||
auto mb =std::make_shared<Mailbox>(*Scheduler::GetCurrent());
|
||||
ActorRef<CustomTileLoader> loaderActor(loader, mb);
|
||||
|
||||
CustomGeometryTile tile(OverscaledTileID(0, 0, 0), "source", test.tileParameters, CustomGeometrySource::TileOptions(),
|
||||
loaderActor);
|
||||
CustomGeometryTile tile(OverscaledTileID(0, 0, 0),
|
||||
"source",
|
||||
test.tileParameters,
|
||||
makeMutable<CustomGeometrySource::TileOptions>(),
|
||||
loaderActor);
|
||||
|
||||
Immutable<LayerProperties> layerProperties = makeMutable<CircleLayerProperties>(staticImmutableCast<CircleLayer::Impl>(layer.baseImpl));
|
||||
StubTileObserver observer;
|
||||
|
||||
Reference in New Issue
Block a user