Changeset 6075 for geovis


Ignore:
Timestamp:
Feb 28, 2016 3:54:11 AM (8 years ago)
Author:
ldelgass
Message:

Parse CSS style and rewrite URLs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • geovis/trunk/RendererCmd.cpp

    r6070 r6075  
    3131#include <osgEarthSymbology/Style>
    3232#include <osgEarthSymbology/StyleSheet>
     33#include <osgEarthSymbology/CssUtils>
    3334#include <osgEarthSymbology/IconSymbol>
     35#include <osgEarthSymbology/ModelSymbol>
    3436#include <osgEarthSymbology/LineSymbol>
    3537#include <osgEarthSymbology/RenderSymbol>
     
    16791681        styleConf.add("type", "text/css");
    16801682        INFO("style CSS: %s", styleConf.value().c_str());
     1683#if 1
     1684        geomOpts.styles() = new osgEarth::Symbology::StyleSheet();
     1685        // For relative paths:
     1686        //styleConf.setReferrer(g_renderer->getCacheDirectory());
     1687        std::string cssString = styleConf.value();
     1688        std::vector<std::string> blocks;
     1689        osgEarth::Symbology::CssUtils::split(cssString, blocks);
     1690        for (std::vector<std::string>::iterator itr = blocks.begin();
     1691             itr != blocks.end(); ++itr) {
     1692            osgEarth::Config blockConf(styleConf);
     1693            blockConf.value() = *itr;
     1694            osgEarth::Symbology::Style style(blockConf);
     1695
     1696            INFO("Style: %s", style.getName().c_str());
     1697            INFO("%s", itr->c_str());
     1698
     1699            if (style.has<osgEarth::Symbology::IconSymbol>()) {
     1700                INFO("Found icon symbol");
     1701                osgEarth::Symbology::IconSymbol *is =
     1702                    style.get<osgEarth::Symbology::IconSymbol>();
     1703                if (is->url().isSet()) {
     1704                    INFO("Icon url before: expr: '%s' eval: '%s'",
     1705                         is->url()->expr().c_str(), is->url()->eval().c_str());
     1706                    // eval() will try to evaluate the expr()
     1707                    std::string path = g_renderer->getCanonicalPath(is->url()->eval());
     1708                    //setInfix() to set the expr() string, setLiteral() will quote
     1709                    is->url()->setLiteral(path);
     1710                    INFO("Icon url after: %s", path.c_str());
     1711                }
     1712            }
     1713            if (style.has<osgEarth::Symbology::ModelSymbol>()) {
     1714                osgEarth::Symbology::ModelSymbol *ms =
     1715                    style.get<osgEarth::Symbology::ModelSymbol>();
     1716                if (ms->url().isSet()) {
     1717                    // eval() will try to evaluate the expr()
     1718                    std::string path = g_renderer->getCanonicalPath(ms->url()->eval());
     1719                    //setInfix() to set the expr() string, setLiteral() will quote
     1720                    ms->url()->setLiteral(path);
     1721                }
     1722            }
     1723            // Need to create a new style otherwise the original CSS is used
     1724            // without the re-written URLs
     1725            geomOpts.styles()->addStyle(osgEarth::Symbology::Style(style.getConfig(false)));
     1726        }
     1727#else
    16811728        osgEarth::Config stylesheetConf;
    16821729        stylesheetConf.add(styleConf);
    16831730        geomOpts.styles() = new osgEarth::Symbology::StyleSheet(stylesheetConf);
     1731#endif
    16841732
    16851733        if (objc > 11) {
     
    17001748                return TCL_ERROR;
    17011749            }
     1750            INFO("Num Selectors: %d", numSelectors);
    17021751            for (int i = 0; i < numSelectors; i++) {
    17031752                int numFields;
Note: See TracChangeset for help on using the changeset viewer.