diff --git a/src/osgEarth/FeatureStyleSorter.cpp b/src/osgEarth/FeatureStyleSorter.cpp index 76761fb7b3..a147b5ebd0 100644 --- a/src/osgEarth/FeatureStyleSorter.cpp +++ b/src/osgEarth/FeatureStyleSorter.cpp @@ -93,51 +93,57 @@ FeatureStyleSorter::sort_usingSelectors( { Feature* feature = itr->get(); - const std::string& styleString = feature->eval(styleExprCopy, &context); - if (!styleString.empty() && styleString != "null") + const std::string& delimitedStyleStrings = feature->eval(styleExprCopy, &context); + if (!delimitedStyleStrings.empty() && delimitedStyleStrings != "null") { - // resolve the style: - const Style* resolved_style = nullptr; - int resolved_index = 0; + std::vector styleStrings; + StringTokenizer(delimitedStyleStrings, styleStrings, ",", "", false, true); - // if the style string begins with an open bracket, it's an inline style definition. - if (styleString.length() > 0 && styleString[0] == '{') + for (auto& styleString : styleStrings) { - Config conf("style", styleString); - conf.setReferrer(sel.styleExpression().get().uriContext().referrer()); - conf.set("type", "text/css"); - auto& literal_style_and_index = literal_styles[conf.toJSON()]; - if (literal_style_and_index.first.empty()) + // resolve the style: + const Style* resolved_style = nullptr; + int resolved_index = 0; + + // if the style string begins with an open bracket, it's an inline style definition. + if (styleString.length() > 0 && styleString[0] == '{') { - literal_style_and_index.first = Style(conf); - // literal styles always come AFTER sheet styles - literal_style_and_index.second = literal_styles.size() + session->styles()->getStyles().size(); + Config conf("style", styleString); + conf.setReferrer(sel.styleExpression().get().uriContext().referrer()); + conf.set("type", "text/css"); + auto& literal_style_and_index = literal_styles[conf.toJSON()]; + if (literal_style_and_index.first.empty()) + { + literal_style_and_index.first = Style(conf); + // literal styles always come AFTER sheet styles + literal_style_and_index.second = literal_styles.size() + session->styles()->getStyles().size(); + } + resolved_style = &literal_style_and_index.first; + resolved_index = literal_style_and_index.second; } - resolved_style = &literal_style_and_index.first; - resolved_index = literal_style_and_index.second; - } - - // otherwise, look up the style in the stylesheet. Do NOT fall back on a default - // style in this case: for style expressions, the user must be explicit about - // default styling; this is because there is no other way to exclude unwanted - // features. - else - { - auto style_and_index = session->styles()->getStyleAndIndex(styleString); - //const Style* selected_style = session->styles()->getStyle(styleString, false); - if (style_and_index.first) + // otherwise, look up the style in the stylesheet. Do NOT fall back on a default + // style in this case: for style expressions, the user must be explicit about + // default styling; this is because there is no other way to exclude unwanted + // features. + else { - resolved_style = style_and_index.first; - resolved_index = style_and_index.second; + auto style_and_index = session->styles()->getStyleAndIndex(styleString); + + //const Style* selected_style = session->styles()->getStyle(styleString, false); + if (style_and_index.first) + { + resolved_style = style_and_index.first; + resolved_index = style_and_index.second; + } } - } - if (resolved_style) - { - auto& bucket = style_buckets[resolved_index]; - bucket.first = resolved_style; - bucket.second.emplace_back(feature); + if (resolved_style) + { + auto& bucket = style_buckets[resolved_index]; + bucket.first = resolved_style; + bucket.second.emplace_back(feature); + } } } } diff --git a/src/osgEarth/StyleSheet.cpp b/src/osgEarth/StyleSheet.cpp index 72ba1b277b..a42d9dd600 100644 --- a/src/osgEarth/StyleSheet.cpp +++ b/src/osgEarth/StyleSheet.cpp @@ -215,14 +215,16 @@ StyleSheet::Options::fromConfig(const Config& conf) auto_script << "// __oe_auto__\n"; auto_script << "function __oe_select_style() {\n"; + auto_script << " var combo = '';\n"; } - auto_script << " if (" << selector_symbol->predicate().get() << ") return \"" << style.getName() << "\";\n"; + auto_script << " if (" << selector_symbol->predicate().get() << ") combo = combo + '" << style.getName() << ",';\n"; } } if (auto_selector) { + auto_script << " if (combo.length > 0) return combo.substring(0, combo.length-1);\n"; auto_script << " return 'default';\n}\n"; auto new_code = auto_script.str(); diff --git a/tests/feature_multi_styling.earth b/tests/feature_multi_styling.earth new file mode 100644 index 0000000000..0f7ee4df75 --- /dev/null +++ b/tests/feature_multi_styling.earth @@ -0,0 +1,74 @@ + + + + + + https://readymap.org/readymap/mbtiles/daylight-v1.2/{z}/{x}/{-y}.pbf + 14 + 14 + spherical-mercator + pbf + @id + + highway + + + + + https://readymap.org/readymap/tiles/1.0.0/7 + + + + 512 + osm-roads + 25m + + + + + + + + + -3.2425e-07 + -89 + 2928.14m + -77.19548706709453 + 38.83147622799055 + + +