Changeset 6354


Ignore:
Timestamp:
May 22, 2016 1:34:59 PM (7 years ago)
Author:
ldelgass
Message:

Add layer position index param to add*Layer methods. Add option to transform
selection box coords to another SRS.

Location:
geovis/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • geovis/trunk/Renderer.cpp

    r6276 r6354  
    13121312bool Renderer::addImageLayer(const char *name,
    13131313                             osgEarth::TileSourceOptions& opts,
     1314                             unsigned int pos,
    13141315                             bool enableCache,
    13151316                             bool coverage,
     
    13441345    layerOpts.maxLevel() = maxLOD;
    13451346    osg::ref_ptr<osgEarth::ImageLayer> layer = new osgEarth::ImageLayer(layerOpts);
    1346     _map->addImageLayer(layer.get());
     1347    if (pos < (unsigned int)_map->getNumImageLayers()) {
     1348        _map->insertImageLayer(layer.get(), pos);
     1349    } else {
     1350        _map->addImageLayer(layer.get());
     1351    }
    13471352    if (layer->getTileSource() == NULL || !layer->getTileSource()->isOK()) {
    13481353        ERROR("Failed to add image layer: %s", name);
     
    14721477void Renderer::addElevationLayer(const char *name,
    14731478                                 osgEarth::TileSourceOptions& opts,
     1479                                 unsigned int pos,
    14741480                                 bool enableCache,
    14751481                                 bool visible,
     
    14961502    // Common options: geodetic (default), egm96, egm84, egm2008
    14971503    //layerOpts.verticalDatum() = "egm96";
    1498     _map->addElevationLayer(new osgEarth::ElevationLayer(layerOpts));
     1504    osgEarth::ElevationLayer *layer = new osgEarth::ElevationLayer(layerOpts);
     1505    _map->addElevationLayer(layer);
     1506    // Map API lacks an insertElevationLayer method, so need to move it
     1507    if (pos < (unsigned int)_map->getNumElevationLayers()) {
     1508        _map->moveElevationLayer(layer, pos);
     1509    }
    14991510    _needsRedraw = true;
    15001511}
     
    18431854}
    18441855
    1845 void Renderer::getBoxSelection(double *latMin, double *latMax, double *longMin, double *longMax)
     1856void Renderer::getBoxSelection(double *latMin, double *latMax,
     1857                               double *longMin, double *longMax,
     1858                               const osgEarth::SpatialReference *outSRS)
    18461859{
    18471860    osgEarth::Annotation::FeatureNode *node = _selectionBox.get();
     
    18551868    *longMin = (*geom)[1].x();
    18561869    *longMax = (*geom)[0].x();
     1870    if (outSRS == NULL)
     1871        return;
     1872
     1873    const osgEarth::SpatialReference* fromSRS = _mapNode->getMapSRS()->getGeographicSRS();
     1874    osgEarth::GeoPoint pt1(fromSRS, *longMin, *latMin);
     1875    osgEarth::GeoPoint pt2(fromSRS, *longMax, *latMax);
     1876    pt1.transform(outSRS);
     1877    pt2.transform(outSRS);
     1878    *latMin = pt1.y();
     1879    *latMax = pt2.y();
     1880    *longMin = pt1.x();
     1881    *longMax = pt2.x();
    18571882}
    18581883
     
    21692194void Renderer::addModelLayer(const char *name,
    21702195                             osgEarth::ModelSourceOptions& opts,
     2196                             unsigned int pos,
    21712197                             bool enableCache,
    21722198                             bool lighting,
     
    21872213    }
    21882214    layerOpts.lightingEnabled() = lighting;
    2189     _map->addModelLayer(new osgEarth::ModelLayer(layerOpts));
     2215    osgEarth::ModelLayer *layer = new osgEarth::ModelLayer(layerOpts);
     2216    if (pos < (unsigned int)_map->getNumModelLayers()) {
     2217        _map->insertModelLayer(layer, pos);
     2218    } else {
     2219        _map->addModelLayer(layer);
     2220    }
    21902221    _needsRedraw = true;
    21912222}
  • geovis/trunk/Renderer.h

    r6276 r6354  
    262262    }
    263263
    264     bool addImageLayer(const char *name, osgEarth::TileSourceOptions& opts,
     264    bool addImageLayer(const char *name,
     265                       osgEarth::TileSourceOptions& opts,
     266                       unsigned int pos = UINT_MAX,
    265267                       bool enableCache = true,
    266268                       bool coverage = false,
     
    308310    }
    309311
    310     void addElevationLayer(const char *name, osgEarth::TileSourceOptions& opts,
     312    void addElevationLayer(const char *name,
     313                           osgEarth::TileSourceOptions& opts,
     314                           unsigned int pos = UINT_MAX,
    311315                           bool enableCache = true,
    312316                           bool visible = true,
     
    344348    }
    345349
    346     void addModelLayer(const char *name, osgEarth::ModelSourceOptions& opts,
     350    void addModelLayer(const char *name,
     351                       osgEarth::ModelSourceOptions& opts,
     352                       unsigned int pos = UINT_MAX,
    347353                       bool enableCache = true,
    348354                       bool lighting = true,
     
    549555    void initBoxSelection(int x, int y);
    550556    void updateBoxSelection(int x, int y);
    551     void getBoxSelection(double *latMin, double *latMax, double *longMin, double *longMax);
     557    void getBoxSelection(double *latMin, double *latMax,
     558                         double *longMin, double *longMax,
     559                         const osgEarth::SpatialReference *outSRS = NULL);
    552560    void clearBoxSelection();
    553561
  • geovis/trunk/RendererCmd.cpp

    r6350 r6354  
    13721372    char *name = Tcl_GetString(objv[3]);
    13731373    char *type = Tcl_GetString(objv[4]);
     1374    unsigned int pos = UINT_MAX;
    13741375    bool cache = true;
    13751376    bool visible = true;
     
    15611562                return TCL_ERROR;
    15621563            }
    1563             ret = g_renderer->addImageLayer(name, aggOpts, cache, coverage, shared, visible, minLOD, maxLOD);
     1564            ret = g_renderer->addImageLayer(name, aggOpts, pos, cache, coverage, shared, visible, minLOD, maxLOD);
    15641565        } else if (driver[0] == 'c' && strcmp(driver, "colorramp") == 0) {
    15651566            osgEarth::Drivers::ColorRampOptions colorRampOpts;
     
    16041605            }
    16051606            colorRampOpts.ramp() = g_renderer->getColorMapFilePath(colormap);
    1606             ret = g_renderer->addImageLayer(name, colorRampOpts, cache, coverage, shared, visible, minLOD, maxLOD);
     1607            ret = g_renderer->addImageLayer(name, colorRampOpts, pos, cache, coverage, shared, visible, minLOD, maxLOD);
    16071608        } else if (driver[0] == 'd' && strcmp(driver, "debug") == 0) {
    16081609            osgEarth::Drivers::DebugOptions opts;
    1609             ret = g_renderer->addImageLayer(name, opts, cache, coverage, shared, visible, minLOD, maxLOD);
     1610            ret = g_renderer->addImageLayer(name, opts, pos, cache, coverage, shared, visible, minLOD, maxLOD);
    16101611        } else if (driver[0] == 'a' && strcmp(driver, "arcgis") == 0) {
    16111612            osgEarth::Drivers::ArcGISOptions opts;
     
    16181619            }
    16191620            //opts.format() = Tcl_GetString(objv[11]);
    1620             ret = g_renderer->addImageLayer(name, opts, cache, coverage, shared, visible, minLOD, maxLOD);
     1621            ret = g_renderer->addImageLayer(name, opts, pos, cache, coverage, shared, visible, minLOD, maxLOD);
    16211622            g_renderer->setImageLayerVisibleRange(name, minRange, maxRange);
    16221623        } else if (driver[0] == 'g' && strcmp(driver, "gdal") == 0) {
    16231624            osgEarth::Drivers::GDALOptions opts;
    16241625            opts.url() = url;
    1625             ret = g_renderer->addImageLayer(name, opts, cache, coverage, shared, visible, minLOD, maxLOD);
     1626            ret = g_renderer->addImageLayer(name, opts, pos, cache, coverage, shared, visible, minLOD, maxLOD);
    16261627            g_renderer->setImageLayerVisibleRange(name, minRange, maxRange);
    16271628        } else if (driver[0] == 't' && strcmp(driver, "tms") == 0) {
     
    16301631            //opts.tmsType() = Tcl_GetString(objv[9]);
    16311632            //opts.format() = Tcl_GetString(objv[10]);
    1632             ret = g_renderer->addImageLayer(name, opts, cache, coverage, shared, visible, minLOD, maxLOD);
     1633            ret = g_renderer->addImageLayer(name, opts, pos, cache, coverage, shared, visible, minLOD, maxLOD);
    16331634            g_renderer->setImageLayerVisibleRange(name, minRange, maxRange);
    16341635        } else if (driver[0] == 'w' && strcmp(driver, "wms") == 0) {
     
    16451646            opts.transparent() = transparent;
    16461647
    1647             ret = g_renderer->addImageLayer(name, opts, cache, coverage, shared, visible, minLOD, maxLOD);
     1648            ret = g_renderer->addImageLayer(name, opts, pos, cache, coverage, shared, visible, minLOD, maxLOD);
    16481649            g_renderer->setImageLayerVisibleRange(name, minRange, maxRange);
    16491650        } else if (driver[0] == 'x' && strcmp(driver, "xyz") == 0) {
     
    16541655            //opts.invertY() = invertY;
    16551656            //opts.format() = Tcl_GetString(objv[9]);
    1656             ret = g_renderer->addImageLayer(name, opts, cache, coverage, shared, visible, minLOD, maxLOD);
     1657            ret = g_renderer->addImageLayer(name, opts, pos, cache, coverage, shared, visible, minLOD, maxLOD);
    16571658            g_renderer->setImageLayerVisibleRange(name, minRange, maxRange);
    16581659        } else {
     
    16841685            osgEarth::Drivers::GDALOptions opts;
    16851686            opts.url() = url;
    1686             g_renderer->addElevationLayer(name, opts, cache, visible, minLOD, maxLOD);
     1687            g_renderer->addElevationLayer(name, opts, pos, cache, visible, minLOD, maxLOD);
    16871688        } else if (driver[0] == 't' && strcmp(driver, "tms") == 0) {
    16881689            osgEarth::Drivers::TMSOptions opts;
     
    16901691            //opts.tmsType() = Tcl_GetString(objv[8]);
    16911692            //opts.format() = Tcl_GetString(objv[9]);
    1692             g_renderer->addElevationLayer(name, opts, cache, visible, minLOD, maxLOD);
     1693            g_renderer->addElevationLayer(name, opts, pos, cache, visible, minLOD, maxLOD);
    16931694        } else if (driver[0] == 'w' && strcmp(driver, "wcs") == 0) {
    16941695            osgEarth::Drivers::WCSOptions opts;
     
    17071708            //opts.srs() = Tcl_GetString(objv[11]);
    17081709            //opts.rangeSubset() = Tcl_GetString(objv[12]);
    1709             g_renderer->addElevationLayer(name, opts, cache, visible, minLOD, maxLOD);
     1710            g_renderer->addElevationLayer(name, opts, pos, cache, visible, minLOD, maxLOD);
    17101711        } else {
    17111712            Tcl_AppendResult(interp, "unknown elevation driver \"", driver,
     
    19431944            return TCL_ERROR;
    19441945        }
    1945         g_renderer->addModelLayer(name, geomOpts, cache, lighting, visible);
     1946        g_renderer->addModelLayer(name, geomOpts, pos, cache, lighting, visible);
    19461947    } else if (type[0] == 'i' && strcmp(type, "icon") == 0) {
    19471948        char *driver = Tcl_GetString(objv[5]);
     
    20552056            return TCL_ERROR;
    20562057        }
    2057         g_renderer->addModelLayer(name, geomOpts, cache, lighting, visible);
     2058        g_renderer->addModelLayer(name, geomOpts, pos, cache, lighting, visible);
    20582059    } else if (type[0] == 'p' && strcmp(type, "point") == 0) {
    20592060        char *driver = Tcl_GetString(objv[5]);
     
    21562157            return TCL_ERROR;
    21572158        }
    2158         g_renderer->addModelLayer(name, geomOpts, cache, lighting, visible);
     2159        g_renderer->addModelLayer(name, geomOpts, pos, cache, lighting, visible);
    21592160    } else if (type[0] == 'p' && strcmp(type, "polygon") == 0) {
    21602161        char *driver = Tcl_GetString(objv[5]);
     
    22762277            return TCL_ERROR;
    22772278        }
    2278         g_renderer->addModelLayer(name, geomOpts, cache, lighting, visible);
     2279        g_renderer->addModelLayer(name, geomOpts, pos, cache, lighting, visible);
    22792280    } else if (type[0] == 'l' && strcmp(type, "line") == 0) {
    22802281        char *driver = Tcl_GetString(objv[5]);
     
    24072408            return TCL_ERROR;
    24082409        }
    2409         g_renderer->addModelLayer(name, geomOpts, cache, lighting, visible);
     2410        g_renderer->addModelLayer(name, geomOpts, pos, cache, lighting, visible);
    24102411   } else if (type[0] == 't' && strcmp(type, "text") == 0) {
    24112412        char *driver = Tcl_GetString(objv[5]);
     
    25212522            return TCL_ERROR;
    25222523        }
    2523         g_renderer->addModelLayer(name, geomOpts, cache, lighting, visible);
     2524        g_renderer->addModelLayer(name, geomOpts, pos, cache, lighting, visible);
    25242525    } else {
    25252526        Tcl_AppendResult(interp, "unknown map layer type \"", type,
Note: See TracChangeset for help on using the changeset viewer.