[mapserver-dev] labelcache and multiple calls to msDrawMap

Jill Vogel jill at emeraldgate.com
Thu Oct 3 22:30:07 EDT 2002


Hi,

I'm working on a standalone app that uses mapserver 3.6.1.  I'm trying
to keep one mapObj* that I can draw multiple times, so I don't have to
keep creating a new one every time the map gets drawn.

Using the itasca demo, the problem occurs whenever I enable the
majrdln3_anno layer, draw the map, disable the layer, and redraw.  The
symbols for the layer are still displayed, even though the layer is off.
This doesn't happen for any other layers, and occurs regardless of which 
other layers are on at the time.

See below for some code that reproduces the issue.


It appears that the trouble lies in the map's labelcache; it isn't being
cleared after msDrawMap is done drawing. 

Is the labelcache used anywhere else?  Is it safe/smart to clear it
completely after drawing the map?  

I haven't spent much time in the mapserver code, so any information about the
labelcache ( or hints for my code snippet ) would be helpful.

Thanks!

Jill

----------------------------------------------------------------------
void TestLabelCacheBug()
{
	  /* Set path to your path to the itasca demo */
    char *path = ".../demo/itasca/";
    char *fullfile = (char *)malloc( strlen( path ) + 20 );
    FILE *file = 0;
    
    mapObj *map = NULL;
    size_t layerId = 8;     /* Id of the majrdln3_anno layer */
    gdImagePtr im = 0;
    
    /* Load demo.map */
    sprintf( fullfile, "%sdemo.map", path );
    map = msLoadMap( fullfile, NULL );
    if ( !map )
    {
        errorObj *err = msGetErrorObj();
        fprintf( stderr, "Error in %s (%d): %s\n",
                 err->routine, err->code, err->message );

        free( fullfile );
        return;
    }
    
    /* Draw the default map to default.png */
    im = msDrawMap( map );
    sprintf( fullfile, "%sdefault.png", path );
    file = fopen( fullfile, "wb" );
    gdImagePng( im, file );
    fclose( file );
    
    /* Turn on the symbol layer, and draw again */
    map->layers[layerId].status = MS_ON;
    im = msDrawMap( map );
    sprintf( fullfile, "%slayer_on.png", path );
    file = fopen( fullfile, "wb" );
    gdImagePng( im, file );
    fclose( file );
    
    /* Turn the symbol layer back off, and draw again */
    map->layers[layerId].status = MS_OFF;
    im = msDrawMap( map );
    sprintf( fullfile, "%slayer_off.png", path );
    file = fopen( fullfile, "wb" );
    gdImagePng( im, file );
    fclose( file );
    
    free( fullfile );
    msFreeMap( map );
}




More information about the mapserver-dev mailing list