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

svn at osgeo.org svn at osgeo.org
Mon Nov 21 23:40:18 EST 2011


Author: sdlime
Date: 2011-11-21 20:40:18 -0800 (Mon, 21 Nov 2011)
New Revision: 12790

Modified:
   sandbox/sdlime/rfc-77/mapserver.h
   sandbox/sdlime/rfc-77/maptemplate.c
   sandbox/sdlime/rfc-77/maputil.c
Log:
Changed signature for msShapeGetAnnotation() to return an int (MS_SUCCESS/MS_FAILURE). For RFC 77 much of the work will be done in this function.

Modified: sandbox/sdlime/rfc-77/mapserver.h
===================================================================
--- sandbox/sdlime/rfc-77/mapserver.h	2011-11-21 13:25:43 UTC (rev 12789)
+++ sandbox/sdlime/rfc-77/mapserver.h	2011-11-22 04:40:18 UTC (rev 12790)
@@ -2275,7 +2275,7 @@
 MS_DLL_EXPORT int msEvalContext(mapObj *map, layerObj *layer, char *context);
 MS_DLL_EXPORT int msEvalExpression(layerObj *layer, shapeObj *shape, expressionObj *expression, int itemindex);
 MS_DLL_EXPORT int msShapeGetClass(layerObj *layer, mapObj *map, shapeObj *shape, int *classgroup, int numclasses);
-MS_DLL_EXPORT char *msShapeGetAnnotation(layerObj *layer, shapeObj *shape);
+MS_DLL_EXPORT int msShapeGetAnnotation(layerObj *layer, shapeObj *shape);
 MS_DLL_EXPORT int msShapeCheckSize(shapeObj *shape, double minfeaturesize);
 MS_DLL_EXPORT int msAdjustImage(rectObj rect, int *width, int *height);
 MS_DLL_EXPORT double msAdjustExtent(rectObj *rect, int width, int height);

Modified: sandbox/sdlime/rfc-77/maptemplate.c
===================================================================
--- sandbox/sdlime/rfc-77/maptemplate.c	2011-11-21 13:25:43 UTC (rev 12789)
+++ sandbox/sdlime/rfc-77/maptemplate.c	2011-11-22 04:40:18 UTC (rev 12790)
@@ -926,10 +926,11 @@
 
     mapserv->resultshape.classindex = msShapeGetClass(layer, layer->map, &mapserv->resultshape,  NULL, -1);
 
-    if ( mapserv->resultshape.classindex>=0 &&
-         (layer->class[mapserv->resultshape.classindex]->text.string || layer->labelitem) && 
-         layer->class[mapserv->resultshape.classindex]->label.size != -1)
-      mapserv->resultshape.text = msShapeGetAnnotation(layer, & mapserv->resultshape);
+    // if ( mapserv->resultshape.classindex>=0 &&
+    //      (layer->class[mapserv->resultshape.classindex]->text.string || layer->labelitem) && 
+    //     layer->class[mapserv->resultshape.classindex]->label.size != -1)
+    if(layer->class[mapserv->resultshape.classindex]->numlabels > 0)
+      msShapeGetAnnotation(layer, &mapserv->resultshape); // RFC 77 TODO: check return value
 
     /* prepare any necessary JOINs here (one-to-one only) */
     if(layer->numjoins > 0) {
@@ -1496,351 +1497,307 @@
   return(MS_SUCCESS);
 }
 
+// RFC 77 TODO: Need to validate these changes with Assefa...
+static int processShplabelTag(layerObj *layer, char **line, shapeObj *origshape) {
+  char *tag, *tagStart, *tagEnd;
+  char *tagValue=NULL;
+  hashTableObj *tagArgs=NULL;
+  int tagOffset, tagLength;
+  char *format;
+  char *argValue=NULL;
+  char *projectionString=NULL;
+  shapeObj tShape;
+  int precision=0;
+  int clip_to_map=MS_TRUE;
+  int use_label_settings=MS_FALSE;
+  double cellsize=0;
+  int labelposvalid = MS_FALSE;
+  pointObj labelPos;
+  int i,status;
+  char number[64]; /* holds a single number in the extent */
+  char numberFormat[16];
+  shapeObj *shape = NULL;
 
-static int processShplabelTag(layerObj *layer, char **line, shapeObj *origshape) 
-{
-    char *tag, *tagStart, *tagEnd;
-    char *tagValue=NULL;
-    hashTableObj *tagArgs=NULL;
-    int tagOffset, tagLength;
-    char *format;
-    char *argValue=NULL;
-    char *projectionString=NULL;
-    shapeObj tShape;
-    int precision=0;
-    int clip_to_map=MS_TRUE;
-    int use_label_settings=MS_FALSE;
-    double cellsize=0;
-    int labelposvalid = MS_FALSE;
-    pointObj labelPos;
-    int i,status;
-    char number[64]; /* holds a single number in the extent */
-    char numberFormat[16];
-    shapeObj *shape = NULL;
-
-    if(!*line) {
+  if(!*line) {
     msSetError(MS_WEBERR, "Invalid line pointer.", "processShplabelTag()");
     return(MS_FAILURE);
-    }
-    if( msCheckParentPointer(layer->map,"map")==MS_FAILURE )
-      return MS_FAILURE;
+  }
+  if(msCheckParentPointer(layer->map,"map") == MS_FAILURE)
+    return MS_FAILURE;
   
-    tagStart = findTag(*line, "shplabel");
+  tagStart = findTag(*line, "shplabel");
 
-    /* It is OK to have no shplabel tags, just return. */
-    if( !tagStart )
-      return MS_SUCCESS;
+  /* It is OK to have no shplabel tags, just return. */
+  if(!tagStart)
+    return MS_SUCCESS;
 
-    if(!origshape || origshape->numlines <= 0) { /* I suppose we need to make sure the part has vertices (need shape checker?) */
-      msSetError(MS_WEBERR, "Null or empty shape.", "processShplabelTag()");
-      return(MS_FAILURE);
-    }
-
+  if(!origshape || origshape->numlines <= 0) { /* I suppose we need to make sure the part has vertices (need shape checker?) */
+    msSetError(MS_WEBERR, "Null or empty shape.", "processShplabelTag()");
+    return(MS_FAILURE);
+  }
     
-    while (tagStart) 
-    {
-        if (shape)
-          msFreeShape(shape);
-        shape = (shapeObj *) msSmallMalloc(sizeof(shapeObj));
-        msInitShape(shape);
-        msCopyShape(origshape, shape);
+  while(tagStart) {
+    if(shape) msFreeShape(shape);
+    shape = (shapeObj *) msSmallMalloc(sizeof(shapeObj));
+    msInitShape(shape);
+    msCopyShape(origshape, shape);
 
-        projectionString = NULL;
-        format = "$x,$y";
-        tagOffset = tagStart - *line;
+    projectionString = NULL;
+    format = "$x,$y";
+    tagOffset = tagStart - *line;
 
-        if(getTagArgs("shplabel", tagStart, &tagArgs) != MS_SUCCESS) return(MS_FAILURE);
-        if(tagArgs) 
-        {
-            argValue = msLookupHashTable(tagArgs, "format");
-            if(argValue) format = argValue;
+    if(getTagArgs("shplabel", tagStart, &tagArgs) != MS_SUCCESS) return(MS_FAILURE);
+    if(tagArgs) {
+      argValue = msLookupHashTable(tagArgs, "format");
+      if(argValue) format = argValue;
 
-            argValue = msLookupHashTable(tagArgs, "precision");
-            if(argValue) precision = atoi(argValue);
+      argValue = msLookupHashTable(tagArgs, "precision");
+      if(argValue) precision = atoi(argValue);
 
-            argValue = msLookupHashTable(tagArgs, "proj");
-            if(argValue) projectionString = argValue;
+      argValue = msLookupHashTable(tagArgs, "proj");
+      if(argValue) projectionString = argValue;
 
-            argValue = msLookupHashTable(tagArgs, "clip_to_map");
-            if(argValue) 
-              if(strcasecmp(argValue,"false") == 0) clip_to_map = MS_FALSE;
+      argValue = msLookupHashTable(tagArgs, "clip_to_map");
+      if(argValue) {
+        if(strcasecmp(argValue,"false") == 0) clip_to_map = MS_FALSE;
+      }
 
-            argValue = msLookupHashTable(tagArgs, "use_label_settings");
-            if(argValue) 
-              if(strcasecmp(argValue,"true") == 0) use_label_settings = MS_TRUE;
-        }
+      argValue = msLookupHashTable(tagArgs, "use_label_settings");
+      if(argValue) { 
+        if(strcasecmp(argValue,"true") == 0) use_label_settings = MS_TRUE;
+      }
+    }
 
-        labelPos.x = -1;
-        labelPos.y = -1;
-        msInitShape(&tShape);
+    labelPos.x = -1;
+    labelPos.y = -1;
+    msInitShape(&tShape);
 
-        tShape.type = MS_SHAPE_LINE;
-        tShape.line = (lineObj *) msSmallMalloc(sizeof(lineObj));
-        tShape.numlines = 1;
-        tShape.line[0].point = NULL; /* initialize the line */
-        tShape.line[0].numpoints = 0;
+    tShape.type = MS_SHAPE_LINE;
+    tShape.line = (lineObj *) msSmallMalloc(sizeof(lineObj));
+    tShape.numlines = 1;
+    tShape.line[0].point = NULL; /* initialize the line */
+    tShape.line[0].numpoints = 0;
 
-        if (layer->map->cellsize <= 0)
-        cellsize = MS_MAX(MS_CELLSIZE(layer->map->extent.minx, layer->map->extent.maxx, layer->map->width), 
-                          MS_CELLSIZE(layer->map->extent.miny, layer->map->extent.maxy, layer->map->height));
-        else
-          cellsize = layer->map->cellsize ;
+    if(layer->map->cellsize <= 0)
+      cellsize = MS_MAX(MS_CELLSIZE(layer->map->extent.minx, layer->map->extent.maxx, layer->map->width), MS_CELLSIZE(layer->map->extent.miny, layer->map->extent.maxy, layer->map->height));
+    else
+      cellsize = layer->map->cellsize ;
 
-        if (shape->type == MS_SHAPE_POINT)
-        {
-            labelposvalid = MS_FALSE;
-            if (shape->numlines > 0 && shape->line[0].numpoints > 0)
-            {
-                labelposvalid = MS_TRUE;
-                labelPos = shape->line[0].point[0];
-                if(layer->transform == MS_TRUE) 
-                {
-                    if (layer->project && 
-                        msProjectionsDiffer(&(layer->projection), &(layer->map->projection)))
-                      msProjectShape(&layer->projection, &layer->map->projection, shape);
+    if(shape->type == MS_SHAPE_POINT) {
+      labelposvalid = MS_FALSE;
+      if(shape->numlines > 0 && shape->line[0].numpoints > 0) {
+        labelposvalid = MS_TRUE;
+        labelPos = shape->line[0].point[0];
+        if(layer->transform == MS_TRUE) {
+          if(layer->project && msProjectionsDiffer(&(layer->projection), &(layer->map->projection)))
+             msProjectShape(&layer->projection, &layer->map->projection, shape);
               
-                    labelPos = shape->line[0].point[0];
-                    labelPos.x = MS_MAP2IMAGE_X(labelPos.x, layer->map->extent.minx, cellsize);
-                    labelPos.y = MS_MAP2IMAGE_Y(labelPos.y, layer->map->extent.maxy, cellsize);
-                }
-            }
-          
+          labelPos = shape->line[0].point[0];
+          labelPos.x = MS_MAP2IMAGE_X(labelPos.x, layer->map->extent.minx, cellsize);
+          labelPos.y = MS_MAP2IMAGE_Y(labelPos.y, layer->map->extent.maxy, cellsize);
         }
-        else if (shape->type == MS_SHAPE_LINE)
-        {
-            pointObj     **annopoints = NULL;
-            double** angles = NULL, **lengths = NULL;
-            int numpoints = 1;
+      }  
+    } else if(shape->type == MS_SHAPE_LINE) {
+      pointObj **annopoints = NULL;
+      double **angles = NULL, **lengths = NULL;
+      int numpoints = 1;
 
-            labelposvalid = MS_FALSE;
-            if(layer->transform == MS_TRUE) {
-                if (layer->project && 
-                    msProjectionsDiffer(&(layer->projection), &(layer->map->projection)))
-                  msProjectShape(&layer->projection, &layer->map->projection, shape);
-                if (clip_to_map)
-                  msClipPolylineRect(shape, layer->map->extent);
-         
+      labelposvalid = MS_FALSE;
+      if(layer->transform == MS_TRUE) {
+        if(layer->project && msProjectionsDiffer(&(layer->projection), &(layer->map->projection)))
+          msProjectShape(&layer->projection, &layer->map->projection, shape);
+        if(clip_to_map)
+          msClipPolylineRect(shape, layer->map->extent);
 
-                msTransformShapeToPixelRound(shape, layer->map->extent, cellsize);
-            }
-            else
-              msOffsetShapeRelativeTo(shape, layer);
+        msTransformShapeToPixelRound(shape, layer->map->extent, cellsize);
+      } else
+        msOffsetShapeRelativeTo(shape, layer);
 
-            if (shape->numlines > 0)
-            {
-                annopoints = msPolylineLabelPoint(shape, -1, 0, &angles, &lengths, &numpoints, MS_FALSE);
-                if (numpoints > 0)
-                {
-                    /*convert to geo*/
-                    labelPos.x = annopoints[0]->x;
-                    labelPos.y = annopoints[0]->y;
+      if(shape->numlines > 0) {
+        annopoints = msPolylineLabelPoint(shape, -1, 0, &angles, &lengths, &numpoints, MS_FALSE);
+        if(numpoints > 0) {
+          /* convert to geo */
+          labelPos.x = annopoints[0]->x;
+          labelPos.y = annopoints[0]->y;
                 
-                    labelposvalid = MS_TRUE;
-                    for (i=0; i<numpoints; i++)
-                    {
-                        if (annopoints[i])
-                          msFree(annopoints[i]);
-                        if (angles[i])
-                          msFree(angles[i]);
-                        if (lengths[i])
-                          msFree(lengths[i]);
-                    }
-                    msFree(angles);
-                    msFree(annopoints);
-                    msFree(lengths);
-                }      
-            }
-        
-        }
-        else if (shape->type == MS_SHAPE_POLYGON)
-        {
-            labelposvalid = MS_FALSE;
-            if(layer->transform == MS_TRUE) 
-            {
-                if (layer->project && 
-                    msProjectionsDiffer(&(layer->projection), &(layer->map->projection)))
-                  msProjectShape(&layer->projection, &layer->map->projection, shape);
-          
-                if (clip_to_map)
-                  msClipPolygonRect(shape, layer->map->extent);
+          labelposvalid = MS_TRUE;
+          for(i=0; i<numpoints; i++) {
+            if(annopoints[i]) msFree(annopoints[i]);
+            if(angles[i]) msFree(angles[i]);
+            if(lengths[i]) msFree(lengths[i]);
+          }
+          msFree(angles);
+          msFree(annopoints);
+          msFree(lengths);
+        }      
+      }
+    } else if (shape->type == MS_SHAPE_POLYGON) {
+      labelposvalid = MS_FALSE;
+      if(layer->transform == MS_TRUE) {
+        if(layer->project && msProjectionsDiffer(&(layer->projection), &(layer->map->projection)))
+          msProjectShape(&layer->projection, &layer->map->projection, shape);
 
-                msTransformShapeToPixelRound(shape, layer->map->extent, cellsize);
-            }
-            else
-              msOffsetShapeRelativeTo(shape, layer);
+        if(clip_to_map)
+          msClipPolygonRect(shape, layer->map->extent);
 
-            if (shape->numlines > 0)
-            {
-                if (msPolygonLabelPoint(shape, &labelPos, -1) == MS_SUCCESS)
-                {
-                    if (labelPos.x == -1 && labelPos.y == -1)
-                      labelposvalid = MS_FALSE;
-                    else
-                      labelposvalid = MS_TRUE;
-                }
-            }
+        msTransformShapeToPixelRound(shape, layer->map->extent, cellsize);
+      } else
+        msOffsetShapeRelativeTo(shape, layer);
+
+      if(shape->numlines > 0) {
+        if(msPolygonLabelPoint(shape, &labelPos, -1) == MS_SUCCESS) {
+          if(labelPos.x == -1 && labelPos.y == -1)
+            labelposvalid = MS_FALSE;
+           else
+            labelposvalid = MS_TRUE;
         }
-        if (labelposvalid == MS_TRUE)
-        {
-            pointObj p1;
-            pointObj p2;
-            int label_offset_x, label_offset_y;
-            labelObj *label=NULL;
-            rectObj r;
-            shapeObj poly;
-            double tmp;
+      }
+    }
 
-            msInitShape(&poly);
+    if(labelposvalid == MS_TRUE) {
+      pointObj p1;
+      pointObj p2;
+      int label_offset_x, label_offset_y;
+      labelObj *label=NULL;
+      rectObj r;
+      shapeObj poly;
+      double tmp;
 
-            p1.x =labelPos.x;
-            p1.y =labelPos.y; 
+      msInitShape(&poly);
+      p1.x =labelPos.x;
+      p1.y =labelPos.y; 
 
-            p2.x =labelPos.x;
-            p2.y =labelPos.y;  
-            if (use_label_settings == MS_TRUE)
-            {
-                if (shape->text && shape->classindex >=0)
-                {
-                    label = &layer->class[shape->classindex]->label;
-                    if(msGetLabelSize(layer->map,label,shape->text,label->size,&r,NULL) == MS_SUCCESS)
-                    {
-                        label_offset_x = (int)(label->offsetx*layer->scalefactor);
-                        label_offset_y = (int)(label->offsety*layer->scalefactor);
+      p2.x =labelPos.x;
+      p2.y =labelPos.y;  
+      if(use_label_settings == MS_TRUE) {
 
-                        p1 = get_metrics(&labelPos, label->position, r, label_offset_x, label_offset_y, 
-                                              label->angle, 0, &poly);
-                        /*should we use the point returned from  get_metrics?. From few test done, It seems
-                         to return the UL corner of the text. For now use the bounds.minx/miny*/
+        /* RFC 77: classes (and shapes) can have more than 1 piece of annotation, here we only use the first (index=0) */
+        if(shape->numtext > 0 && shape->text[0] && shape->classindex >= 0) {
+          label = layer->class[shape->classindex]->labels[0];
+          if(msGetLabelSize(layer->map, label, shape->text[0], label->size, &r, NULL) == MS_SUCCESS) {
+            label_offset_x = (int)(label->offsetx*layer->scalefactor);
+            label_offset_y = (int)(label->offsety*layer->scalefactor);
 
-                        p1.x = poly.bounds.minx;
-                        p1.y = poly.bounds.miny;
-                        p2.x = poly.bounds.maxx;
-                        p2.y = poly.bounds.maxy;
-                        
-                    }
-                }
-            }
-            /* y's are flipped because it is in image coordinate systems */
-            p1.x = MS_IMAGE2MAP_X(p1.x, layer->map->extent.minx, cellsize);
-            tmp = p1.y;
-            p1.y = MS_IMAGE2MAP_Y(p2.y, layer->map->extent.maxy, cellsize);
-            p2.x = MS_IMAGE2MAP_X(p2.x, layer->map->extent.minx, cellsize);
-            p2.y = MS_IMAGE2MAP_Y(tmp, layer->map->extent.maxy, cellsize);
-            if(layer->transform == MS_TRUE) {
-                if (layer->project && 
-                    msProjectionsDiffer(&(layer->projection), &(layer->map->projection)))
-                {
-                    msProjectPoint(&layer->map->projection, &layer->projection, &p1);
-                    msProjectPoint(&layer->map->projection, &layer->projection, &p2);
-                }
-            }
-            msAddPointToLine(&(tShape.line[0]), &p1);
-            msAddPointToLine(&(tShape.line[0]), &p2);
+            p1 = get_metrics(&labelPos, label->position, r, label_offset_x, label_offset_y, label->angle, 0, &poly);
+
+            /* should we use the point returned from  get_metrics?. From few test done, It seems
+               to return the UL corner of the text. For now use the bounds.minx/miny */
+            p1.x = poly.bounds.minx;
+            p1.y = poly.bounds.miny;
+            p2.x = poly.bounds.maxx;
+            p2.y = poly.bounds.maxy;
+          }
         }
-        else
-          tShape.numlines = 0;
+      }
+        
+      /* y's are flipped because it is in image coordinate systems */
+      p1.x = MS_IMAGE2MAP_X(p1.x, layer->map->extent.minx, cellsize);
+      tmp = p1.y;
+      p1.y = MS_IMAGE2MAP_Y(p2.y, layer->map->extent.maxy, cellsize);
+      p2.x = MS_IMAGE2MAP_X(p2.x, layer->map->extent.minx, cellsize);
+      p2.y = MS_IMAGE2MAP_Y(tmp, layer->map->extent.maxy, cellsize);
+      if(layer->transform == MS_TRUE) {
+        if(layer->project && msProjectionsDiffer(&(layer->projection), &(layer->map->projection))) {
+          msProjectPoint(&layer->map->projection, &layer->projection, &p1);
+          msProjectPoint(&layer->map->projection, &layer->projection, &p2);
+        }
+      }
+      msAddPointToLine(&(tShape.line[0]), &p1);
+      msAddPointToLine(&(tShape.line[0]), &p2);
+    } else
+      tShape.numlines = 0;
 
-         if(projectionString && strcasecmp(projectionString,"image") == 0) {
-             precision = 0;
+    if(projectionString && strcasecmp(projectionString,"image") == 0) {
+      precision = 0;
 
-             /* if necessary, project the shape to match the map */
-             if(msProjectionsDiffer(&(layer->projection), &(layer->map->projection)))
-               msProjectShape(&layer->projection, &layer->map->projection, &tShape);
+      /* if necessary, project the shape to match the map */
+      if(msProjectionsDiffer(&(layer->projection), &(layer->map->projection)))
+        msProjectShape(&layer->projection, &layer->map->projection, &tShape);
       
-              msClipPolylineRect(&tShape, layer->map->extent);
+        msClipPolylineRect(&tShape, layer->map->extent);
 
-              msTransformShapeToPixelRound(&tShape, layer->map->extent, layer->map->cellsize);
+        msTransformShapeToPixelRound(&tShape, layer->map->extent, layer->map->cellsize);
+    } else if(projectionString) {
+      projectionObj projection;
+      msInitProjection(&projection);
 
-         } else if(projectionString) {
-             projectionObj projection;
-             msInitProjection(&projection);
+      status = msLoadProjectionString(&projection, projectionString);
+      if(status != MS_SUCCESS) return MS_FAILURE;
 
-             status = msLoadProjectionString(&projection, projectionString);
-             if(status != MS_SUCCESS) return MS_FAILURE;
+      if(msProjectionsDiffer(&(layer->projection), &projection)) 
+        msProjectShape(&layer->projection, &projection, &tShape);
+    }   
 
-             if(msProjectionsDiffer(&(layer->projection), &projection)) 
-               msProjectShape(&layer->projection, &projection, &tShape);
-         }
-         
-          
+    /* find the end of the tag */
+    tagEnd = findTagEnd(tagStart);
+    tagEnd++;
 
-          /* find the end of the tag */
-          tagEnd = findTagEnd(tagStart);
-          tagEnd++;
+    /* build the complete tag so we can do substitution */
+    tagLength = tagEnd - tagStart;
+    tag = (char *) msSmallMalloc(tagLength + 1);
+    strlcpy(tag, tagStart, tagLength+1);
 
-          /* build the complete tag so we can do substitution */
-          tagLength = tagEnd - tagStart;
-          tag = (char *) msSmallMalloc(tagLength + 1);
-          strlcpy(tag, tagStart, tagLength+1);
+    /* do the replacement */
+    tagValue = msStrdup(format);
+    if(precision > 0)
+      snprintf(numberFormat, sizeof(numberFormat), "%%.%dlf", precision);
+    else
+      snprintf(numberFormat, sizeof(numberFormat), "%%f");
 
-          /* do the replacement */
-          tagValue = msStrdup(format);
-          if(precision > 0)
-            snprintf(numberFormat, sizeof(numberFormat), "%%.%dlf", precision);
-          else
-            snprintf(numberFormat, sizeof(numberFormat), "%%f");
-
-          if (tShape.numlines > 0)
-          {
-              if(strcasestr(tagValue, "$x") != 0)
-              {
-                  snprintf(number, sizeof(number), numberFormat, tShape.line[0].point[0].x);
-                  tagValue = msReplaceSubstring(tagValue, "$x", number);
-              }
-              if(strcasestr(tagValue, "$y") != 0)
-              {
-                  snprintf(number, sizeof(number), numberFormat, tShape.line[0].point[0].y);
-                  tagValue = msReplaceSubstring(tagValue, "$y", number);
-              }
+    if(tShape.numlines > 0) {
+      if(strcasestr(tagValue, "$x") != 0) {
+        snprintf(number, sizeof(number), numberFormat, tShape.line[0].point[0].x);
+        tagValue = msReplaceSubstring(tagValue, "$x", number);
+      }
+      if(strcasestr(tagValue, "$y") != 0) {
+        snprintf(number, sizeof(number), numberFormat, tShape.line[0].point[0].y);
+        tagValue = msReplaceSubstring(tagValue, "$y", number);
+      }
           
-              if(strcasestr(tagValue, "$minx") != 0)
-              {
-                  snprintf(number, sizeof(number), numberFormat, tShape.line[0].point[0].x);
-                  tagValue = msReplaceSubstring(tagValue, "$minx", number);
-              }
-              if(strcasestr(tagValue, "$miny") != 0)
-              {
-                  snprintf(number, sizeof(number), numberFormat, tShape.line[0].point[0].y);
-                  tagValue = msReplaceSubstring(tagValue, "$miny", number);
-              }
-              if(strcasestr(tagValue, "$maxx") != 0)
-              {
-                  snprintf(number, sizeof(number), numberFormat, tShape.line[0].point[1].x);
-                  tagValue = msReplaceSubstring(tagValue, "$maxx", number);
-              }
-              if(strcasestr(tagValue, "$maxy") != 0)
-              {
-                  snprintf(number, sizeof(number), numberFormat, tShape.line[0].point[1].y);
-                  tagValue = msReplaceSubstring(tagValue, "$maxy", number);
-              }
-          }
-           /* find the end of the tag */
-          tagEnd = findTagEnd(tagStart);
-          tagEnd++;
+      if(strcasestr(tagValue, "$minx") != 0) {
+        snprintf(number, sizeof(number), numberFormat, tShape.line[0].point[0].x);
+         tagValue = msReplaceSubstring(tagValue, "$minx", number);
+      }
+      if(strcasestr(tagValue, "$miny") != 0) {
+        snprintf(number, sizeof(number), numberFormat, tShape.line[0].point[0].y);
+        tagValue = msReplaceSubstring(tagValue, "$miny", number);
+      }
+      if(strcasestr(tagValue, "$maxx") != 0) {
+        snprintf(number, sizeof(number), numberFormat, tShape.line[0].point[1].x);
+        tagValue = msReplaceSubstring(tagValue, "$maxx", number);
+      }
+      if(strcasestr(tagValue, "$maxy") != 0) {
+        snprintf(number, sizeof(number), numberFormat, tShape.line[0].point[1].y);
+        tagValue = msReplaceSubstring(tagValue, "$maxy", number);
+      }
+    }
+       
+    /* find the end of the tag */
+    tagEnd = findTagEnd(tagStart);
+    tagEnd++;
 
-          /* build the complete tag so we can do substitution */
-          tagLength = tagEnd - tagStart;
-          tag = (char *) msSmallMalloc(tagLength + 1);
-          strlcpy(tag, tagStart, tagLength+1);
+    /* build the complete tag so we can do substitution */
+    tagLength = tagEnd - tagStart;
+    tag = (char *) msSmallMalloc(tagLength + 1);
+    strlcpy(tag, tagStart, tagLength+1);
 
-          *line = msReplaceSubstring(*line, tag, tagValue);
+    *line = msReplaceSubstring(*line, tag, tagValue);
 
-          /* clean up */
-          msFreeShape(&tShape);
-          free(tag); tag = NULL;
-          msFreeHashTable(tagArgs); tagArgs=NULL;
-          msFree(tagValue); tagValue=NULL;
-             
+    /* clean up */
+    msFreeShape(&tShape);
+    free(tag); tag = NULL;
+    msFreeHashTable(tagArgs); tagArgs=NULL;
+    msFree(tagValue); tagValue=NULL;
 
-         if((*line)[tagOffset] != '\0')
-          tagStart = findTag(*line+tagOffset+1, "shplabel");
-         else
-           tagStart = NULL; 
-    }
-    if (shape)
-      msFreeShape(shape);
+    if((*line)[tagOffset] != '\0')
+      tagStart = findTag(*line+tagOffset+1, "shplabel");
+    else
+      tagStart = NULL; 
+  }
+  if(shape)
+    msFreeShape(shape);
 
-    return(MS_SUCCESS);
+  return(MS_SUCCESS);
 }
 
 

Modified: sandbox/sdlime/rfc-77/maputil.c
===================================================================
--- sandbox/sdlime/rfc-77/maputil.c	2011-11-21 13:25:43 UTC (rev 12789)
+++ sandbox/sdlime/rfc-77/maputil.c	2011-11-22 04:40:18 UTC (rev 12790)
@@ -566,64 +566,77 @@
   return(-1); /* no match */
 }
 
-char *msShapeGetAnnotation(layerObj *layer, shapeObj *shape)
+int msShapeGetAnnotation(layerObj *layer, shapeObj *shape)
 {
-  char *tmpstr=NULL;
+  char *tmpstr;
+  int i, j;
 
-  if(layer->class[shape->classindex]->text.string) { /* test for global label first */
-    switch(layer->class[shape->classindex]->text.type) {
-    case(MS_STRING):
-      {
-        char *target=NULL;
-        tokenListNodeObjPtr node=NULL;
-        tokenListNodeObjPtr nextNode=NULL;
+  /* RFC 77 TODO: check and throw some errors here... */
+  if(!layer || !shape) return MS_FAILURE;
 
-        tmpstr = msStrdup(layer->class[shape->classindex]->text.string);
+  j = shape->classindex;
+  for(i=0; i<layer->class[j].numlabels; i++) {
 
-        node = layer->class[shape->classindex]->text.tokens;
-        if(node) {
-          while(node != NULL) {
-            nextNode = node->next;
-            if(node->token == MS_TOKEN_BINDING_DOUBLE || node->token == MS_TOKEN_BINDING_INTEGER || node->token == MS_TOKEN_BINDING_STRING || node->token == MS_TOKEN_BINDING_TIME) {
-              target = (char *) msSmallMalloc(strlen(node->tokenval.bindval.item) + 3);
-              sprintf(target, "[%s]", node->tokenval.bindval.item);
-              tmpstr = msReplaceSubstring(tmpstr, target, shape->values[node->tokenval.bindval.index]);
-              msFree(target);
-	    }
-            node = nextNode;
-          }
+    /* RFC 77 TODO: will evaluate label expressions here... */
+
+    tmpstr = NULL; /* initialize */
+    if(layer->class[j]->text.string) { /* RFC 77 TODO: will check for a label text value first, then class text and finally try labelitem */
+      switch(layer->class[j]->text.type) {
+      case(MS_STRING):
+        {
+          char *target=NULL;
+          tokenListNodeObjPtr node=NULL;
+          tokenListNodeObjPtr nextNode=NULL;
+
+          tmpstr = msStrdup(layer->class[j]->text.string);
+
+          node = layer->class[j]->text.tokens;
+          if(node) {
+            while(node != NULL) {
+              nextNode = node->next;
+              if(node->token == MS_TOKEN_BINDING_DOUBLE || node->token == MS_TOKEN_BINDING_INTEGER || node->token == MS_TOKEN_BINDING_STRING || node->token == MS_TOKEN_BINDING_TIME) {
+                target = (char *) msSmallMalloc(strlen(node->tokenval.bindval.item) + 3);
+                sprintf(target, "[%s]", node->tokenval.bindval.item);
+                tmpstr = msReplaceSubstring(tmpstr, target, shape->values[node->tokenval.bindval.index]);
+                msFree(target);
+	      }
+              node = nextNode;
+            }
+	  }
         }
-      }
-      break;
-    case(MS_EXPRESSION):
-      {
-        int status;
-        parseObj p;
+        break;
+      case(MS_EXPRESSION):
+        {
+          int status;
+          parseObj p;
 
-        p.shape = shape;
-        p.expr = &(layer->class[shape->classindex]->text);
-        p.expr->curtoken = p.expr->tokens; /* reset */
-        p.type = MS_PARSE_TYPE_STRING;
+          p.shape = shape;
+          p.expr = &(layer->class[j]->text);
+          p.expr->curtoken = p.expr->tokens; /* reset */
+          p.type = MS_PARSE_TYPE_STRING;
 
-        status = yyparse(&p);
+          status = yyparse(&p);
 
-        if (status != 0) {
-	  msSetError(MS_PARSEERR, "Failed to process text expression: %s", "msShapeGetAnnotation", layer->class[shape->classindex]->text.string);
-	  return NULL;
+          if (status != 0) {
+	    msSetError(MS_PARSEERR, "Failed to process text expression: %s", "msShapeGetAnnotation", layer->class[c]->text.string);
+	    return MS_FAILURE;
+          }
+
+          tmpstr = p.result.strval;        
+          break;
         }
-
-        tmpstr = p.result.strval;        
+      default:
         break;
       }
-    default:
-      break;
+    } else {
+      if (shape->values && layer->labelitemindex >= 0)
+        tmpstr = msStrdup(shape->values[layer->labelitemindex]);
     }
-  } else {
-    if (shape->values && layer->labelitemindex >= 0)
-      tmpstr = msStrdup(shape->values[layer->labelitemindex]);
+
+    shape->text[i] = tmpstr;
   }
 
-  return(tmpstr);
+  return MS_SUCCESS;
 }
 
 /* Check if the shape is enough big to be drawn with the



More information about the mapserver-commits mailing list