diff options
Diffstat (limited to 'src/style/style.cpp')
-rw-r--r-- | src/style/style.cpp | 148 |
1 files changed, 5 insertions, 143 deletions
diff --git a/src/style/style.cpp b/src/style/style.cpp index c2794fed88..a08e77ac01 100644 --- a/src/style/style.cpp +++ b/src/style/style.cpp @@ -38,154 +38,14 @@ void Style::updateSources(const std::shared_ptr<StyleLayerGroup> &group) { } } -StyleProperties resetClassProperties(StyleLayer &layer) { - if (layer.layers) { - return CompositeProperties(); - } else if (layer.bucket) { - switch (layer.bucket->type) { - case BucketType::Fill: return FillProperties(); break; - case BucketType::Line: return LineProperties(); break; - case BucketType::Icon: return IconProperties(); break; - case BucketType::Text: return TextProperties(); break; - case BucketType::Raster: return RasterProperties(); break; - default: return std::false_type(); break; - } - } else { - return BackgroundProperties(); - } -} - -template <typename T> -void applyProperty(const ClassProperties &properties, PropertyKey key, T &target) { - auto it = properties.properties.find(key); - if (it != properties.properties.end()) { - const PropertyValue &value = it->second; - if (value.is<T>()) { - target = value.get<T>(); - } - } -} - -template <typename T> -void applyProperty(const ClassProperties &properties, PropertyKey key, T &target, float z) { - auto it = properties.properties.find(key); - if (it != properties.properties.end()) { - const PropertyValue &value = it->second; - if (value.is<FunctionProperty>()) { - target = value.get<FunctionProperty>().evaluate<T>(z); - } else if (value.is<bool>()) { - target = value.get<bool>(); - } - } -} - -void applyClassProperties(StyleProperties &style, const ClassProperties &properties, float z) { - if (style.is<FillProperties>()) { - FillProperties &fill = style.get<FillProperties>(); - applyProperty(properties, PropertyKey::FillEnabled, fill.enabled, z); - applyProperty(properties, PropertyKey::FillAntialias, fill.antialias, z); - applyProperty(properties, PropertyKey::FillOpacity, fill.opacity, z); - applyProperty(properties, PropertyKey::FillColor, fill.fill_color); - applyProperty(properties, PropertyKey::FillOutlineColor, fill.stroke_color); - applyProperty(properties, PropertyKey::FillTranslateX, fill.translate[0], z); - applyProperty(properties, PropertyKey::FillTranslateY, fill.translate[1], z); - applyProperty(properties, PropertyKey::FillTranslateAnchor, fill.translateAnchor); - applyProperty(properties, PropertyKey::FillImage, fill.image); - } else if (style.is<LineProperties>()) { - LineProperties &line = style.get<LineProperties>(); - applyProperty(properties, PropertyKey::LineEnabled, line.enabled, z); - applyProperty(properties, PropertyKey::LineOpacity, line.opacity, z); - applyProperty(properties, PropertyKey::LineColor, line.color); - applyProperty(properties, PropertyKey::LineTranslateX, line.translate[0], z); - applyProperty(properties, PropertyKey::LineTranslateY, line.translate[1], z); - applyProperty(properties, PropertyKey::LineTranslateAnchor, line.translateAnchor); - applyProperty(properties, PropertyKey::LineWidth, line.width, z); - applyProperty(properties, PropertyKey::LineOffset, line.offset, z); - applyProperty(properties, PropertyKey::LineBlur, line.blur, z); - applyProperty(properties, PropertyKey::LineDashLand, line.dash_array[0], z); - applyProperty(properties, PropertyKey::LineDashGap, line.dash_array[1], z); - applyProperty(properties, PropertyKey::LineImage, line.image); - } else if (style.is<IconProperties>()) { - IconProperties &icon = style.get<IconProperties>(); - applyProperty(properties, PropertyKey::IconEnabled, icon.enabled, z); - applyProperty(properties, PropertyKey::IconOpacity, icon.opacity, z); - applyProperty(properties, PropertyKey::IconRotate, icon.rotate, z); - applyProperty(properties, PropertyKey::IconRotateAnchor, icon.rotate_anchor); - } else if (style.is<TextProperties>()) { - TextProperties &text = style.get<TextProperties>(); - applyProperty(properties, PropertyKey::TextEnabled, text.enabled, z); - applyProperty(properties, PropertyKey::TextOpacity, text.opacity, z); - applyProperty(properties, PropertyKey::TextSize, text.size, z); - applyProperty(properties, PropertyKey::TextColor, text.color); - applyProperty(properties, PropertyKey::TextHaloColor, text.halo_color); - applyProperty(properties, PropertyKey::TextHaloWidth, text.halo_width, z); - applyProperty(properties, PropertyKey::TextHaloBlur, text.halo_blur, z); - } else if (style.is<CompositeProperties>()) { - CompositeProperties &composite = style.get<CompositeProperties>(); - applyProperty(properties, PropertyKey::CompositeEnabled, composite.enabled, z); - applyProperty(properties, PropertyKey::CompositeOpacity, composite.opacity, z); - } else if (style.is<RasterProperties>()) { - RasterProperties &raster = style.get<RasterProperties>(); - applyProperty(properties, PropertyKey::RasterEnabled, raster.enabled, z); - applyProperty(properties, PropertyKey::RasterOpacity, raster.opacity, z); - applyProperty(properties, PropertyKey::RasterSpin, raster.spin, z); - applyProperty(properties, PropertyKey::RasterBrightnessLow, raster.brightness[0], z); - applyProperty(properties, PropertyKey::RasterBrightnessHigh, raster.brightness[1], z); - applyProperty(properties, PropertyKey::RasterSaturation, raster.saturation, z); - applyProperty(properties, PropertyKey::RasterContrast, raster.contrast, z); - applyProperty(properties, PropertyKey::RasterFade, raster.fade, z); - } else if (style.is<BackgroundProperties>()) { - BackgroundProperties &background = style.get<BackgroundProperties>(); - applyProperty(properties, PropertyKey::BackgroundColor, background.color); - } -} - -void Style::updateProperties(const std::shared_ptr<StyleLayerGroup> &group, float z, timestamp t) { - if (!group) { - return; - } - - for (const std::shared_ptr<StyleLayer> &layer : group->layers) { - if (!layer) continue; - - if (layer->layers) { - updateProperties(layer->layers, z, t); - } - - // Accomodate for different tile size. - if (layer->bucket) { - const StyleBucket &bucket = *layer->bucket; - if (bucket.source) { - const Source &source = *bucket.source; - z += std::log(source.tile_size / 256.0f) / M_LN2; - } - } - - layer->style = resetClassProperties(*layer); - - // Apply default class (if exists) - auto default_it = layer->styles.find(ClassID::Default); - if (default_it != layer->styles.end()) { - applyClassProperties(layer->style, default_it->second, z); - } - - // Apply overriding classes in order. - for (const std::string &class_name : appliedClasses) { - const ClassID class_id = ClassDictionary::Lookup(class_name); - auto class_it = layer->styles.find(class_id); - if (class_it != layer->styles.end()) { - applyClassProperties(layer->style, class_it->second, z); - } - } - } -} - void Style::updateProperties(float z, timestamp t) { uv::writelock lock(mtx); updateSources(); - updateProperties(layers, z, t); + if (layers) { + layers->updateProperties(z, t); + } // Apply transitions after the first time. if (!initial_render_complete) { @@ -231,6 +91,8 @@ void Style::loadJSON(const uint8_t *const data) { parser.parse(const_cast<const rapidjson::Document &>(doc)); layers = parser.getLayers(); + + updateClasses(); } } |