Change StyleBucket::source to indirect reference

This eliminates a reference loop: VectorTileData holds StyleLayers which
hold StyleBuckets which held Sources which hold VectorTileDatas. This
breaks the StyleBucket -> Source link in favor of manually resolving the
reference where necessary.
This commit is contained in:
John Firebaugh
2015-06-17 14:08:40 -07:00
parent 0581df8787
commit fd58861fcd
6 changed files with 31 additions and 22 deletions

View File

@@ -57,6 +57,7 @@ void StyleParser::parse(JSVal document) {
// create point annotations symbol bucket
util::ptr<StyleBucket> pointBucket = std::make_shared<StyleBucket>(pointAnnotationsLayer->type);
pointBucket->name = pointAnnotationsLayer->id;
pointBucket->source = pointID;
pointBucket->source_layer = pointAnnotationsLayer->id;
// build up point annotations style
@@ -74,7 +75,6 @@ void StyleParser::parse(JSVal document) {
sources.emplace_back(pointAnnotationsSource);
pointAnnotationsSource->info.type = SourceType::Annotations;
pointAnnotationsSource->info.source_id = pointID;
pointBucket->source = pointAnnotationsSource;
pointAnnotationsLayer->bucket = pointBucket;
}
@@ -231,6 +231,7 @@ void StyleParser::parseSources(JSVal value) {
parseRenderProperty<SourceTypeClass>(itr->value, source->info.type, "type");
parseRenderProperty(itr->value, source->info.url, "url");
parseRenderProperty(itr->value, source->info.tile_size, "tileSize");
source->info.source_id = name;
source->info.parseTileJSONProperties(itr->value);
sources.emplace_back(source);
sourcesMap.emplace(name, source);
@@ -947,12 +948,10 @@ void StyleParser::parseBucket(JSVal value, util::ptr<StyleLayer> &layer) {
if (value.HasMember("source")) {
JSVal value_source = replaceConstant(value["source"]);
if (value_source.IsString()) {
const std::string source_name = { value_source.GetString(), value_source.GetStringLength() };
auto source_it = sourcesMap.find(source_name);
if (source_it != sourcesMap.end()) {
bucket->source = source_it->second;
} else {
Log::Warning(Event::ParseStyle, "can't find source '%s' required for layer '%s'", source_name.c_str(), layer->id.c_str());
bucket->source = { value_source.GetString(), value_source.GetStringLength() };
auto source_it = sourcesMap.find(bucket->source);
if (source_it == sourcesMap.end()) {
Log::Warning(Event::ParseStyle, "can't find source '%s' required for layer '%s'", bucket->source.c_str(), layer->id.c_str());
}
} else {
Log::Warning(Event::ParseStyle, "source of layer '%s' must be a string", layer->id.c_str());