Index: mapserver.h
===================================================================
--- mapserver.h	(revision 9082)
+++ mapserver.h	(working copy)
@@ -136,6 +136,7 @@
 
 #define MS_TRUE 1 /* logical control variables */
 #define MS_FALSE 0
+#define MS_UNKNOWN -1
 #define MS_ON 1
 #define MS_OFF 0
 #define MS_DEFAULT 2
@@ -2028,6 +2029,9 @@
 /* ==================================================================== */
 /*      Prototypes for functions in maputil.c                           */
 /* ==================================================================== */
+
+MS_DLL_EXPORT int msExtentsOverlap(mapObj *map, layerObj *layer);
+
 /* For mappdf */
 MS_DLL_EXPORT int getRgbColor(mapObj *map,int i,int *r,int *g,int *b); /* maputil.c */
 MS_DLL_EXPORT int msBindLayerToShape(layerObj *layer, shapeObj *shape, int querymapMode);
Index: maputil.c
===================================================================
--- maputil.c	(revision 9082)
+++ maputil.c	(working copy)
@@ -39,6 +39,7 @@
 #include "mapparser.h"
 #include "mapthread.h"
 #include "mapfile.h"
+#include "mapcopy.h"
 
 #ifdef _WIN32
 #include <fcntl.h>
@@ -1785,3 +1786,58 @@
     return MS_SUCCESS;
 }
 
+/*
+** Issue #3043: Layer extent comparison short circuit.
+**
+** msExtentsOverlap()
+** returns MS_TRUE if overlap, MS_FALSE if disjoin, MS_UNKNOWN if not enough info to calculate
+**
+*/
+int msExtentsOverlap(mapObj *map, layerObj *layer)
+{
+    rectObj map_extent;
+    rectObj layer_extent;
+    
+    /* No extent info? Nothing we can do, return MS_UNKNOWN. */
+    if( (map->extent.minx == -1) && (map->extent.miny == -1) && (map->extent.maxx == -1 ) && (map->extent.maxy == -1) ) return MS_UNKNOWN;
+    if( (layer->extent.minx == -1) && (layer->extent.miny == -1) && (layer->extent.maxx == -1 ) && (layer->extent.maxy == -1) ) return MS_UNKNOWN;
+        
+#ifdef USE_PROJ
+
+    /* No map projection? Let someone else sort this out. */
+    if( ! (map->projection.numargs > 0) ) 
+        return MS_UNKNOWN;
+
+    /* No layer projection? Perform naive comparison, because they are 
+    ** in the same projection. */
+    if( ! (layer->projection.numargs > 0) ) 
+        return msRectOverlap( &(map->extent), &(layer->extent) );
+    
+    /* We need to transform our rectangles for comparison, 
+    ** so we will work with copies and leave the originals intact. */
+    MS_COPYRECT(&map_extent, &(map->extent) );
+    MS_COPYRECT(&layer_extent, &(layer->extent) );
+
+    /* Transform map extents into geographics for comparison. */
+    if( msProjectRect(&(map->projection), &(map->latlon), &map_extent) )
+        return MS_UNKNOWN;
+        
+    /* Transform layer extents into geographics for comparison. */
+    if( msProjectRect(&(layer->projection), &(map->latlon), &layer_extent) )
+        return MS_UNKNOWN;
+
+    /* Simple case? Return simple answer. */
+    if ( map_extent.minx < map_extent.maxx && layer_extent.minx < layer_extent.maxx )
+        return msRectOverlap( &(map_extent), &(layer_extent) );
+        
+    /* Uh oh, one of the rects crosses the dateline!
+    ** Let someone else handle it. */
+    return MS_UNKNOWN;
+   
+#else
+    /* No proj? Naive comparison. */
+    if( msRectOverlap( &(map->extent), &(layer->extent) ) return MS_TRUE;
+    return MS_FALSE;
+#endif
+
+}
Index: mapdraw.c
===================================================================
--- mapdraw.c	(revision 9082)
+++ mapdraw.c	(working copy)
@@ -644,6 +644,10 @@
       if((layer->mingeowidth > 0) && ((map->extent.maxx - map->extent.minx) < layer->mingeowidth)) return(MS_FALSE);
   }
 
+  /* Only return MS_FALSE if it is definitely false. Sometimes it will return MS_UNKNOWN, which we 
+  ** consider true, for this use case (it might be visible, try and draw it, see what happens). */
+  if ( msExtentsOverlap(map, layer) == MS_FALSE ) return(MS_FALSE);
+
   return MS_TRUE;  /* All tests passed.  Layer is visible. */
 }
 /*

