[mapserver-dev] labelcache and multiple calls to msDrawMap

Steve Lime steve.lime at dnr.state.mn.us
Mon Oct 7 15:39:34 EDT 2002


What language are you using? In perl there is a method for a
labelCacheObj to clear the cache. You'd use it like this:

  $map->{labelcache}->freeCache();

and then continue drawing. I don't know if such a beast exists for
PHP/MapScript. 

Oops, I see you're using C. Here's the C code wrapped by the
freeCache() method above. I didn't write it but it appears to work ok.

void freeCache(labelCacheObj *self) {
    int i;
    for (i = 0; i < self->numlabels; i++) {
        free(self->labels[i].string);
        msFreeShape(self->labels[i].poly);
    }   
    self->numlabels = 0;
    for (i = 0; i < self->nummarkers; i++) {
        msFreeShape(self->markers[i].poly);
    }
    self->nummarkers = 0;
}

Steve

Stephen Lime
Data & Applications Manager

Minnesota DNR
500 Lafayette Road
St. Paul, MN 55155
651-297-2937

>>> Jill Vogel <jill at emeraldgate.com> 10/03/02 09:30PM >>>
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