Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tile fallback #2119

Closed
wants to merge 4 commits into from
Closed
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
8 changes: 7 additions & 1 deletion core/include/tangram/data/clientDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,17 @@ class ClientDataSource : public TileSource {

void addPointFeature(Properties&& properties, LngLat coordinates);

void addPolylineFeature(Properties&& properties, PolylineBuilder&& polyline);
uint64_t addPolylineFeature(Properties&& properties, PolylineBuilder&& polyline);

void addPolygonFeature(Properties&& properties, PolygonBuilder
&& polygon);

void updatePolylineFeature(uint64_t id, const Coordinates& coordinates);

void updatePolylineFeature(uint64_t id, const Properties&& properties);

void removePolylineFeature(uint64_t id);

// Transform added feature data into tiles.
void generateTiles();

Expand Down
4 changes: 4 additions & 0 deletions core/include/tangram/data/tileSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class TileSource : public std::enable_shared_from_this<TileSource> {
struct DataSource {
virtual ~DataSource() {}

virtual TileID getFallbackTileID(const TileID& _tileID, int32_t _maxZoom, int32_t _zoomBias) = 0;

virtual bool loadTileData(std::shared_ptr<TileTask> _task, TileTaskCb _cb) = 0;

/* Stops any running I/O tasks pertaining to @_tile */
Expand Down Expand Up @@ -92,6 +94,8 @@ class TileSource : public std::enable_shared_from_this<TileSource> {
*/
virtual const char* mimeType() const;

TileID getFallbackTileID(const TileID& _tileID);

/* Fetches data for the map tile specified by @_tileID
*
* LoadTile starts an asynchronous I/O task to retrieve the data for a tile. When
Expand Down
69 changes: 66 additions & 3 deletions core/src/data/clientDataSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct ClientDataSource::Storage {
std::unique_ptr<geojsonvt::GeoJSONVT> tiles;
geometry::feature_collection<double> features;
std::vector<Properties> properties;
std::map<uint64_t, uint64_t> polylineIds;
};

struct ClientDataSource::PolylineBuilderData : mapbox::geometry::line_string<double> {
Expand Down Expand Up @@ -260,14 +261,21 @@ void ClientDataSource::addPointFeature(Properties&& properties, LngLat coordinat
m_store->properties.emplace_back(properties);
}

void ClientDataSource::addPolylineFeature(Properties&& properties, PolylineBuilder&& polyline) {
uint64_t ClientDataSource::addPolylineFeature(Properties&& properties, PolylineBuilder&& polyline) {

std::lock_guard<std::mutex> lock(m_mutexStore);

uint64_t id = m_store->features.size();
uint64_t i = m_store->features.size();
uint64_t id = m_store->polylineIds.size();

properties.set("id", std::to_string(id));

auto geom = std::move(polyline.data);
m_store->features.emplace_back(*geom, id);
m_store->features.emplace_back(*geom, i);
m_store->properties.emplace_back(properties);
m_store->polylineIds.insert(std::pair<uint64_t, uint64_t>(id, i));

return id;
}

void ClientDataSource::addPolygonFeature(Properties&& properties, PolygonBuilder&& polygon) {
Expand All @@ -280,6 +288,61 @@ void ClientDataSource::addPolygonFeature(Properties&& properties, PolygonBuilder
m_store->properties.emplace_back(properties);
}

void ClientDataSource::updatePolylineFeature(uint64_t id, const Coordinates& coordinates) {

std::lock_guard<std::mutex> lock(m_mutexStore);

std::map<uint64_t, uint64_t>::iterator findIt = m_store->polylineIds.find(id);

if (findIt != m_store->polylineIds.end() && findIt->second < m_store->features.size()) {
uint64_t i = findIt->second;

geometry::line_string<double> geom;
for (auto &p : coordinates) {
geom.emplace_back(p.longitude, p.latitude);
}

m_store->features[i] = mapbox::geometry::feature<double>(geom, i);
}
}

void ClientDataSource::updatePolylineFeature(uint64_t id, const Properties&& properties) {

std::lock_guard<std::mutex> lock(m_mutexStore);

std::map<uint64_t, uint64_t>::iterator findIt = m_store->polylineIds.find(id);

if (findIt != m_store->polylineIds.end() && findIt->second < m_store->properties.size()) {
uint64_t i = findIt->second;

for (int j = 0; j < properties.items().size(); ++j) {
m_store->properties[i].set(properties.items()[j].key,
properties.getString(properties.items()[j].key));
}
}
}

void ClientDataSource::removePolylineFeature(uint64_t id) {

std::lock_guard<std::mutex> lock(m_mutexStore);

std::map<uint64_t, uint64_t>::iterator findIt = m_store->polylineIds.find(id);

if (findIt != m_store->polylineIds.end() && findIt->second < m_store->features.size()) {
uint64_t i = findIt->second;

m_store->features.erase(std::next(m_store->features.begin(), i));
m_store->properties.erase(std::next(m_store->properties.begin(), i));

for (std::map<uint64_t, uint64_t>::iterator it = m_store->polylineIds.begin(); it != m_store->polylineIds.end(); ++it) {
if (it->second > i) {
it->second = it->second - 1;
m_store->features[it->second].id = it->second;
}
}
}
}

struct add_geometry {

static constexpr double extent = 4096.0;
Expand Down
Loading