[core] Share GeoJSONData pointer as weak_ptr instead of raw ptr
This commit is contained in:
@@ -33,23 +33,23 @@ void RenderGeoJSONSource::update(Immutable<style::Source::Impl> baseImpl_,
|
||||
|
||||
enabled = needsRendering;
|
||||
|
||||
GeoJSONData* data_ = impl().getData();
|
||||
auto data_ = impl().getData().lock();
|
||||
|
||||
if (data_ != data) {
|
||||
if (data.lock() != data_) {
|
||||
data = data_;
|
||||
tilePyramid.cache.clear();
|
||||
|
||||
if (data) {
|
||||
if (data_) {
|
||||
const uint8_t maxZ = impl().getZoomRange().max;
|
||||
for (const auto& pair : tilePyramid.tiles) {
|
||||
if (pair.first.canonical.z <= maxZ) {
|
||||
static_cast<GeoJSONTile*>(pair.second.get())->updateData(data->getTile(pair.first.canonical));
|
||||
static_cast<GeoJSONTile*>(pair.second.get())->updateData(data_->getTile(pair.first.canonical));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
if (!data_) {
|
||||
tilePyramid.tiles.clear();
|
||||
tilePyramid.renderTiles.clear();
|
||||
return;
|
||||
@@ -63,8 +63,8 @@ void RenderGeoJSONSource::update(Immutable<style::Source::Impl> baseImpl_,
|
||||
util::tileSize,
|
||||
impl().getZoomRange(),
|
||||
optional<LatLngBounds>{},
|
||||
[&] (const OverscaledTileID& tileID) {
|
||||
return std::make_unique<GeoJSONTile>(tileID, impl().id, parameters, data->getTile(tileID.canonical));
|
||||
[&, data_] (const OverscaledTileID& tileID) {
|
||||
return std::make_unique<GeoJSONTile>(tileID, impl().id, parameters, data_->getTile(tileID.canonical));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ private:
|
||||
const style::GeoJSONSource::Impl& impl() const;
|
||||
|
||||
TilePyramid tilePyramid;
|
||||
style::GeoJSONData* data = nullptr;
|
||||
std::weak_ptr<style::GeoJSONData> data;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@@ -75,7 +75,7 @@ GeoJSONSource::Impl::Impl(std::string id_, GeoJSONOptions options_)
|
||||
GeoJSONSource::Impl::Impl(const Impl& other, const GeoJSON& geoJSON)
|
||||
: Source::Impl(other),
|
||||
options(other.options) {
|
||||
double scale = util::EXTENT / util::tileSize;
|
||||
constexpr double scale = util::EXTENT / util::tileSize;
|
||||
|
||||
if (options.cluster
|
||||
&& geoJSON.is<mapbox::feature::feature_collection<double>>()
|
||||
@@ -84,7 +84,7 @@ GeoJSONSource::Impl::Impl(const Impl& other, const GeoJSON& geoJSON)
|
||||
clusterOptions.maxZoom = options.clusterMaxZoom;
|
||||
clusterOptions.extent = util::EXTENT;
|
||||
clusterOptions.radius = ::round(scale * options.clusterRadius);
|
||||
data = std::make_unique<SuperclusterData>(
|
||||
data = std::make_shared<SuperclusterData>(
|
||||
geoJSON.get<mapbox::feature::feature_collection<double>>(), clusterOptions);
|
||||
} else {
|
||||
mapbox::geojsonvt::Options vtOptions;
|
||||
@@ -93,7 +93,7 @@ GeoJSONSource::Impl::Impl(const Impl& other, const GeoJSON& geoJSON)
|
||||
vtOptions.buffer = ::round(scale * options.buffer);
|
||||
vtOptions.tolerance = scale * options.tolerance;
|
||||
vtOptions.lineMetrics = options.lineMetrics;
|
||||
data = std::make_unique<GeoJSONVTData>(geoJSON, vtOptions);
|
||||
data = std::make_shared<GeoJSONVTData>(geoJSON, vtOptions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,8 +103,8 @@ Range<uint8_t> GeoJSONSource::Impl::getZoomRange() const {
|
||||
return { options.minzoom, options.maxzoom };
|
||||
}
|
||||
|
||||
GeoJSONData* GeoJSONSource::Impl::getData() const {
|
||||
return data.get();
|
||||
std::weak_ptr<GeoJSONData> GeoJSONSource::Impl::getData() const {
|
||||
return data;
|
||||
}
|
||||
|
||||
optional<std::string> GeoJSONSource::Impl::getAttribution() const {
|
||||
|
||||
@@ -31,13 +31,13 @@ public:
|
||||
~Impl() final;
|
||||
|
||||
Range<uint8_t> getZoomRange() const;
|
||||
GeoJSONData* getData() const;
|
||||
std::weak_ptr<GeoJSONData> getData() const;
|
||||
|
||||
optional<std::string> getAttribution() const final;
|
||||
|
||||
private:
|
||||
GeoJSONOptions options;
|
||||
std::unique_ptr<GeoJSONData> data;
|
||||
std::shared_ptr<GeoJSONData> data;
|
||||
};
|
||||
|
||||
} // namespace style
|
||||
|
||||
Reference in New Issue
Block a user