Пример #1
0
/**
 * @brief KmlExport::createGroundTrackStyle Creates a custom style for the ground track.
 * @return Returns the custom style.
 */
StylePtr KmlExport::createGroundTrackStyle()
{
    // 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);

    style->set_id("ts_2_tb");

    return style;
}
Пример #2
0
void addstylestring2kml (
    const char *pszStyleString,
    StylePtr poKmlStyle,
    KmlFactory * poKmlFactory,
    PlacemarkPtr poKmlPlacemark,
    OGRFeature * poOgrFeat )
{

    LineStylePtr poKmlLineStyle = NULL;
    PolyStylePtr poKmlPolyStyle = NULL;
    IconStylePtr poKmlIconStyle = NULL;
    LabelStylePtr poKmlLabelStyle = NULL;
    
    /***** just bail now if stylestring is empty *****/

    if ( !pszStyleString || !*pszStyleString ) {
        return;
    }

    /***** create and init a style mamager with the style string *****/

    OGRStyleMgr *poOgrSM = new OGRStyleMgr;

    poOgrSM->InitStyleString ( pszStyleString );

    /***** loop though the style parts *****/

    int i;

    for ( i = 0; i < poOgrSM->GetPartCount ( NULL ); i++ ) {
        OGRStyleTool *poOgrST = poOgrSM->GetPart ( i, NULL );

        if ( !poOgrST ) {
            continue;
        }
        
        switch ( poOgrST->GetType (  ) ) {
        case OGRSTCPen:
            {
                GBool nullcheck;

                poKmlLineStyle = poKmlFactory->CreateLineStyle (  );

                OGRStylePen *poStylePen = ( OGRStylePen * ) poOgrST;

                /***** pen color *****/

                int nR,
                    nG,
                    nB,
                    nA;

                const char *pszcolor = poStylePen->Color ( nullcheck );

                if ( !nullcheck
                     && poStylePen->GetRGBFromString ( pszcolor, nR, nG, nB, nA ) ) {
                    poKmlLineStyle->set_color ( Color32 ( nA, nB, nG, nR ) );
                }
                double dfWidth = poStylePen->Width ( nullcheck );

                if ( nullcheck )
                    dfWidth = 1.0;

                poKmlLineStyle->set_width ( dfWidth );
                
                break;
            }
        case OGRSTCBrush:
            {
                GBool nullcheck;

                poKmlPolyStyle = poKmlFactory->CreatePolyStyle (  );

                OGRStyleBrush *poStyleBrush = ( OGRStyleBrush * ) poOgrST;

                /***** brush color *****/

                int nR,
                    nG,
                    nB,
                    nA;

                const char *pszcolor = poStyleBrush->ForeColor ( nullcheck );

                if ( !nullcheck
                     && poStyleBrush->GetRGBFromString ( pszcolor, nR, nG, nB, nA ) ) {
                    poKmlPolyStyle->set_color ( Color32 ( nA, nB, nG, nR ) );
                }
                

                break;
            }
        case OGRSTCSymbol:
            {
                GBool nullcheck;
                GBool nullcheck2;

                OGRStyleSymbol *poStyleSymbol = ( OGRStyleSymbol * ) poOgrST;

                /***** id (kml icon) *****/

                const char *pszId = poStyleSymbol->Id ( nullcheck );

                if ( !nullcheck ) {
                    if ( !poKmlIconStyle)
                        poKmlIconStyle = poKmlFactory->CreateIconStyle (  );

                    /***** split it at the ,'s *****/

                    char **papszTokens =
                        CSLTokenizeString2 ( pszId, ",",
                                             CSLT_HONOURSTRINGS | CSLT_STRIPLEADSPACES |
                                             CSLT_STRIPENDSPACES );

                    if ( papszTokens ) {

                        /***** for lack of a better solution just take the first one *****/
                        //todo come up with a better idea

                        if ( papszTokens[0] ) {
                            IconStyleIconPtr poKmlIcon =
                                poKmlFactory->CreateIconStyleIcon (  );
                            poKmlIcon->set_href ( papszTokens[0] );
                            poKmlIconStyle->set_icon ( poKmlIcon );
                        }

                        CSLDestroy ( papszTokens );

                    }


                }

                /***** heading *****/

                double heading = poStyleSymbol->Angle ( nullcheck );

                if ( !nullcheck ) {
                    if ( !poKmlIconStyle)
                        poKmlIconStyle = poKmlFactory->CreateIconStyle (  );
                    poKmlIconStyle->set_heading ( heading );
                }

                /***** scale *****/

                double dfScale = poStyleSymbol->Size ( nullcheck );

                if ( !nullcheck ) {
                    if ( !poKmlIconStyle)
                        poKmlIconStyle = poKmlFactory->CreateIconStyle (  );

                    poKmlIconStyle->set_scale ( dfScale );
                }

                /***** color *****/

                int nR,
                    nG,
                    nB,
                    nA;

                const char *pszcolor = poStyleSymbol->Color ( nullcheck );

                if ( !nullcheck && poOgrST->GetRGBFromString ( pszcolor, nR, nG, nB, nA ) ) {
                    poKmlIconStyle->set_color ( Color32 ( nA, nB, nG, nR ) );
                }

                /***** hotspot *****/

                double dfDx = poStyleSymbol->SpacingX ( nullcheck );
                double dfDy = poStyleSymbol->SpacingY ( nullcheck2 );

                if ( !nullcheck && !nullcheck2 ) {
                    if ( !poKmlIconStyle)
                        poKmlIconStyle = poKmlFactory->CreateIconStyle (  );

                    HotSpotPtr poKmlHotSpot = poKmlFactory->CreateHotSpot (  );

                    poKmlHotSpot->set_x ( dfDx );
                    poKmlHotSpot->set_y ( dfDy );

                    poKmlIconStyle->set_hotspot ( poKmlHotSpot );
                }
                
                break;
            }
        case OGRSTCLabel:
            {
                GBool nullcheck;
                GBool nullcheck2;
                
                poKmlLabelStyle = poKmlFactory->CreateLabelStyle (  );

                OGRStyleLabel *poStyleLabel = ( OGRStyleLabel * ) poOgrST;

                /***** color *****/

                int nR,
                    nG,
                    nB,
                    nA;

                const char *pszcolor = poStyleLabel->ForeColor ( nullcheck );

                if ( !nullcheck
                     && poStyleLabel->GetRGBFromString ( pszcolor, nR, nG, nB, nA ) ) {
                    poKmlLabelStyle->set_color ( Color32 ( nA, nB, nG, nR ) );
                }

                /***** scale *****/

                double dfScale = poStyleLabel->Stretch ( nullcheck );

                if ( !nullcheck ) {
                    dfScale /= 100.0;
                    poKmlLabelStyle->set_scale ( dfScale );
                }
                
                /***** heading *****/

                double heading = poStyleLabel->Angle ( nullcheck );

                if ( !nullcheck ) {
                    if ( !poKmlIconStyle) {
                        poKmlIconStyle = poKmlFactory->CreateIconStyle (  );
                        IconStyleIconPtr poKmlIcon = poKmlFactory->CreateIconStyleIcon (  );
                        poKmlIconStyle->set_icon ( poKmlIcon );
                    }
                    
                    poKmlIconStyle->set_heading ( heading );
                }

                /***** hotspot *****/

                double dfDx = poStyleLabel->SpacingX ( nullcheck );
                double dfDy = poStyleLabel->SpacingY ( nullcheck2 );

                if ( !nullcheck && !nullcheck2 ) {
                    if ( !poKmlIconStyle) {
                        poKmlIconStyle = poKmlFactory->CreateIconStyle (  );
                        IconStyleIconPtr poKmlIcon = poKmlFactory->CreateIconStyleIcon (  );
                        poKmlIconStyle->set_icon ( poKmlIcon );
                    }
                    
                    HotSpotPtr poKmlHotSpot = poKmlFactory->CreateHotSpot (  );

                    poKmlHotSpot->set_x ( dfDx );
                    poKmlHotSpot->set_y ( dfDy );

                    poKmlIconStyle->set_hotspot ( poKmlHotSpot );
                }

                /***** label text *****/

                const char *pszText = poStyleLabel->TextString ( nullcheck );

                if ( !nullcheck ) {
                    if ( poKmlPlacemark ) {

                        poKmlPlacemark->set_name( pszText );
                    }
                }
                    
                break;
            }
        case OGRSTCNone:
        default:
            break;
        }

        delete poOgrST;
    }

    if ( poKmlLineStyle )
        poKmlStyle->set_linestyle ( poKmlLineStyle );

    if ( poKmlPolyStyle )
        poKmlStyle->set_polystyle ( poKmlPolyStyle );

    if ( poKmlIconStyle )
        poKmlStyle->set_iconstyle ( poKmlIconStyle );

    if ( poKmlLabelStyle )
        poKmlStyle->set_labelstyle ( poKmlLabelStyle );
    
    delete poOgrSM;
}
Пример #3
0
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;
}
Пример #4
0
/**
 * @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;
}