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

6264 mutable geojson #6347

Merged
merged 1 commit into from
Sep 20, 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
2 changes: 1 addition & 1 deletion src/mbgl/style/source_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class Source::Impl : public TileObserver, private util::noncopyable {

Source& base;
SourceObserver* observer = nullptr;
std::map<OverscaledTileID, std::unique_ptr<Tile>> tiles;

private:
// TileObserver implementation.
Expand All @@ -93,7 +94,6 @@ class Source::Impl : public TileObserver, private util::noncopyable {
virtual Range<uint8_t> getZoomRange() = 0;
virtual std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) = 0;

std::map<OverscaledTileID, std::unique_ptr<Tile>> tiles;
std::map<UnwrappedTileID, RenderTile> renderTiles;
TileCache cache;
};
Expand Down
35 changes: 21 additions & 14 deletions src/mbgl/style/sources/geojson_source_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ void GeoJSONSource::Impl::setGeoJSON(const GeoJSON& geoJSON) {
geoJSONOrSupercluster =
std::make_unique<mapbox::supercluster::Supercluster>(features, clusterOptions);
}

for (auto const &item : tiles) {
GeoJSONTile* geoJSONTile = static_cast<GeoJSONTile*>(item.second.get());
setTileData(*geoJSONTile, geoJSONTile->id);
}
}

void GeoJSONSource::Impl::setTileData(GeoJSONTile& tile, const OverscaledTileID& tileID) {
if (geoJSONOrSupercluster.is<GeoJSONVTPointer>()) {
tile.updateData(geoJSONOrSupercluster.get<GeoJSONVTPointer>()->getTile(tileID.canonical.z,
tileID.canonical.x,
tileID.canonical.y).features);
} else {
assert(geoJSONOrSupercluster.is<SuperclusterPointer>());
tile.updateData(geoJSONOrSupercluster.get<SuperclusterPointer>()->getTile(tileID.canonical.z,
tileID.canonical.x,
tileID.canonical.y));
}
}

void GeoJSONSource::Impl::loadDescription(FileSource& fileSource) {
Expand Down Expand Up @@ -126,20 +144,9 @@ Range<uint8_t> GeoJSONSource::Impl::getZoomRange() {
std::unique_ptr<Tile> GeoJSONSource::Impl::createTile(const OverscaledTileID& tileID,
const UpdateParameters& parameters) {
assert(loaded);
if (geoJSONOrSupercluster.is<GeoJSONVTPointer>()) {
return std::make_unique<GeoJSONTile>(tileID, base.getID(), parameters,
geoJSONOrSupercluster.get<GeoJSONVTPointer>()->getTile(
tileID.canonical.z,
tileID.canonical.x,
tileID.canonical.y).features);
} else {
assert(geoJSONOrSupercluster.is<SuperclusterPointer>());
return std::make_unique<GeoJSONTile>(tileID, base.getID(), parameters,
geoJSONOrSupercluster.get<SuperclusterPointer>()->getTile(
tileID.canonical.z,
tileID.canonical.x,
tileID.canonical.y));
}
auto tilePointer = std::make_unique<GeoJSONTile>(tileID, base.getID(), parameters);
setTileData(*tilePointer.get(), tileID);
return std::move(tilePointer);
}

} // namespace style
Expand Down
2 changes: 2 additions & 0 deletions src/mbgl/style/sources/geojson_source_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/sources/geojson_source.hpp>
#include <mbgl/util/variant.hpp>
#include <mbgl/tile/geojson_tile.hpp>

namespace mbgl {

Expand All @@ -19,6 +20,7 @@ class GeoJSONSource::Impl : public Source::Impl {
optional<std::string> getURL();

void setGeoJSON(const GeoJSON&);
void setTileData(GeoJSONTile&, const OverscaledTileID& tileID);

void loadDescription(FileSource&) final;

Expand Down
6 changes: 4 additions & 2 deletions src/mbgl/tile/geojson_tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ class GeoJSONTileData : public GeometryTileData,

GeoJSONTile::GeoJSONTile(const OverscaledTileID& overscaledTileID,
std::string sourceID_,
const style::UpdateParameters& parameters,
const mapbox::geometry::feature_collection<int16_t>& features)
const style::UpdateParameters& parameters)
: GeometryTile(overscaledTileID, sourceID_, parameters) {
}

void GeoJSONTile::updateData(const mapbox::geometry::feature_collection<int16_t>& features) {
setData(std::make_unique<GeoJSONTileData>(features));
}

Expand Down
5 changes: 3 additions & 2 deletions src/mbgl/tile/geojson_tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class GeoJSONTile : public GeometryTile {
public:
GeoJSONTile(const OverscaledTileID&,
std::string sourceID,
const style::UpdateParameters&,
const mapbox::geometry::feature_collection<int16_t>&);
const style::UpdateParameters&);

void updateData(const mapbox::geometry::feature_collection<int16_t>&);

void setNecessity(Necessity) final;
};

Expand Down