osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthDrivers/kml/KML_GroundOverlay.cpp

Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
00003  * Copyright 2008-2010 Pelican Mapping
00004  * http://osgearth.org
00005  *
00006  * osgEarth is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018  */
00019 #include "KML_GroundOverlay"
00020 #include "KML_Geometry"
00021 #include <osgEarthUtil/ImageOverlay>
00022 
00023 using namespace osgEarth::Util;
00024 
00025 void
00026 KML_GroundOverlay::scan( const Config& conf, KMLContext& cx )
00027 {
00028     KML_Overlay::scan( conf, cx );
00029 }
00030 
00031 void
00032 KML_GroundOverlay::build( const Config& conf, KMLContext& cx )
00033 {
00034     // the URL of the overlay image
00035     std::string href = conf.child("icon").value("href");
00036     if ( href.empty() ) {
00037         OE_WARN << LC << "GroundOverlay missing required Icon element" << std::endl;
00038         return;
00039     }
00040 
00041     ImageOverlay* im = 0L;
00042 
00043     // the extent of the overlay image
00044     const Config& llb = conf.child("latlonbox");
00045     if ( !llb.empty() )
00046     {
00047         double north = llb.value<double>("north", 0.0);
00048         double south = llb.value<double>("south", 0.0);
00049         double east  = llb.value<double>("east", 0.0);
00050         double west  = llb.value<double>("west", 0.0);
00051         Angular rotation( llb.value<double>("rotation", 0.0), Units::DEGREES );
00052 
00053         osg::ref_ptr<osg::Image> image = URI(href, conf.uriContext()).readImage();
00054         if ( !image.valid() ) {
00055             OE_WARN << LC << "GroundOverlay failed to read image from " << href << std::endl;
00056             return;
00057         }
00058 
00059         im = new ImageOverlay( cx._mapNode, image.get() );
00060         im->setBoundsAndRotation( Bounds(west, south, east, north), rotation );
00061         cx._groupStack.top()->addChild( im );
00062     }
00063 
00064     else if ( conf.hasChild("gx:latlonquad") )
00065     {
00066         const Config& llq = conf.child("gx:latlonquad");
00067         KML_Geometry g;
00068         Style style;
00069         g.buildChild( llq, cx, style );
00070         if ( g._geom.valid() && g._geom->size() >= 4 )
00071         {
00072             osg::ref_ptr<osg::Image> image = URI(href, conf.uriContext()).readImage();
00073             if ( !image.valid() ) {
00074                 OE_WARN << LC << "GroundOverlay failed to read image from " << href << std::endl;
00075                 return;
00076             }
00077 
00078             const Geometry& p = *(g._geom.get());
00079             im = new ImageOverlay( cx._mapNode, image.get() );
00080             im->setCorners( 
00081                 osg::Vec2d( p[0].x(), p[0].y() ),
00082                 osg::Vec2d( p[1].x(), p[1].y() ),
00083                 osg::Vec2d( p[3].x(), p[3].y() ),
00084                 osg::Vec2d( p[2].x(), p[2].y() ) );
00085             cx._groupStack.top()->addChild( im );
00086         }
00087     }
00088 
00089     else {
00090         OE_WARN << LC << "GroundOverlay missing required LatLonBox/gx:LatLonQuad element" << std::endl;
00091         return;
00092     }
00093 
00094 
00095     // superclass build always called last
00096     KML_Overlay::build( conf, cx, im );
00097 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines