diff options
Diffstat (limited to 'src/mbgl/layer/symbol_layer.cpp')
-rw-r--r-- | src/mbgl/layer/symbol_layer.cpp | 169 |
1 files changed, 83 insertions, 86 deletions
diff --git a/src/mbgl/layer/symbol_layer.cpp b/src/mbgl/layer/symbol_layer.cpp index 1e06a3ea71..932e500c5e 100644 --- a/src/mbgl/layer/symbol_layer.cpp +++ b/src/mbgl/layer/symbol_layer.cpp @@ -16,45 +16,45 @@ std::unique_ptr<StyleLayer> SymbolLayer::clone() const { } void SymbolLayer::parseLayout(const JSVal& value) { - parseProperty<Function<PlacementType>>("symbol-placement", PropertyKey::SymbolPlacement, layout, value); - parseProperty<Function<float>>("symbol-spacing", PropertyKey::SymbolSpacing, layout, value); - parseProperty<Function<bool>>("symbol-avoid-edges", PropertyKey::SymbolAvoidEdges, layout, value); - parseProperty<Function<bool>>("icon-allow-overlap", PropertyKey::IconAllowOverlap, layout, value); - parseProperty<Function<bool>>("icon-ignore-placement", PropertyKey::IconIgnorePlacement, layout, value); - parseProperty<Function<bool>>("icon-optional", PropertyKey::IconOptional, layout, value); - parseProperty<Function<RotationAlignmentType>>("icon-rotation-alignment", PropertyKey::IconRotationAlignment, layout, value); - parseProperty<Function<float>>("icon-size", PropertyKey::IconSize, layout, value); - parseProperty<Function<std::string>>("icon-image", PropertyKey::IconImage, layout, value); - parseProperty<Function<float>>("icon-rotate", PropertyKey::IconRotate, layout, value); - parseProperty<Function<float>>("icon-padding", PropertyKey::IconPadding, layout, value); - parseProperty<Function<bool>>("icon-keep-upright", PropertyKey::IconKeepUpright, layout, value); - parseProperty<Function<std::array<float, 2>>>("icon-offset", PropertyKey::IconOffset, layout, value); - parseProperty<Function<RotationAlignmentType>>("text-rotation-alignment", PropertyKey::TextRotationAlignment, layout, value); - parseProperty<Function<std::string>>("text-field", PropertyKey::TextField, layout, value); - parseProperty<Function<std::string>>("text-font", PropertyKey::TextFont, layout, value); - parseProperty<Function<float>>("text-size", PropertyKey::TextSize, layout, value); - parseProperty<Function<float>>("text-max-width", PropertyKey::TextMaxWidth, layout, value); - parseProperty<Function<float>>("text-line-height", PropertyKey::TextLineHeight, layout, value); - parseProperty<Function<float>>("text-letter-spacing", PropertyKey::TextLetterSpacing, layout, value); - parseProperty<Function<TextJustifyType>>("text-justify", PropertyKey::TextJustify, layout, value); - parseProperty<Function<TextAnchorType>>("text-anchor", PropertyKey::TextAnchor, layout, value); - parseProperty<Function<float>>("text-max-angle", PropertyKey::TextMaxAngle, layout, value); - parseProperty<Function<float>>("text-rotate", PropertyKey::TextRotate, layout, value); - parseProperty<Function<float>>("text-padding", PropertyKey::TextPadding, layout, value); - parseProperty<Function<bool>>("text-keep-upright", PropertyKey::TextKeepUpright, layout, value); - parseProperty<Function<TextTransformType>>("text-transform", PropertyKey::TextTransform, layout, value); - parseProperty<Function<std::array<float, 2>>>("text-offset", PropertyKey::TextOffset, layout, value); - parseProperty<Function<bool>>("text-allow-overlap", PropertyKey::TextAllowOverlap, layout, value); - parseProperty<Function<bool>>("text-ignore-placement", PropertyKey::TextIgnorePlacement, layout, value); - parseProperty<Function<bool>>("text-optional", PropertyKey::TextOptional, layout, value); + layout.placement.parse("symbol-placement", value); + layout.spacing.parse("symbol-spacing", value); + layout.avoidEdges.parse("symbol-avoid-edges", value); + + layout.icon.allowOverlap.parse("icon-allow-overlap", value); + layout.icon.ignorePlacement.parse("icon-ignore-placement", value); + layout.icon.optional.parse("icon-optional", value); + layout.icon.rotationAlignment.parse("icon-rotation-alignment", value); + layout.icon.size.parse("icon-size", value); + layout.icon.image.parse("icon-image", value); + layout.icon.rotate.parse("icon-rotate", value); + layout.icon.padding.parse("icon-padding", value); + layout.icon.keepUpright.parse("icon-keep-upright", value); + layout.icon.offset.parse("icon-offset", value); + + layout.text.rotationAlignment.parse("text-rotation-alignment", value); + layout.text.field.parse("text-field", value); + layout.text.font.parse("text-font", value); + layout.text.size.parse("text-size", value); + layout.text.maxWidth.parse("text-max-width", value); + layout.text.lineHeight.parse("text-line-height", value); + layout.text.letterSpacing.parse("text-letter-spacing", value); + layout.text.justify.parse("text-justify", value); + layout.text.anchor.parse("text-anchor", value); + layout.text.maxAngle.parse("text-max-angle", value); + layout.text.rotate.parse("text-rotate", value); + layout.text.padding.parse("text-padding", value); + layout.text.keepUpright.parse("text-keep-upright", value); + layout.text.transform.parse("text-transform", value); + layout.text.offset.parse("text-offset", value); + layout.text.allowOverlap.parse("text-allow-overlap", value); + layout.text.ignorePlacement.parse("text-ignore-placement", value); + layout.text.optional.parse("text-optional", value); } void SymbolLayer::parsePaints(const JSVal& layer) { paints.parseEach(layer, [&] (ClassProperties& paint, const JSVal& value) { parseProperty<Function<float>>("icon-opacity", PropertyKey::IconOpacity, paint, value); parseProperty<PropertyTransition>("icon-opacity-transition", PropertyKey::IconOpacity, paint, value); - parseProperty<Function<float>>("icon-size", PropertyKey::IconSize, paint, value); - parseProperty<PropertyTransition>("icon-size-transition", PropertyKey::IconSize, paint, value); parseProperty<Function<Color>>("icon-color", PropertyKey::IconColor, paint, value); parseProperty<PropertyTransition>("icon-color-transition", PropertyKey::IconColor, paint, value); parseProperty<Function<Color>>("icon-halo-color", PropertyKey::IconHaloColor, paint, value); @@ -69,8 +69,6 @@ void SymbolLayer::parsePaints(const JSVal& layer) { parseProperty<Function<float>>("text-opacity", PropertyKey::TextOpacity, paint, value); parseProperty<PropertyTransition>("text-opacity-transition", PropertyKey::TextOpacity, paint, value); - parseProperty<Function<float>>("text-size", PropertyKey::TextSize, paint, value); - parseProperty<PropertyTransition>("text-size-transition", PropertyKey::TextSize, paint, value); parseProperty<Function<Color>>("text-color", PropertyKey::TextColor, paint, value); parseProperty<PropertyTransition>("text-color-transition", PropertyKey::TextColor, paint, value); parseProperty<Function<Color>>("text-halo-color", PropertyKey::TextHaloColor, paint, value); @@ -113,64 +111,63 @@ void SymbolLayer::recalculate(const StyleCalculationParameters& parameters) { paints.calculate(PropertyKey::TextTranslateAnchor, properties.text.translate_anchor, parameters); // text-size and icon-size are layout properties but they also need to be evaluated as paint properties: - auto it = layout.properties.find(PropertyKey::IconSize); - if (it != layout.properties.end()) { - const PropertyEvaluator<float> evaluator(parameters); - properties.icon.size = mapbox::util::apply_visitor(evaluator, it->second); - } - it = layout.properties.find(PropertyKey::TextSize); - if (it != layout.properties.end()) { - const PropertyEvaluator<float> evaluator(parameters); - properties.text.size = mapbox::util::apply_visitor(evaluator, it->second); - } + layout.icon.size.calculate(parameters); + layout.text.size.calculate(parameters); + properties.icon.size = layout.icon.size; + properties.text.size = layout.text.size; passes = properties.isVisible() ? RenderPass::Translucent : RenderPass::None; } std::unique_ptr<Bucket> SymbolLayer::createBucket(StyleBucketParameters& parameters) const { - const float z = parameters.tileID.z; - auto bucket = std::make_unique<SymbolBucket>(parameters.tileID.overscaling, z); + auto bucket = std::make_unique<SymbolBucket>(parameters.tileID.overscaling, + parameters.tileID.z); + + bucket->layout = layout; - layout.calculate(PropertyKey::SymbolPlacement, bucket->layout.placement, z); - if (bucket->layout.placement == PlacementType::Line) { - bucket->layout.icon.rotation_alignment = RotationAlignmentType::Map; - bucket->layout.text.rotation_alignment = RotationAlignmentType::Map; + StyleCalculationParameters p(parameters.tileID.z); + bucket->layout.placement.calculate(p); + if (bucket->layout.placement.value == PlacementType::Line) { + bucket->layout.icon.rotationAlignment = RotationAlignmentType::Map; + bucket->layout.text.rotationAlignment = RotationAlignmentType::Map; }; - layout.calculate(PropertyKey::SymbolSpacing, bucket->layout.spacing, z); - layout.calculate(PropertyKey::SymbolAvoidEdges, bucket->layout.avoid_edges, z); - - layout.calculate(PropertyKey::IconAllowOverlap, bucket->layout.icon.allow_overlap, z); - layout.calculate(PropertyKey::IconIgnorePlacement, bucket->layout.icon.ignore_placement, z); - layout.calculate(PropertyKey::IconOptional, bucket->layout.icon.optional, z); - layout.calculate(PropertyKey::IconRotationAlignment, bucket->layout.icon.rotation_alignment, z); - layout.calculate(PropertyKey::IconImage, bucket->layout.icon.image, z); - layout.calculate(PropertyKey::IconPadding, bucket->layout.icon.padding, z); - layout.calculate(PropertyKey::IconRotate, bucket->layout.icon.rotate, z); - layout.calculate(PropertyKey::IconKeepUpright, bucket->layout.icon.keep_upright, z); - layout.calculate(PropertyKey::IconOffset, bucket->layout.icon.offset, z); - - layout.calculate(PropertyKey::TextRotationAlignment, bucket->layout.text.rotation_alignment, z); - layout.calculate(PropertyKey::TextField, bucket->layout.text.field, z); - layout.calculate(PropertyKey::TextFont, bucket->layout.text.font, z); - layout.calculate(PropertyKey::TextMaxWidth, bucket->layout.text.max_width, z); - layout.calculate(PropertyKey::TextLineHeight, bucket->layout.text.line_height, z); - layout.calculate(PropertyKey::TextLetterSpacing, bucket->layout.text.letter_spacing, z); - layout.calculate(PropertyKey::TextMaxAngle, bucket->layout.text.max_angle, z); - layout.calculate(PropertyKey::TextRotate, bucket->layout.text.rotate, z); - layout.calculate(PropertyKey::TextPadding, bucket->layout.text.padding, z); - layout.calculate(PropertyKey::TextIgnorePlacement, bucket->layout.text.ignore_placement, z); - layout.calculate(PropertyKey::TextOptional, bucket->layout.text.optional, z); - layout.calculate(PropertyKey::TextJustify, bucket->layout.text.justify, z); - layout.calculate(PropertyKey::TextAnchor, bucket->layout.text.anchor, z); - layout.calculate(PropertyKey::TextKeepUpright, bucket->layout.text.keep_upright, z); - layout.calculate(PropertyKey::TextTransform, bucket->layout.text.transform, z); - layout.calculate(PropertyKey::TextOffset, bucket->layout.text.offset, z); - layout.calculate(PropertyKey::TextAllowOverlap, bucket->layout.text.allow_overlap, z); - - layout.calculate(PropertyKey::IconSize, bucket->layout.icon.size, z + 1); - layout.calculate(PropertyKey::IconSize, bucket->layout.icon.max_size, 18); - layout.calculate(PropertyKey::TextSize, bucket->layout.text.size, z + 1); - layout.calculate(PropertyKey::TextSize, bucket->layout.text.max_size, 18); + bucket->layout.spacing.calculate(p); + bucket->layout.avoidEdges.calculate(p); + + bucket->layout.icon.allowOverlap.calculate(p); + bucket->layout.icon.ignorePlacement.calculate(p); + bucket->layout.icon.optional.calculate(p); + bucket->layout.icon.rotationAlignment.calculate(p); + bucket->layout.icon.image.calculate(p); + bucket->layout.icon.padding.calculate(p); + bucket->layout.icon.rotate.calculate(p); + bucket->layout.icon.keepUpright.calculate(p); + bucket->layout.icon.offset.calculate(p); + + bucket->layout.text.rotationAlignment.calculate(p); + bucket->layout.text.field.calculate(p); + bucket->layout.text.font.calculate(p); + bucket->layout.text.maxWidth.calculate(p); + bucket->layout.text.lineHeight.calculate(p); + bucket->layout.text.letterSpacing.calculate(p); + bucket->layout.text.maxAngle.calculate(p); + bucket->layout.text.rotate.calculate(p); + bucket->layout.text.padding.calculate(p); + bucket->layout.text.ignorePlacement.calculate(p); + bucket->layout.text.optional.calculate(p); + bucket->layout.text.justify.calculate(p); + bucket->layout.text.anchor.calculate(p); + bucket->layout.text.keepUpright.calculate(p); + bucket->layout.text.transform.calculate(p); + bucket->layout.text.offset.calculate(p); + bucket->layout.text.allowOverlap.calculate(p); + + bucket->layout.icon.size.calculate(StyleCalculationParameters(18)); + bucket->layout.text.size.calculate(StyleCalculationParameters(18)); + bucket->layout.iconMaxSize = bucket->layout.icon.size; + bucket->layout.textMaxSize = bucket->layout.text.size; + bucket->layout.icon.size.calculate(StyleCalculationParameters(p.z + 1)); + bucket->layout.text.size.calculate(StyleCalculationParameters(p.z + 1)); bucket->parseFeatures(parameters.layer, filter); |