From 6a5cad3dbc10e2cafd95269402a92fda34d01385 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Thu, 12 Oct 2017 14:39:28 +0200 Subject: [PATCH] msLayerIsVisible(): speed it up by doing layer vs map scale comparisons before extent comparison --- mapdraw.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/mapdraw.c b/mapdraw.c index 01848199ea..41ac8903dd 100644 --- a/mapdraw.c +++ b/mapdraw.c @@ -594,17 +594,8 @@ int msLayerIsVisible(mapObj *map, layerObj *layer) if(layer->type == MS_LAYER_QUERY || layer->type == MS_LAYER_TILEINDEX) return(MS_FALSE); if((layer->status != MS_ON) && (layer->status != MS_DEFAULT)) 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 ) { - if( layer->debug >= MS_DEBUGLEVEL_V ) { - msDebug("msLayerIsVisible(): Skipping layer (%s) because LAYER.EXTENT does not intersect MAP.EXTENT\n", layer->name); - } - return(MS_FALSE); - } - - if(msEvalContext(map, layer, layer->requires) == MS_FALSE) return(MS_FALSE); - + /* Do comparisons of layer scale vs map scale now, since msExtentsOverlap() */ + /* can be slow */ if(map->scaledenom > 0) { /* layer scale boundaries should be checked first */ @@ -614,13 +605,27 @@ int msLayerIsVisible(mapObj *map, layerObj *layer) } return(MS_FALSE); } - if((layer->minscaledenom > 0) && (map->scaledenom <= layer->minscaledenom)) { + if(/*(layer->minscaledenom > 0) &&*/ (map->scaledenom <= layer->minscaledenom)) { if( layer->debug >= MS_DEBUGLEVEL_V ) { msDebug("msLayerIsVisible(): Skipping layer (%s) because LAYER.MINSCALE is too large for this MAP scale\n", layer->name); } 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 ) { + if( layer->debug >= MS_DEBUGLEVEL_V ) { + msDebug("msLayerIsVisible(): Skipping layer (%s) because LAYER.EXTENT does not intersect MAP.EXTENT\n", layer->name); + } + return(MS_FALSE); + } + + if(msEvalContext(map, layer, layer->requires) == MS_FALSE) return(MS_FALSE); + + if(map->scaledenom > 0) { + /* now check class scale boundaries (all layers *must* pass these tests) */ if(layer->numclasses > 0) { for(i=0; inumclasses; i++) {