コード例 #1
0
ファイル: kmlexport.cpp プロジェクト: 1heinz/TauLabs
StyleMapPtr KmlExport::createWallAxesStyle()
{
    StyleMapPtr styleMap = factory->CreateStyleMap();

    {
        // Add custom balloon style (gets rid of "Directions to here...")
        // https://groups.google.com/forum/?fromgroups#!topic/kml-support-getting-started/2CqF9oiynRY
        BalloonStylePtr balloonStyle = factory->CreateBalloonStyle();
        balloonStyle->set_text("$[id]");

        // Create an icon style
        IconStylePtr iconStyle = factory->CreateIconStyle();
        iconStyle->set_scale(0);

        // Create a label style
        LabelStylePtr labelStyle = factory->CreateLabelStyle();
        labelStyle->set_color(kmlbase::Color32(255, 0, 255, 255));
        labelStyle->set_scale(0);

        // Create a line style
        LineStylePtr lineStyle = factory->CreateLineStyle();
        lineStyle->set_color(kmlbase::Color32(255, 0, 0, 0)); // Black
        lineStyle->set_width(.9);

        // Link the style to the icon
        StylePtr style = factory->CreateStyle();
        style->set_balloonstyle(balloonStyle);
        style->set_iconstyle(iconStyle);
        style->set_linestyle(lineStyle);
        style->set_labelstyle(labelStyle);

        PairPtr pair = factory->CreatePair();
        pair->set_styleselector(style);
        pair->set_key(kmldom::STYLESTATE_NORMAL);

        styleMap->add_pair(pair);
    }

    {
        // Add custom balloon style (gets rid of "Directions to here...")
        // https://groups.google.com/forum/?fromgroups#!topic/kml-support-getting-started/2CqF9oiynRY
        BalloonStylePtr balloonStyle = factory->CreateBalloonStyle();
        balloonStyle->set_text("$[id]");

        // Create an icon style
        IconStylePtr iconStyle = factory->CreateIconStyle();
        iconStyle->set_scale(0);

        // Create a label style
        LabelStylePtr labelStyle = factory->CreateLabelStyle();
        labelStyle->set_color(kmlbase::Color32(255, 0, 255, 255));
        labelStyle->set_scale(0.75);

        // Create a line style
        LineStylePtr lineStyle = factory->CreateLineStyle();
        lineStyle->set_color(kmlbase::Color32(255, 0, 0, 0)); // Black
        lineStyle->set_width(1.8);

        // Link the style to the icon
        StylePtr style = factory->CreateStyle();
        style->set_balloonstyle(balloonStyle);
        style->set_iconstyle(iconStyle);
        style->set_linestyle(lineStyle);
        style->set_labelstyle(labelStyle);

        PairPtr pair = factory->CreatePair();
        pair->set_styleselector(style);
        pair->set_key(kmldom::STYLESTATE_HIGHLIGHT);

        styleMap->add_pair(pair);
    }

    styleMap->set_id("ts_1_tb");


    return styleMap;
}
コード例 #2
0
ファイル: ogrlibkmlstyle.cpp プロジェクト: Wedjaa/node-gdal
void styletable2kml (
    OGRStyleTable * poOgrStyleTable,
    KmlFactory * poKmlFactory,
    ContainerPtr poKmlContainer,
    char** papszOptions )
{

    /***** just return if the styletable is null *****/

    if ( !poOgrStyleTable )
        return;

    std::set<CPLString> aoSetNormalStyles;
    std::set<CPLString> aoSetHighlightStyles;
    poOgrStyleTable->ResetStyleStringReading (  );
    const char *pszStyleString;

    /* Collect styles that end with _normal or _highlight */
    while ( poOgrStyleTable->GetNextStyle (  ) != NULL ) {
        const char *pszStyleName = poOgrStyleTable->GetLastStyleName (  );

        if( strlen(pszStyleName) > strlen("_normal") &&
            EQUAL(pszStyleName + strlen(pszStyleName) - strlen("_normal"), "_normal") )
        {
            CPLString osName(pszStyleName);
            osName.resize(strlen(pszStyleName) - strlen("_normal"));
            aoSetNormalStyles.insert(osName);
        }
        else if( strlen(pszStyleName) > strlen("_highlight") &&
                  EQUAL(pszStyleName + strlen(pszStyleName) - strlen("_highlight"), "_highlight") )
        {
            CPLString osName(pszStyleName);
            osName.resize(strlen(pszStyleName) - strlen("_highlight"));
            aoSetHighlightStyles.insert(osName);
        }
    }

    /***** parse the style table *****/

    poOgrStyleTable->ResetStyleStringReading (  );

    while ( ( pszStyleString = poOgrStyleTable->GetNextStyle (  ) ) != NULL ) {
        const char *pszStyleName = poOgrStyleTable->GetLastStyleName (  );

        if( aoSetNormalStyles.find(pszStyleName) != aoSetNormalStyles.end() &&
            aoSetHighlightStyles.find(pszStyleName) != aoSetHighlightStyles.end() )
        {
            continue;
        }

        /***** add the style header to the kml *****/

        StylePtr poKmlStyle = poKmlFactory->CreateStyle (  );

        poKmlStyle->set_id ( pszStyleName );

        /***** parse the style string *****/

        addstylestring2kml ( pszStyleString, poKmlStyle, poKmlFactory, NULL );

        /***** add balloon style *****/
        const char* pszBalloonStyleBgColor = CSLFetchNameValue(papszOptions, CPLSPrintf("%s_balloonstyle_bgcolor", pszStyleName));
        const char* pszBalloonStyleText = CSLFetchNameValue(papszOptions, CPLSPrintf("%s_balloonstyle_text", pszStyleName));
        int nR, nG, nB, nA;
        OGRStylePen oStyleTool;
        if( (pszBalloonStyleBgColor != NULL &&
             oStyleTool.GetRGBFromString ( pszBalloonStyleBgColor, nR, nG, nB, nA )  ) ||
            pszBalloonStyleText != NULL )
        {
            BalloonStylePtr poKmlBalloonStyle = poKmlFactory->CreateBalloonStyle();
            if( pszBalloonStyleBgColor != NULL &&
                oStyleTool.GetRGBFromString ( pszBalloonStyleBgColor, nR, nG, nB, nA ) )
                poKmlBalloonStyle->set_bgcolor ( Color32 ( static_cast<GByte>(nA),
                                                           static_cast<GByte>(nB),
                                                           static_cast<GByte>(nG),
                                                           static_cast<GByte>(nR) ) );
            if( pszBalloonStyleText != NULL )
                poKmlBalloonStyle->set_text(pszBalloonStyleText);
            poKmlStyle->set_balloonstyle ( poKmlBalloonStyle );
        }

        /***** add the style to the container *****/

        DocumentPtr poKmlDocument = AsDocument ( poKmlContainer );
        poKmlDocument->add_styleselector ( poKmlStyle );

    }

    /* Find style name that end with _normal and _highlight to create */
    /* a StyleMap from both */
    std::set<CPLString>::iterator aoSetNormalStylesIter =
        aoSetNormalStyles.begin();
    for( ; aoSetNormalStylesIter != aoSetNormalStyles.end(); ++aoSetNormalStylesIter )
    {
        CPLString osStyleName(*aoSetNormalStylesIter);
        if( aoSetHighlightStyles.find(osStyleName) !=
                aoSetHighlightStyles.end() )
        {
            StyleMapPtr poKmlStyleMap = poKmlFactory->CreateStyleMap (  );
            poKmlStyleMap->set_id ( osStyleName );

            PairPtr poKmlPairNormal = poKmlFactory->CreatePair (  );
            poKmlPairNormal->set_key(STYLESTATE_NORMAL);
            poKmlPairNormal->set_styleurl(CPLSPrintf("#%s_normal", osStyleName.c_str()));
            poKmlStyleMap->add_pair(poKmlPairNormal);

            PairPtr poKmlPairHightlight = poKmlFactory->CreatePair (  );
            poKmlPairHightlight->set_key(STYLESTATE_HIGHLIGHT);
            poKmlPairHightlight->set_styleurl(CPLSPrintf("#%s_highlight", osStyleName.c_str()));
            poKmlStyleMap->add_pair(poKmlPairHightlight);

            /***** add the style to the container *****/
            DocumentPtr poKmlDocument = AsDocument ( poKmlContainer );
            poKmlDocument->add_styleselector ( poKmlStyleMap );
        }
    }

    return;
}
コード例 #3
0
ファイル: kmlexport.cpp プロジェクト: 1heinz/TauLabs
/**
 * @brief KmlExport::createCustomBalloonStyle Creates a custom balloon stye, using an arrow as an icon.
 * @return Returns the custom balloon style.
 */
StyleMapPtr KmlExport::createCustomBalloonStyle()
{
    StyleMapPtr styleMap = factory->CreateStyleMap();

    {

        // Add custom balloon style (gets rid of "Directions to here...")
        // https://groups.google.com/forum/?fromgroups#!topic/kml-support-getting-started/2CqF9oiynRY
        BalloonStylePtr balloonStyle = factory->CreateBalloonStyle();
        balloonStyle->set_text("$[description]");

        // Change the icon
        IconStyleIconPtr iconStyleIcon = factory->CreateIconStyleIcon();
        iconStyleIcon->set_href("http://maps.google.com/mapfiles/kml/shapes/arrow.png");

        // Create a label style
        LabelStylePtr labelStyle = factory->CreateLabelStyle();
        labelStyle->set_color(kmlbase::Color32(255, 0, 255, 255));
        labelStyle->set_scale(0.75);

        // Create an icon style
        IconStylePtr iconStyle = factory->CreateIconStyle();
        iconStyle->set_icon(iconStyleIcon);
        iconStyle->set_scale(0.65);

        // Create a line style
        LineStylePtr lineStyle = factory->CreateLineStyle();
        lineStyle->set_width(3.25);

        // Link the style to the icon
        StylePtr style = factory->CreateStyle();
        style->set_balloonstyle(balloonStyle);
        style->set_iconstyle(iconStyle);
        style->set_linestyle(lineStyle);
        style->set_labelstyle(labelStyle);

        PairPtr pair = factory->CreatePair();
        pair->set_styleselector(style);
        pair->set_key(kmldom::STYLESTATE_NORMAL);

        styleMap->add_pair(pair);
    }

    {
        // Add custom balloon style (gets rid of "Directions to here...")
        // https://groups.google.com/forum/?fromgroups#!topic/kml-support-getting-started/2CqF9oiynRY
        BalloonStylePtr balloonStyle = factory->CreateBalloonStyle();
        balloonStyle->set_text("$[description]");

        // Change the icon
        IconStyleIconPtr iconStyleIcon = factory->CreateIconStyleIcon();
        iconStyleIcon->set_href("http://maps.google.com/mapfiles/kml/shapes/arrow.png");

        // Create an icon style
        IconStylePtr iconStyle = factory->CreateIconStyle();
        iconStyle->set_icon(iconStyleIcon);
        iconStyle->set_scale(0.65);

        // Create a label style
        LabelStylePtr labelStyle = factory->CreateLabelStyle();
        labelStyle->set_color(kmlbase::Color32(255, 0, 255, 255));
        labelStyle->set_scale(0.9);

        // Create a line style
        LineStylePtr lineStyle = factory->CreateLineStyle();
        lineStyle->set_width(6.5);

        // Link the style to the icon
        StylePtr style = factory->CreateStyle();
        style->set_balloonstyle(balloonStyle);
        style->set_iconstyle(iconStyle);
        style->set_linestyle(lineStyle);
        style->set_labelstyle(labelStyle);

        PairPtr pair = factory->CreatePair();
        pair->set_styleselector(style);
        pair->set_key(kmldom::STYLESTATE_HIGHLIGHT);

        styleMap->add_pair(pair);
    }

    styleMap->set_id("directiveArrowStyle");

    return styleMap;
}