[mapserver-commits] r12802 - sandbox/sdlime/rfc-77

svn at osgeo.org svn at osgeo.org
Fri Nov 25 13:59:24 EST 2011


Author: sdlime
Date: 2011-11-25 10:59:23 -0800 (Fri, 25 Nov 2011)
New Revision: 12802

Modified:
   sandbox/sdlime/rfc-77/maplegend.c
Log:
Updated a few things with legend embedding to deal with multiple class labels.

Modified: sandbox/sdlime/rfc-77/maplegend.c
===================================================================
--- sandbox/sdlime/rfc-77/maplegend.c	2011-11-25 18:10:22 UTC (rev 12801)
+++ sandbox/sdlime/rfc-77/maplegend.c	2011-11-25 18:59:23 UTC (rev 12802)
@@ -144,18 +144,18 @@
     if (theclass->numstyles > 0) {
       for(i=0; i<theclass->numstyles; i++)
         msDrawMarkerSymbol(&map->symbolset, image_draw, &marker, theclass->styles[i], lp->scalefactor);          
-    } else if (theclass->label.size!=-1) {
-      labelObj label = theclass->label;
-      double lsize = label.size;
-      double langle = label.angle;
-      int lpos = label.position;
-      label.angle = 0;
-      label.position = MS_CC;
-      if (label.type == MS_TRUETYPE) label.size = height;
-      msDrawLabel(map, image_draw, marker, (char*)"Az", &label,1.0);
-      label.size = lsize;
-      label.position = lpos;
-      label.angle = langle;
+    } else if (theclass->labels && theclass->numlabels > 0) {
+      labelObj *label = theclass->labels[0]; /* use the first label definition */
+      double lsize = label->size;
+      double langle = label->angle;
+      int lpos = label->position;
+      label->angle = 0;
+      label->position = MS_CC;
+      if (label->type == MS_TRUETYPE) label->size = height;
+      msDrawLabel(map, image_draw, marker, (char*)"Az", label, 1.0);
+      label->size = lsize;
+      label->position = lpos;
+      label->angle = langle;
     }
     break;
   case MS_LAYER_POINT:
@@ -626,8 +626,7 @@
   if(s != -1) 
     msRemoveSymbol(&(map->symbolset), s); /* solves some caching issues in AGG with long-running processes */
 
-  if(msGrowSymbolSet(&map->symbolset) == NULL)
-    return -1;
+  if(msGrowSymbolSet(&map->symbolset) == NULL) return MS_FAILURE;
   s = map->symbolset.numsymbols;
   legendSymbol = map->symbolset.symbol[s];
   map->symbolset.numsymbols++;
@@ -635,29 +634,25 @@
 
   /* render the legend. */
   image = msDrawLegend(map, MS_FALSE);
-  if( image == NULL ) return -1;
+  if( image == NULL ) return MS_FAILURE;
 
   /* copy renderered legend image into symbol */
   legendSymbol->pixmap_buffer = calloc(1,sizeof(rasterBufferObj));
   MS_CHECK_ALLOC(legendSymbol->pixmap_buffer, sizeof(rasterBufferObj), MS_FAILURE);
 
-  if(MS_SUCCESS != renderer->getRasterBufferCopy(image,legendSymbol->pixmap_buffer))
-	  return MS_FAILURE;
+  if(MS_SUCCESS != renderer->getRasterBufferCopy(image,legendSymbol->pixmap_buffer)) return MS_FAILURE;
   legendSymbol->renderer = renderer;
 
   msFreeImage( image );
 
-  if(!legendSymbol->pixmap_buffer) return(-1); /* something went wrong creating scalebar */
+  if(!legendSymbol->pixmap_buffer) 
+    return MS_FAILURE; /* something went wrong creating legend */
 
   legendSymbol->type = MS_SYMBOL_PIXMAP; /* intialize a few things */
   legendSymbol->name = msStrdup("legend");  
   legendSymbol->sizex = legendSymbol->pixmap_buffer->width;
   legendSymbol->sizey = legendSymbol->pixmap_buffer->height;
 
-  /* I'm not too sure this test is sufficient ... NFW. */
-  /* if(map->legend.transparent == MS_ON) */
-  /*  gdImageColorTransparent(legendSymbol->img_deprecated, 0); */
-
   switch(map->legend.position) {
   case(MS_LL):
     point.x = MS_NINT(legendSymbol->sizex/2.0);
@@ -687,17 +682,15 @@
 
   l = msGetLayerIndex(map, "__embed__legend");
   if(l == -1) {
-    if(msGrowMapLayers(map) == NULL)
-        return(-1);
+    if(msGrowMapLayers(map) == NULL) return MS_FAILURE;
     l = map->numlayers;
     map->numlayers++;
-    if(initLayer((GET_LAYER(map, l)), map) == -1) return(-1);
+    if(initLayer((GET_LAYER(map, l)), map) == -1) return MS_FAILURE;
     GET_LAYER(map, l)->name = msStrdup("__embed__legend");
     GET_LAYER(map, l)->type = MS_LAYER_ANNOTATION;
 
-    if(msGrowLayerClasses( GET_LAYER(map, l) ) == NULL)
-        return(-1);
-    if(initClass(GET_LAYER(map, l)->class[0]) == -1) return(-1);
+    if(msGrowLayerClasses( GET_LAYER(map, l) ) == NULL) return MS_FAILURE;
+    if(initClass(GET_LAYER(map, l)->class[0]) == -1) return MS_FAILURE;
     GET_LAYER(map, l)->numclasses = 1; /* so we make sure to free it */
         
     /* update the layer order list with the layer's index. */
@@ -709,10 +702,13 @@
   if(msMaybeAllocateClassStyle(GET_LAYER(map, l)->class[0], 0)==MS_FAILURE) return MS_FAILURE;
   GET_LAYER(map, l)->class[0]->styles[0]->symbol = s;
   GET_LAYER(map, l)->class[0]->styles[0]->color.pen = -1;
-  GET_LAYER(map, l)->class[0]->label.force = MS_TRUE;
-  GET_LAYER(map, l)->class[0]->label.size = MS_MEDIUM; /* must set a size to have a valid label definition */
-  GET_LAYER(map, l)->class[0]->label.priority = MS_MAX_LABEL_PRIORITY;
 
+  if(msGrowClassLabels(GET_LAYER(map, l)->class[0]) == NULL) return(MS_FAILURE);
+  initLabel(GET_LAYER(map, l)->class[0]->labels[0]); /* necessary? */
+  GET_LAYER(map, l)->class[0]->labels[0]->force = MS_TRUE;
+  GET_LAYER(map, l)->class[0]->labels[0]->size = MS_MEDIUM; /* must set a size to have a valid label definition */
+  GET_LAYER(map, l)->class[0]->labels[0]->priority = MS_MAX_LABEL_PRIORITY;
+
   if(map->legend.postlabelcache) /* add it directly to the image */
     msDrawMarkerSymbol(&map->symbolset, img, &point, GET_LAYER(map, l)->class[0]->styles[0], 1.0);
   else
@@ -721,5 +717,5 @@
   /* Mark layer as deleted so that it doesn't interfere with html legends or with saving maps */
   GET_LAYER(map, l)->status = MS_DELETE;
 
-  return(0);
+  return MS_SUCCESS;
 }



More information about the mapserver-commits mailing list