add methods getTiles and setTiles to mimick maplibre-gl-js interface (#149)
This commit is contained in:
@@ -26,6 +26,14 @@ public:
|
||||
|
||||
void loadDescription(FileSource&) final;
|
||||
|
||||
/// @brief Gets the tile urls for this vector source.
|
||||
/// @return List of tile urls.
|
||||
const std::vector<std::string> getTiles() const;
|
||||
|
||||
/// @brief Sets the tile urls for this vector source.
|
||||
/// @param tiles List of tile urls.
|
||||
void setTiles(const std::vector<std::string>& tiles);
|
||||
|
||||
bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const override;
|
||||
|
||||
mapbox::base::WeakPtr<Source> makeWeakPtr() override { return weakFactory.makeWeakPtr(); }
|
||||
|
||||
@@ -92,6 +92,25 @@ void VectorSource::loadDescription(FileSource& fileSource) {
|
||||
});
|
||||
}
|
||||
|
||||
const std::vector<std::string> VectorSource::getTiles() const {
|
||||
auto tileset = impl().tileset;
|
||||
if (tileset.has_value()) {
|
||||
return tileset->tiles;
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
void VectorSource::setTiles(const std::vector<std::string>& tiles) {
|
||||
auto& tileset = impl().tileset;
|
||||
if (!tileset.has_value()) return;
|
||||
if (tileset->tiles == tiles) return;
|
||||
Tileset newtileset(*tileset);
|
||||
newtileset.tiles = tiles;
|
||||
baseImpl = makeMutable<Impl>(impl(), newtileset);
|
||||
observer->onSourceChanged(*this);
|
||||
}
|
||||
|
||||
bool VectorSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) const {
|
||||
return mbgl::underlying_type(Tile::Kind::Geometry) == mbgl::underlying_type(info->tileKind);
|
||||
}
|
||||
|
||||
@@ -919,6 +919,50 @@ TEST(Source, RenderTileSetSourceUpdate) {
|
||||
renderSource->update(uninitialized.baseImpl, layers, true, true, test.tileParameters());
|
||||
}
|
||||
|
||||
TEST(Source, VectorSourceSetTiles) {
|
||||
SourceTest test;
|
||||
test.styleObserver.sourceChanged = [&](Source& source) {
|
||||
EXPECT_EQ(source.as<VectorSource>()->getTiles(), std::vector<std::string>{"new"});
|
||||
test.end();
|
||||
};
|
||||
|
||||
VectorSource source("source", Tileset{{"url"}});
|
||||
source.setObserver(&test.styleObserver);
|
||||
source.setTiles({"unused"}); // make sure early setTiles does not segfault
|
||||
source.loadDescription(*test.fileSource);
|
||||
EXPECT_EQ(source.as<VectorSource>()->getTiles(), std::vector<std::string>{"url"});
|
||||
source.setTiles({"new"});
|
||||
test.run();
|
||||
}
|
||||
|
||||
TEST(Source, VectorSourceUrlSetTiles) {
|
||||
SourceTest test;
|
||||
test.styleObserver.sourceLoaded = [&](Source& source) {
|
||||
EXPECT_EQ(source.as<VectorSource>()->getTiles(), std::vector<std::string>{"tiles"});
|
||||
source.as<VectorSource>()->setTiles({"new"});
|
||||
};
|
||||
int count = 0;
|
||||
test.styleObserver.sourceChanged = [&](Source& source) {
|
||||
if (count++) {
|
||||
EXPECT_EQ(source.as<VectorSource>()->getTiles(), std::vector<std::string>{"new"});
|
||||
test.end();
|
||||
}
|
||||
};
|
||||
|
||||
test.fileSource->sourceResponse = [&](const Resource& resource) {
|
||||
EXPECT_EQ("url", resource.url);
|
||||
Response response;
|
||||
response.data = std::make_unique<std::string>(R"({"tiles": ["tiles"]})");
|
||||
return response;
|
||||
};
|
||||
|
||||
VectorSource source("source", "url");
|
||||
source.setObserver(&test.styleObserver);
|
||||
source.setTiles({"unused"});
|
||||
source.loadDescription(*test.fileSource);
|
||||
test.run();
|
||||
}
|
||||
|
||||
TEST(Source, GeoJSONSourceTilesAfterDataReset) {
|
||||
SourceTest test;
|
||||
GeoJSONSource source("source");
|
||||
|
||||
Reference in New Issue
Block a user