Skip to content

Commit bd86c2c

Browse files
committed
Fix for embedding legend and scalebar if pixel buffer is not supported with the selected output format (MapServer#4618)
1 parent 551d5f4 commit bd86c2c

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

maplegend.c

+17-6
Original file line numberDiff line numberDiff line change
@@ -632,15 +632,10 @@ int msEmbedLegend(mapObj *map, imageObj *img)
632632
pointObj point;
633633
imageObj *image = NULL;
634634
symbolObj *legendSymbol;
635+
char* imageType = NULL;
635636

636637
rendererVTableObj *renderer;
637638

638-
if(!MS_RENDERER_PLUGIN(map->outputformat) || !MS_MAP_RENDERER(map)->supports_pixel_buffer) {
639-
msSetError(MS_MISCERR, "unsupported output format", "msEmbedLegend()");
640-
return MS_FAILURE;
641-
}
642-
renderer = MS_MAP_RENDERER(map);
643-
644639
s = msGetSymbolIndex(&(map->symbolset), "legend", MS_FALSE);
645640
if(s != -1)
646641
msRemoveSymbol(&(map->symbolset), s); /* solves some caching issues in AGG with long-running processes */
@@ -652,10 +647,26 @@ int msEmbedLegend(mapObj *map, imageObj *img)
652647
map->symbolset.numsymbols++;
653648
initSymbol(legendSymbol);
654649

650+
if(!MS_RENDERER_PLUGIN(map->outputformat) || !MS_MAP_RENDERER(map)->supports_pixel_buffer) {
651+
imageType = msStrdup(map->imagetype); /* save format */
652+
if MS_DRIVER_CAIRO(map->outputformat)
653+
map->outputformat = msSelectOutputFormat( map, "cairopng" );
654+
else
655+
map->outputformat = msSelectOutputFormat( map, "png" );
656+
657+
msInitializeRendererVTable(map->outputformat);
658+
}
659+
renderer = MS_MAP_RENDERER(map);
660+
655661
/* render the legend. */
656662
image = msDrawLegend(map, MS_FALSE);
657663
if( image == NULL ) return -1;
658664

665+
if (imageType) {
666+
map->outputformat = msSelectOutputFormat( map, imageType ); /* restore format */
667+
msFree(imageType);
668+
}
669+
659670
/* copy renderered legend image into symbol */
660671
legendSymbol->pixmap_buffer = calloc(1,sizeof(rasterBufferObj));
661672
MS_CHECK_ALLOC(legendSymbol->pixmap_buffer, sizeof(rasterBufferObj), MS_FAILURE);

mapscale.c

+20-5
Original file line numberDiff line numberDiff line change
@@ -339,24 +339,39 @@ int msEmbedScalebar(mapObj *map, imageObj *img)
339339
int l,index,s;
340340
pointObj point;
341341
imageObj *image = NULL;
342-
rendererVTableObj *renderer = MS_MAP_RENDERER(map);
342+
rendererVTableObj *renderer;
343343
symbolObj *embededSymbol;
344+
char* imageType = NULL;
344345

345-
if( ! renderer ) {
346-
msSetError(MS_MISCERR,"unsupported outputformat","msEmbedScalebar()");
347-
return MS_FAILURE;
348-
}
349346
index = msGetSymbolIndex(&(map->symbolset), "scalebar", MS_FALSE);
350347
if(index != -1)
351348
msRemoveSymbol(&(map->symbolset), index); /* remove cached symbol in case the function is called multiple
352349
times with different zoom levels */
353350

354351
if((embededSymbol=msGrowSymbolSet(&map->symbolset)) == NULL)
355352
return MS_FAILURE;
353+
356354
s = map->symbolset.numsymbols;
357355
map->symbolset.numsymbols++;
358356

357+
if(!MS_RENDERER_PLUGIN(map->outputformat) || !MS_MAP_RENDERER(map)->supports_pixel_buffer) {
358+
imageType = msStrdup(map->imagetype); /* save format */
359+
if MS_DRIVER_CAIRO(map->outputformat)
360+
map->outputformat = msSelectOutputFormat( map, "cairopng" );
361+
else
362+
map->outputformat = msSelectOutputFormat( map, "png" );
363+
364+
msInitializeRendererVTable(map->outputformat);
365+
}
366+
renderer = MS_MAP_RENDERER(map);
367+
359368
image = msDrawScalebar(map);
369+
370+
if (imageType) {
371+
map->outputformat = msSelectOutputFormat( map, imageType ); /* restore format */
372+
msFree(imageType);
373+
}
374+
360375
if(!image) {
361376
return MS_FAILURE;
362377
}

0 commit comments

Comments
 (0)