Example #1
0
        protected void setCenterAndRadius(osg.Node node, GeoExtent cell_extent, SmartReadCallback reader)
        {
            SpatialReference srs = map_layer.getOutputSRS(getSession(), getTerrainSRS());
            // first get the output srs centroid:
            GeoPoint centroid = srs.transform(cell_extent.getCentroid());
            GeoPoint sw       = srs.transform(cell_extent.getSouthwest());

            double radius = map_layer.getEncodeCellRadius() ?
                            (centroid - sw).length() :
                            -1.0;

            if (terrain_node.valid() && terrain_srs != null)
            {
                GeoPoint clamped;
                for (int t = 0; t < 5; t++)
                {
                    clamped = GeomUtils.clampToTerrain(centroid, terrain_node.get(), terrain_srs, reader);
                    if (!clamped.isValid())
                    {
                        // if the clamp failed, it's due to the geocentric intersection bug in which the isect
                        // fails when coplanar with a tile boundary/skirt. Fudge the centroid and try again.
                        double fudge = 0.001 * ((double)(1 + (Random.Rand() % 10)));
                        centroid.X += fudge;
                        centroid.Y -= fudge;
                        centroid.Z += fudge * fudge;
                    }
                    else
                    {
                        break;
                    }
                }

                if (!clamped.isValid())
                {
                    SpatialReference geo    = srs.getGeographicSRS();
                    GeoPoint         latlon = geo.transform(centroid);
                    //osgGIS.warn() << "*** UNABLE TO CLAMP CENTROID: ***" << latlon.toString() << std.endl;
                }
                else
                {
                    centroid = clamped;
                }
            }
            else
            {
                //osgGIS.warn() << "*** Failed to clamp Center/Radius for cell" << std.endl;
            }

            if (node is osg.LOD)
            {
                osg.LOD plod = (osg.LOD)node;
                plod.setCenter(centroid);
                plod.setRadius(radius);
            }
            else if (node is osg.ProxyNode)
            {
                osg.ProxyNode proxy = (osg.ProxyNode)node;
                proxy.setCenter(centroid);
                proxy.setRadius(radius);
            }
        }