how to show coordinates when moving the mouse inside the map

classic Classic list List threaded Threaded
7 messages Options
Ekkim Ekkim
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

how to show coordinates when moving the mouse inside the map

 
Hi;
i need help if someone knows parts of  code to enable 'coords' mode which have the same effect as the commande osgearth_viewer --coords .
 Please help me
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to show coordinates when moving the mouse inside the map

Ekkim Ekkim
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to show coordinates when moving the mouse inside the map

thanks glwaldron

am testing this code:

#include <osgDB/ReadFile>
#include <osgEarth/Map>
#include <osgViewer/Viewer>
#include <osgEarth/MapNode>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/Sky>
#include <osgEarth\GeoTransform>
#include <osgEarthAnnotation/PlaceNode>
#include <osgEarthUtil/MouseCoordsTool>
#include <osgEarthUtil/ExampleResources>
#include <osgViewer/View>
#include <osgEarthUtil/MGRSFormatter>
#include <osgEarthUtil/LatLongFormatter>
using namespace osgEarth;
using namespace osgEarth::Util;
using namespace osgEarth::Annotation;
using namespace osgEarth::Util::Controls;
using namespace osgEarth::Symbology;








 LabelControl* readout = new LabelControl();
        readout->setBackColor( Color(Color::Black, 0.8) );
        readout->setHorizAlign( Control::ALIGN_RIGHT );
                readout->setVertAlign( Control::ALIGN_BOTTOM );

                 Formatter* formatter = new LatLongFormatter(LatLongFormatter::FORMAT_DECIMAL_DEGREES);
                MouseCoordsTool* mcTool = new MouseCoordsTool( map );
                 mcTool->addCallback( new MouseCoordsLabelCallback(readout, formatter) );
        viewer->addEventHandler( mcTool );

        osgEarth::Util::EarthManipulator* manip = new osgEarth::Util::EarthManipulator();
        viewer->setCameraManipulator (manip);
        viewer->setUpViewInWindow(50, 50, 512, 512);
        viewer->setSceneData(root);
        return viewer->run();
       



and these are the errors:


gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to show coordinates when moving the mouse inside the map

Are you linking with osgEarthSymbology?
Glenn Waldron / Pelican Mapping
Ekkim Ekkim
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to show coordinates when moving the mouse inside the map

thanks gwaldron.
yes i m linking osgEarthSymbology , the execution works but coordinates didn't appear in the viewer.
   


gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to show coordinates when moving the mouse inside the map

Seems like you make a LabelControl, but didn't put it anywhere.

View the osgearth_controls.cpp for an example for how to create and populate a ControlCanvas.
Glenn Waldron / Pelican Mapping
Ekkim Ekkim
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to show coordinates when moving the mouse inside the map

i modified the code like this but nothing is changed in the execution results and coordinates don't appear yet !  thanks for your answers  




ControlCanvas* canvas = ControlCanvas::getOrCreate( viewer );
        createControls( canvas );
        LabelControl* readout = new LabelControl("Upper left control", 22, osg::Vec4f(1,1,0,1) );
        readout->setBackColor( Color(Color::Black, 0.8) );
        readout->setHorizAlign( Control::ALIGN_RIGHT );
                readout->setVertAlign( Control::ALIGN_BOTTOM );
                bool useMGRS=true , useDMS= true , useDD=true ;
                /*Formatter* formatter =
            useMGRS ? (Formatter*)new MGRSFormatter(MGRSFormatter::PRECISION_1M, 0L, MGRSFormatter::USE_SPACES) :
            useDMS  ? (Formatter*)new LatLongFormatter(LatLongFormatter::FORMAT_DEGREES_MINUTES_SECONDS) :
            useDD   ? (Formatter*)new LatLongFormatter(LatLongFormatter::FORMAT_DECIMAL_DEGREES) :
            0L;
                */
                Formatter* formatter = new LatLongFormatter(LatLongFormatter::FORMAT_DECIMAL_DEGREES);
                MouseCoordsTool* mcTool = new MouseCoordsTool( map );
                 mcTool->addCallback( new MouseCoordsLabelCallback(readout, formatter) );
        viewer->addEventHandler( mcTool );
       canvas->addControl( readout );


this is the creation function :

void createControls( ControlCanvas* cs )
{
 
    // a container centered on the screen, containing an image and a text label.
    {
        VBox* center = new VBox();
        center->setBorderColor( 1, 1, 1, 1 );
        center->setBackColor( .6,.5,.4,0.5 );
        center->setPadding( 10 );
        center->setHorizAlign( Control::ALIGN_CENTER );
        center->setVertAlign( Control::ALIGN_CENTER );

       // Add an image:
        osg::ref_ptr<osg::Image> image = osgDB::readImageFile("../data/osgearth.gif");
        if ( image.valid() )
        {
            s_imageControl = new ImageControl( image.get() );
            s_imageControl->setHorizAlign( Control::ALIGN_CENTER );
            s_imageControl->setFixSizeForRotation( true );
            center->addControl( s_imageControl );
            center->setHorizAlign( Control::ALIGN_CENTER );
        }  
        // Add a text label:
        LabelControl* label = new LabelControl( "osgEarth Controls Toolkit" );
        label->setFont( osgEarth::Registry::instance()->getDefaultFont() );
        label->setFontSize( 24.0f );
        label->setHorizAlign( Control::ALIGN_CENTER );
        label->setMargin( 5 );
        center->addControl( label );

        // Rotation slider
        HBox* rotateBox = new HBox();
        rotateBox->setChildVertAlign( Control::ALIGN_CENTER );
        rotateBox->setHorizFill( true );
        rotateBox->setBackColor( Color::Blue );
        {
            rotateBox->addControl( new LabelControl("Rotate: ") );

            HSliderControl* rotateSlider = new HSliderControl( -180.0, 180.0, 0.0 );
            rotateSlider->addEventHandler( new RotateImage() );
            rotateSlider->setHeight( 8.0f );
            rotateSlider->setHorizFill( true );
            rotateBox->addControl( rotateSlider );
        }
        center->addControl( rotateBox );

        cs->addControl( center );
    }

    // a simple vbox with absolute positioning in the upper left with two text labels.
    {
        VBox* ul = new VBox();
        ul->setPosition( 20, 20 );
        ul->setPadding( 10 );
        {
            LabelControl* title = new LabelControl( "Upper left control", 22, osg::Vec4f(1,1,0,1) );
            ul->addControl( title );

            LabelControl* content = new LabelControl( "Here is some text in the upper left control" );
            ul->addControl( content );

            HBox* c2 = new HBox();
            c2->setChildSpacing( 10 );
            {
                HSliderControl* slider = new HSliderControl( 0, 100 );
                slider->setBackColor( .6,0,0,1 );
                slider->setHeight( 25 );
                slider->setWidth( 300 );
                slider->addEventHandler( new MySliderHandler() );
                c2->addControl( slider );

                s_sliderLabel = new LabelControl();
                s_sliderLabel->setVertAlign( Control::ALIGN_CENTER );
                c2->addControl( s_sliderLabel );        
            }
            ul->addControl( c2 );

            HBox* c3 = new HBox();
            c3->setHorizAlign( Control::ALIGN_CENTER );
            c3->setChildSpacing( 10 );
            {
                HBox* c4 = new HBox();
                c4->setChildSpacing( 5 );
                {
                    c4->addControl( new CheckBoxControl( true ) );
                    c4->addControl( new LabelControl( "Checkbox 1" ) );
                }
                c3->addControl( c4 );

                HBox* c5 = new HBox();
                c5->setChildSpacing( 5 );
                {
                    c5->addControl( new CheckBoxControl( false ) );
                    c5->addControl( new LabelControl( "Checkbox 2" ) );
                }
                c3->addControl( c5 );
            }
            ul->addControl( c3 );
        }
        cs->addControl( ul );

        ul->addEventHandler( new MyClickHandler );
    }

    // a centered hbox container along the bottom on the screen.
    {
        HBox* bottom = new HBox();
        bottom->setBackColor(0,0,0,0.5);        
        bottom->setMargin( 10 );
        bottom->setChildSpacing( 145 );
        bottom->setVertAlign( Control::ALIGN_BOTTOM );
        bottom->setHorizAlign( Control::ALIGN_CENTER );

        for( int i=0; i<4; ++i )
        {
            LabelControl* label = new LabelControl();
            std::stringstream buf;
            buf << "Label_" << i;
            std::string str;
            str = buf.str();
            label->setText( str );
            label->setMargin( 10 );
            label->setBackColor( 1,1,1,0.4 );
            bottom->addControl( label );

            label->setActiveColor(1,.3,.3,1);
            label->addEventHandler( new MyClickHandler );
        }

        cs->addControl( bottom );
    }
}

Loading...