[mapserver-commits] r7231 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Mon Dec 31 00:19:01 EST 2007


Author: sdlime
Date: 2007-12-31 00:19:00 -0500 (Mon, 31 Dec 2007)
New Revision: 7231

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapdraw.c
Log:
Fixed a bug with path following labels where in labels turned over to auto angle computations would use the position set in the mapfile rather than MS_CC. We needed to force ALL labels to MS_CC when ANGLE FOLLOW is set. (bug #2455)

Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2007-12-30 21:42:11 UTC (rev 7230)
+++ trunk/mapserver/HISTORY.TXT	2007-12-31 05:19:00 UTC (rev 7231)
@@ -13,6 +13,10 @@
 Current Version (5.1-dev, SVN trunk):
 -------------------------------------
 
+- fixed issue where path following labels sometimes used the supplied
+setting for position. In all cases with ANGLE FOLLOW we want to force
+position MS_CC regardless of what is set in the mapfile.
+
 - enforce (-99 -99) to be the penup value for vector symbols (#1036)
 
 - Support for labeling features (polygon & line) prior to clipping. This

Modified: trunk/mapserver/mapdraw.c
===================================================================
--- trunk/mapserver/mapdraw.c	2007-12-30 21:42:11 UTC (rev 7230)
+++ trunk/mapserver/mapdraw.c	2007-12-31 05:19:00 UTC (rev 7231)
@@ -1400,19 +1400,15 @@
 
       /* Bug #1620 implementation */
       if ( layer->class[c]->label.autofollow == MS_TRUE ) {
+        layer->class[c]->label.position = MS_CC; /* Force all label positions to MS_CC regardless if a path is computed */
 
-        /* Determine the label path iff it has not been computed above */
+        /* Determine the label path if it has not been computed above */
         if(bLabelNoClip == MS_FALSE)
           annopath = msPolylineLabelPath(shape, layer->class[c]->label.minfeaturesize, &(map->fontset), shape->text, &(layer->class[c]->label), layer->scalefactor, &status);
 
         if( annopath ) {
           labelObj label = layer->class[c]->label;
           
-          /* Label path derived from line overrides the rotation and position
-             values, so ignore the specified angle and set the position to
-             auto. */
-          label.position = MS_AUTO;
-        
           if(layer->labelcache) {
             if(msAddLabel(map, layer->index, c, shape->index, shape->tileindex, NULL, annopath, shape->text, length, &label) != MS_SUCCESS) return(MS_FAILURE);
           } else {
@@ -1617,6 +1613,7 @@
 
       /* Bug #1620 implementation */
       if(layer->class[c]->label.autofollow == MS_TRUE) {
+        layer->class[c]->label.position = MS_CC; /* Force all label positions to MS_CC regardless if a path is computed */
 
         if (bLabelNoClip == MS_FALSE)
           annopath = msPolylineLabelPath(shape, layer->class[c]->label.minfeaturesize, &(map->fontset), shape->text, &(layer->class[c]->label), layer->scalefactor, &status);
@@ -1624,12 +1621,6 @@
         if(annopath) {
           labelObj label = layer->class[c]->label;
 
-          /* 
-	  ** Label path derived from line overrides the rotation and position
-          ** values, so ignore the specified angle and set the position to auto. 
-          */
-          label.position = MS_AUTO;
-          
           if(layer->labelcache) {
             if(msAddLabel(map, layer->index, c, shape->index, shape->tileindex, NULL, annopath, shape->text, length, &label) != MS_SUCCESS) return(MS_FAILURE);
           } else {
@@ -2113,100 +2104,82 @@
                         marker_rect.maxx = marker_rect.minx + (marker_width-1);
                         marker_rect.maxy = marker_rect.miny + (marker_height-1); 
                     }
+
                     if(labelPtr->position == MS_AUTO) {
+                      int first_pos, pos, last_pos;
 
-                        /* If we have a label path there are no alternate positions.
-                   Just check against the image boundaries, existing markers
-                   and existing labels. (Bug #1620) */
-                        if ( cachePtr->labelpath ) {
+                      if(labelPtr->type == MS_LAYER_LINE) {                        
+                        first_pos = MS_UC; /* There are three possible positions: UC, CC, LC */
+                        last_pos = MS_CC;
+                      } else {
+                        first_pos = MS_UL; /* There are 8 possible outer positions: UL, LR, UR, LL, CR, CL, UC, LC */
+                        last_pos = MS_LC;
+                      }
 
-                            /* Assume label can be drawn */
-                            cachePtr->status = MS_TRUE;
+                      for(pos = first_pos; pos <= last_pos; pos++) {
+                        msFreeShape(cachePtr->poly);
+                        cachePtr->status = MS_TRUE; /* assume label *can* be drawn */
 
-                            /* Copy the bounds into the cache's polygon */
-                            msCopyShape(&(cachePtr->labelpath->bounds), cachePtr->poly);
+                        p = get_metrics(&(cachePtr->point), pos, r, (marker_offset_x + labelPtr->offsetx), (marker_offset_y + labelPtr->offsety), labelPtr->angle, labelPtr->buffer, cachePtr->poly);
+                        if(layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0)
+                          msRectToPolygon(marker_rect, cachePtr->poly); /* save marker bounding polygon */
 
-                            msFreeShape(&(cachePtr->labelpath->bounds));
+                        /* Compare against image bounds, rendered labels and markers (sets cachePtr->status) */
+                        msTestLabelCacheCollisions(&(map->labelcache), labelPtr, image->width, image->height, 
+                        labelPtr->buffer + map_edge_buffer, cachePtr, priority, l);
 
+                        if(cachePtr->status) /* found a suitable place for this label */ {
+                          if(MS_VALID_COLOR(labelPtr->backgroundcolor))
+                            get_metrics_line(&(cachePtr->point), pos, r, (marker_offset_x + labelPtr->offsetx), (marker_offset_y + labelPtr->offsety), labelPtr->angle, 1, billboard.line);
+                          break;
+                        }
 
-                            /* Compare against image bounds, rendered labels and markers (sets cachePtr->status) */
-                            msTestLabelCacheCollisions(&(map->labelcache), labelPtr, image->width, image->height, 
-                                    labelPtr->buffer + map_edge_buffer, cachePtr, priority, l);
+                      } /* next position */
 
-                        } else { 
+                      if(labelPtr->force) cachePtr->status = MS_TRUE; /* draw in spite of collisions based on last position, need a *best* position */
 
-                            /* We have a label point */
-                            int first_pos, pos, last_pos;
+                    } else {
 
-                            if ( labelPtr->type == MS_LAYER_LINE ) {
-                                /* There are three possible positions: UC, CC, LC */
-                                first_pos = MS_UC;
-                                last_pos = MS_CC;
-                            } else {
-                                /* There are 8 possible outer positions: UL, LR, UR, LL, CR, CL, UC, LC */
-                                first_pos = MS_UL;
-                                last_pos = MS_LC;
-                            }
+                      cachePtr->status = MS_TRUE; /* assume label *can* be drawn */
 
-                            for(pos = first_pos; pos <= last_pos; pos++) {
-                                msFreeShape(cachePtr->poly);
-                                cachePtr->status = MS_TRUE; /* assume label *can* be drawn */
+		      if(cachePtr->labelpath ) {
 
-                                p = get_metrics(&(cachePtr->point), pos, r, (marker_offset_x + labelPtr->offsetx), (marker_offset_y + labelPtr->offsety), labelPtr->angle, labelPtr->buffer, cachePtr->poly);
-                                if(layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0)
-                                    msRectToPolygon(marker_rect, cachePtr->poly); /* save marker bounding polygon */
+			/* Copy the bounds into the cache's polygon */
+			msCopyShape(&(cachePtr->labelpath->bounds), cachePtr->poly);
+		        msFreeShape(&(cachePtr->labelpath->bounds));
 
-                                /* Compare against image bounds, rendered labels and markers (sets cachePtr->status) */
-                                msTestLabelCacheCollisions(&(map->labelcache), labelPtr, image->width, image->height, 
-                                        labelPtr->buffer + map_edge_buffer, cachePtr, priority, l);
+		        /* Compare against image bounds, rendered labels and markers (sets cachePtr->status) */
+		        msTestLabelCacheCollisions(&(map->labelcache), labelPtr, image->width, image->height, labelPtr->buffer + map_edge_buffer, cachePtr, priority, l);
 
-                                if(cachePtr->status) /* found a suitable place for this label */ {
-                                    if(MS_VALID_COLOR(labelPtr->backgroundcolor))
-                                        get_metrics_line(&(cachePtr->point), pos, r, (marker_offset_x + labelPtr->offsetx), (marker_offset_y + labelPtr->offsety), labelPtr->angle, 1, billboard.line);                                          
-                                    break;
-                                }
+                      } else {
 
-                            } /* next position */
-
+                        if(labelPtr->position == MS_CC) { /* don't need the marker_offset */
+                          p = get_metrics(&(cachePtr->point), labelPtr->position, r, labelPtr->offsetx, labelPtr->offsety, labelPtr->angle, labelPtr->buffer, cachePtr->poly);
+                          if(MS_VALID_COLOR(labelPtr->backgroundcolor))
+                            get_metrics_line(&(cachePtr->point), labelPtr->position, r, labelPtr->offsetx, labelPtr->offsety, labelPtr->angle, 1, billboard.line);
+                        } else {
+                          p = get_metrics(&(cachePtr->point), labelPtr->position, r, (marker_offset_x + labelPtr->offsetx), (marker_offset_y + labelPtr->offsety), labelPtr->angle, labelPtr->buffer, cachePtr->poly);
+                          if(MS_VALID_COLOR(labelPtr->backgroundcolor))
+                            get_metrics_line(&(cachePtr->point), labelPtr->position, r, (marker_offset_x + labelPtr->offsetx), (marker_offset_y + labelPtr->offsety), labelPtr->angle, 1, billboard.line);
                         }
-
-                        if(labelPtr->force) cachePtr->status = MS_TRUE; /* draw in spite of collisions based on last position, need a *best* position */
-
-                    } else {
-
-                        cachePtr->status = MS_TRUE; /* assume label *can* be drawn */
-
-                        if(labelPtr->position == MS_CC) {/* don't need the marker_offset */
-                            p = get_metrics(&(cachePtr->point), labelPtr->position, r, labelPtr->offsetx, labelPtr->offsety, labelPtr->angle, labelPtr->buffer, cachePtr->poly);
-                            if(MS_VALID_COLOR(labelPtr->backgroundcolor))
-                                get_metrics_line(&(cachePtr->point), labelPtr->position, r, labelPtr->offsetx, labelPtr->offsety, labelPtr->angle, 1, billboard.line);
-
-                        }
-                        else{
-                            p = get_metrics(&(cachePtr->point), labelPtr->position, r, (marker_offset_x + labelPtr->offsetx), (marker_offset_y + labelPtr->offsety), labelPtr->angle, labelPtr->buffer, cachePtr->poly);
-                            if(MS_VALID_COLOR(labelPtr->backgroundcolor))
-                                get_metrics_line(&(cachePtr->point), labelPtr->position, r, (marker_offset_x + labelPtr->offsetx), (marker_offset_y + labelPtr->offsety), labelPtr->angle, 1, billboard.line);
-                        }
                         if(layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0)
-                            msRectToPolygon(marker_rect, cachePtr->poly); /* save marker bounding polygon, part of overlap tests */
+                          msRectToPolygon(marker_rect, cachePtr->poly); /* save marker bounding polygon, part of overlap tests */
 
                         if(!labelPtr->force) { /* no need to check anything else */
-
-                            /* Compare against image bounds, rendered labels and markers (sets cachePtr->status) */
-                            msTestLabelCacheCollisions(&(map->labelcache), labelPtr, image->width, image->height, 
-                                    labelPtr->buffer + map_edge_buffer, cachePtr, priority, l);
-
+                          /* Compare against image bounds, rendered labels and markers (sets cachePtr->status) */
+                          msTestLabelCacheCollisions(&(map->labelcache), labelPtr, image->width, image->height, labelPtr->buffer + map_edge_buffer, cachePtr, priority, l);
                         }
+		      }
                     } /* end position if-then-else */
 
                     /* imagePolyline(img, cachePtr->poly, 1, 0, 0); */
 
                     if(!cachePtr->status)
-                        continue; /* next label */
+                      continue; /* next label */
 
                     if(layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0) { /* need to draw a marker */
-                        for(i=0; i<cachePtr->numstyles; i++)
-                            msDrawMarkerSymbol(&map->symbolset, image, &(cachePtr->point), &(cachePtr->styles[i]), layerPtr->scalefactor);
+                      for(i=0; i<cachePtr->numstyles; i++)
+                        msDrawMarkerSymbol(&map->symbolset, image, &(cachePtr->point), &(cachePtr->styles[i]), layerPtr->scalefactor);
                     }
 
                     if(MS_VALID_COLOR(labelPtr->backgroundcolor)) {



More information about the mapserver-commits mailing list