Index: 2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/data/RasterTiledImageLayer.java
===================================================================
--- 2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/data/RasterTiledImageLayer.java	(revision 460)
+++ 2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/data/RasterTiledImageLayer.java	(revision 461)
@@ -27,16 +27,21 @@
 import gov.nasa.worldwind.avlist.AVKey;
 import gov.nasa.worldwind.avlist.AVList;
 import gov.nasa.worldwind.data.RasterServer;
+import gov.nasa.worldwind.geom.Angle;
+import gov.nasa.worldwind.geom.Extent;
+import gov.nasa.worldwind.geom.Sector;
 import gov.nasa.worldwind.layers.BasicTiledImageLayer;
+import gov.nasa.worldwind.layers.TextureTile;
+import gov.nasa.worldwind.render.DrawContext;
 import gov.nasa.worldwind.retrieve.RetrievalPostProcessor;
 import gov.nasa.worldwind.retrieve.Retriever;
 import gov.nasa.worldwind.retrieve.RetrieverFactory;
+import gov.nasa.worldwind.util.Logging;
 import gov.nasa.worldwind.util.WWUtil;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Element;
-
 import org.gvsig.fmap.mapcontext.MapContext;
 import org.gvsig.fmap.mapcontext.layers.FLayer;
 import org.gvsig.view3d.swing.impl.DefaultMapControl3D;
@@ -153,4 +158,70 @@
         this.setValue(AVKey.RETRIEVER_FACTORY_LOCAL, retrieverFactory);
 
     }
+    
+    protected boolean isTileVisible(DrawContext dc, TextureTile tile) {
+        
+        if(tile.getSector().isWithinLatLonLimits()){
+            return tile.getExtent(dc).intersects(
+                dc.getView().getFrustumInModelCoordinates())
+                && (dc.getVisibleSector() == null || dc.getVisibleSector()
+                .intersects(tile.getSector()));
+        } else {
+            
+            LOG.warn(
+                "Tile sector is out of range Latitude {} {} Longitude {} {}. Trying to adjust sector",
+                new Object[] { tile.getSector().getMinLatitude(),
+                    tile.getSector().getMaxLatitude(),
+                    tile.getSector().getMinLongitude(),
+                    tile.getSector().getMaxLongitude() });
+            
+            // Try to fix extend. This is necessary to avoid problems getting if
+            // some tile is visible or not when the tile has corrupt sector like
+            // ~180.0000001 or -90.000000004561
+            Extent extend = this.fixExtend(tile, dc);
+            return extend.intersects(dc.getView()
+                .getFrustumInModelCoordinates())
+                && (dc.getVisibleSector() == null || dc.getVisibleSector()
+                    .intersects(tile.getSector()));
+        }
+    }
+
+    private Extent fixExtend(TextureTile tile, DrawContext dc) {
+        
+        if (dc == null) {
+            String msg = Logging.getMessage("nullValue.DrawContextIsNull");
+            Logging.logger().severe(msg);
+            throw new IllegalArgumentException(msg);
+        }
+        
+        if ( tile.getSector().isWithinLatLonLimits()){
+            return Sector.computeBoundingBox(dc.getGlobe(),
+                dc.getVerticalExaggeration(), tile.getSector());
+        } else {
+            
+            double[] degreesArray = tile.getSector().asDegreesArray();
+            
+            double minLatitude =
+                degreesArray[0] < Angle.NEG90.degrees ? Angle.NEG90.degrees
+                    : degreesArray[0];
+            double maxLatitude =
+                degreesArray[1] > Angle.POS90.degrees ? Angle.POS90.degrees
+                    : degreesArray[1];
+            double minLongitude =
+                degreesArray[2] < Angle.NEG180.degrees ? Angle.NEG180.degrees
+                    : degreesArray[2];
+            double maxLongitude =
+                degreesArray[3] > Angle.POS180.degrees ? Angle.POS180.degrees
+                    : degreesArray[3];
+            
+            Sector adjustedSector =
+                new Sector(Angle.fromDegrees(minLatitude),
+                    Angle.fromDegrees(maxLatitude),
+                    Angle.fromDegrees(minLongitude),
+                    Angle.fromDegrees(maxLongitude));
+            
+            return Sector.computeBoundingBox(dc.getGlobe(),
+                dc.getVerticalExaggeration(), adjustedSector);
+        }
+    }
 }
Index: 2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/data/DefaultLayerConverter.java
===================================================================
--- 2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/data/DefaultLayerConverter.java	(revision 460)
+++ 2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/data/DefaultLayerConverter.java	(revision 461)
@@ -170,7 +170,7 @@
             scale * rasterTileDelta.getLongitude().degrees);
         params.setValue(AVKey.LEVEL_ZERO_TILE_DELTA, levelZeroTileDelta);
         
-        //Only rasterized vectorial layers
+        // Only rasterized vectorial layers
         // params.setValue(AVKey.LEVEL_ZERO_TILE_DELTA, new
         // LatLon(Angle.fromDegrees(1), Angle.fromDegrees(1)));
 
@@ -199,13 +199,21 @@
                 new Point2D.Double(envelope.getMaximum(0), envelope
                     .getMaximum(1)));
         
-        double minLatitude = Double.isInfinite(p1.getY()) ? Angle.NEG90.degrees : p1.getY();
-        double maxLatitude = Double.isInfinite(p2.getY()) ? Angle.POS90.degrees : p2.getY();
-        double minLongitude = Double.isInfinite(p1.getX()) ? Angle.NEG180.degrees : p1.getX();
-        double maxLongitude = Double.isInfinite(p2.getX()) ? Angle.POS180.degrees : p2.getX();
+        double minLatitude =
+            Double.isInfinite(p1.getY()) || p1.getY() < Angle.NEG90.degrees
+                ? Angle.NEG90.degrees : p1.getY();
+        double maxLatitude =
+            Double.isInfinite(p2.getY()) || p2.getY() > Angle.POS90.degrees
+                ? Angle.POS90.degrees : p2.getY();
+        double minLongitude =
+            Double.isInfinite(p1.getX()) || p1.getX() < Angle.NEG180.degrees
+                ? Angle.NEG180.degrees : p1.getX();
+        double maxLongitude =
+            Double.isInfinite(p2.getX()) || p2.getX() > Angle.POS180.degrees
+                ? Angle.POS180.degrees : p2.getX();
 
         Sector sector =
-            new Sector(Sector.fromDegrees(minLatitude, maxLatitude,
+            new Sector(Sector.fromDegrees(minLatitude,maxLatitude,
                 minLongitude, maxLongitude));
 
         return sector;
