[mapserver-commits] r13194 - sandbox/tb-labels

svn at osgeo.org svn at osgeo.org
Fri Mar 2 07:32:21 EST 2012


Author: tbonfort
Date: 2012-03-02 04:32:21 -0800 (Fri, 02 Mar 2012)
New Revision: 13194

Modified:
   sandbox/tb-labels/mapdraw.c
Log:
don't test a label text against its own marker on annotation layers



Modified: sandbox/tb-labels/mapdraw.c
===================================================================
--- sandbox/tb-labels/mapdraw.c	2012-03-02 03:59:47 UTC (rev 13193)
+++ sandbox/tb-labels/mapdraw.c	2012-03-02 12:32:21 UTC (rev 13194)
@@ -2592,15 +2592,14 @@
    return retval;
 }
 
-int computeOldStyleMarkerPoly(mapObj *map, imageObj *image, labelCacheMemberObj *cachePtr, 
+int computeMarkerPoly(mapObj *map, imageObj *image, labelCacheMemberObj *cachePtr, 
       labelCacheSlotObj *cacheslot, shapeObj *markerPoly) {
    layerObj *layerPtr = (GET_LAYER(map, cachePtr->layerindex));
-   markerPoly->numlines = 0;
-   pointObj *point = markerPoly->line[0].point;
    if(layerPtr->type == MS_LAYER_ANNOTATION && cachePtr->numstyles > 0) {
       /* TODO: at the moment only checks the bottom (first) marker style since it *should* be the
          largest, perhaps we should check all of them and build a composite size */
       double marker_width,marker_height;
+      pointObj *point = markerPoly->line[0].point;
       if(msGetMarkerSize(&map->symbolset, &(cachePtr->styles[0]), &marker_width, &marker_height, layerPtr->scalefactor) != MS_SUCCESS)
          return MS_FAILURE;
       markerPoly->numlines = 1;
@@ -2608,12 +2607,6 @@
       markerPoly->bounds.miny = cachePtr->point.y - .5 * marker_height;
       markerPoly->bounds.maxx = markerPoly->bounds.minx + (marker_width-1);
       markerPoly->bounds.maxy = markerPoly->bounds.miny + (marker_height-1);
-   } else if (layerPtr->type == MS_LAYER_POINT && cachePtr->markerid!=-1) { /* there is a marker already in the image that we need to account for */
-      markerCacheMemberObj *markerPtr = &(cacheslot->markers[cachePtr->markerid]); /* point to the right sport in the marker cache (if available) */
-      markerPoly->numlines = 1;
-      markerPoly->bounds = markerPtr->poly->bounds;
-   }
-   if(markerPoly->numlines) {
       point[0].x = markerPoly->bounds.minx;
       point[0].y = markerPoly->bounds.miny;
       point[1].x = markerPoly->bounds.minx;
@@ -2628,6 +2621,23 @@
    return MS_SUCCESS;
 }
 
+void fastComputeBounds(shapeObj *shape)
+{
+   int i,j;
+   shape->bounds.minx = shape->bounds.maxx = shape->line[0].point[0].x;
+   shape->bounds.miny = shape->bounds.maxy = shape->line[0].point[0].y;
+  
+    
+  for( i=0; i<shape->numlines; i++ ) {
+    for( j=0; j<shape->line[i].numpoints; j++ ) {
+      shape->bounds.minx = MS_MIN(shape->bounds.minx, shape->line[i].point[j].x);
+      shape->bounds.maxx = MS_MAX(shape->bounds.maxx, shape->line[i].point[j].x);
+      shape->bounds.miny = MS_MIN(shape->bounds.miny, shape->line[i].point[j].y);
+      shape->bounds.maxy = MS_MAX(shape->bounds.maxy, shape->line[i].point[j].y);
+    }
+  }
+}
+
 int computeLabelMarkerPoly(mapObj *map, imageObj *img, labelCacheMemberObj *cachePtr,
       labelObj *label, shapeObj *markerPoly) {
    int i;
@@ -2686,23 +2696,6 @@
    return MS_SUCCESS;
 }
 
-void fastComputeBounds(shapeObj *shape)
-{
-   int i,j;
-   shape->bounds.minx = shape->bounds.maxx = shape->line[0].point[0].x;
-   shape->bounds.miny = shape->bounds.maxy = shape->line[0].point[0].y;
-  
-    
-  for( i=0; i<shape->numlines; i++ ) {
-    for( j=0; j<shape->line[i].numpoints; j++ ) {
-      shape->bounds.minx = MS_MIN(shape->bounds.minx, shape->line[i].point[j].x);
-      shape->bounds.maxx = MS_MAX(shape->bounds.maxx, shape->line[i].point[j].x);
-      shape->bounds.miny = MS_MIN(shape->bounds.miny, shape->line[i].point[j].y);
-      shape->bounds.maxy = MS_MAX(shape->bounds.maxy, shape->line[i].point[j].y);
-    }
-  }
-}
-
 int msDrawLabelCache(imageObj *image, mapObj *map)
 {
   int nReturnVal = MS_SUCCESS;
@@ -2726,8 +2719,19 @@
       marker_line.numpoints = 5;
       msInitShape(&marker_poly);
       marker_poly.line = &marker_line;
-      marker_poly.numlines = 1;
+      marker_poly.numlines = 0;
+      marker_poly.type = MS_SHAPE_POLYGON;
       
+      shapeObj label_marker_poly;
+      lineObj  label_marker_line;
+      pointObj label_marker_points[5];
+      label_marker_line.point = label_marker_points;
+      label_marker_line.numpoints = 5;
+      msInitShape(&label_marker_poly);
+      label_marker_poly.line = &label_marker_line;
+      label_marker_poly.numlines = 0;
+      label_marker_poly.type = MS_SHAPE_POLYGON;
+      
       shapeObj metrics_poly;
       lineObj metrics_line;
       pointObj metrics_points[5];
@@ -2736,6 +2740,7 @@
       msInitShape(&metrics_poly);
       metrics_poly.line = &metrics_line;
       metrics_poly.numlines = 1;
+      metrics_poly.type = MS_SHAPE_POLYGON;
 
       double marker_offset_x, marker_offset_y;
  
@@ -2806,26 +2811,26 @@
             
             marker_offset_x = marker_offset_y = 0; /* assume no marker */
             
-            /* compute label bbox of a marker used in an annotation layer or a point layer with markerPtr */
-            computeOldStyleMarkerPoly(map,image,cachePtr,cacheslot,&marker_poly);
-            if(marker_poly.numlines) {
-               marker_offset_x = (marker_poly.bounds.maxx-marker_poly.bounds.minx)/2.0;
-               marker_offset_y = (marker_poly.bounds.maxy-marker_poly.bounds.miny)/2.0;
+            /* compute label bbox of a marker used in an annotation layer and/or 
+             * the offset needed for point layer with markerPtr */
+            marker_poly.numlines = 0;
+            if(layerPtr->type == MS_LAYER_ANNOTATION) {
+               computeMarkerPoly(map,image,cachePtr,cacheslot,&marker_poly);
+               if(marker_poly.numlines) {
+                  marker_offset_x = (marker_poly.bounds.maxx-marker_poly.bounds.minx)/2.0;
+                  marker_offset_y = (marker_poly.bounds.maxy-marker_poly.bounds.miny)/2.0;
                /* if this is an annotation layer, transfer the markerPoly */
-               if(layerPtr->type == MS_LAYER_ANNOTATION) {
-                  if(cachePtr->numlabels > 1 || classPtr->leader.maxdistance) {
-                     msSetError(MS_MISCERR,"Multiple Labels and/or LEADERs are not supported with annotation layers","msDrawLabelCache()");
-                     return MS_FAILURE;
-                  }
                   tmppoly = cachePtr->poly;
                   cachePtr->poly = &marker_poly;
                   if( MS_OFF == msTestLabelCacheCollisions(map, cachePtr, 0,priority, l)) {
                      continue; /* the marker collided, no point continuing */
                   }
                   cachePtr->poly = tmppoly;
-                  msAddLine(cachePtr->poly,marker_poly.line);
-                  msComputeBounds(cachePtr->poly);
                }
+            } else if (layerPtr->type == MS_LAYER_POINT && cachePtr->markerid!=-1) { /* there is a marker already in the image that we need to account for */
+               markerCacheMemberObj *markerPtr = &(cacheslot->markers[cachePtr->markerid]); /* point to the right spot in the marker cache*/
+               marker_offset_x = (markerPtr->poly->bounds.maxx-markerPtr->poly->bounds.minx)/2.0;
+               marker_offset_y = (markerPtr->poly->bounds.maxy-markerPtr->poly->bounds.miny)/2.0;
             }
 
 
@@ -2853,26 +2858,26 @@
               }
 
               /* compute the poly of the label styles */
-              computeLabelMarkerPoly(map,image,cachePtr,labelPtr,&marker_poly);
-              if(marker_poly.numlines) {
+              computeLabelMarkerPoly(map,image,cachePtr,labelPtr,&label_marker_poly);
+              if(label_marker_poly.numlines) {
                  if(cachePtr->numlabels > 1) {
-                    marker_offset_x = (marker_poly.bounds.maxx-marker_poly.bounds.minx)/2.0;
-                    marker_offset_y = (marker_poly.bounds.maxy-marker_poly.bounds.miny)/2.0;
+                    marker_offset_x = (label_marker_poly.bounds.maxx-label_marker_poly.bounds.minx)/2.0;
+                    marker_offset_y = (label_marker_poly.bounds.maxy-label_marker_poly.bounds.miny)/2.0;
                  } else {
                     /* we might be using an old style behavior with a markerPtr */
-                    marker_offset_x = MS_MAX(marker_offset_x,(marker_poly.bounds.maxx-marker_poly.bounds.minx)/2.0);
-                    marker_offset_y = MS_MAX(marker_offset_y,(marker_poly.bounds.maxy-marker_poly.bounds.miny)/2.0);
+                    marker_offset_x = MS_MAX(marker_offset_x,(label_marker_poly.bounds.maxx-label_marker_poly.bounds.minx)/2.0);
+                    marker_offset_y = MS_MAX(marker_offset_y,(label_marker_poly.bounds.maxy-label_marker_poly.bounds.miny)/2.0);
                  }
                  /* add marker to cachePtr->poly */
-                 tmppoly = cachePtr->poly;
-                 cachePtr->poly = &marker_poly;
-                 if(labelPtr->force != MS_TRUE)
+                 if(labelPtr->force != MS_TRUE) {
+                    tmppoly = cachePtr->poly;
+                    cachePtr->poly = &label_marker_poly;
                     label_marker_status = msTestLabelCacheCollisions(map, cachePtr, 0,priority, l);
-                 cachePtr->poly = tmppoly;
+                    cachePtr->poly = tmppoly;
+                 }
                  if(label_marker_status == MS_OFF &&
                          !(labelPtr->force || classPtr->leader.maxdistance))
                     break; /* the marker collided, break from multi-label loop */
-                 cachePtr->poly = tmppoly;
               }
 
 
@@ -3039,18 +3044,22 @@
                  if(labelPtr->annotext) {
                     msAddLine(cachePtr->poly, metrics_poly.line);
                  }
-                 if(marker_poly.numlines) {
-                    msAddLine(cachePtr->poly, marker_poly.line);
+                 if(label_marker_poly.numlines) {
+                    msAddLine(cachePtr->poly, label_marker_poly.line);
                  }
                  if(!label_marker_status)
                     labelPtr->status = MS_OFF;
-                 fastComputeBounds(cachePtr->poly);
               }
             } /* next label in the group */
+           
+            /* add the marker polygon if we have one */
+            if(marker_poly.numlines) {
+               msAddLine(cachePtr->poly, marker_poly.line);
+            }
+            fastComputeBounds(cachePtr->poly);
             
             /*
-             * with multiple labels and leader lines, cachePtr->status can be set back to ON if the last label
-             * didn't collide. we set it back to OFF in that case so it can become a candidate for leader offsetting
+             * cachePtr->status can be set to ON only if all it's labels didn't collide
              */
             cachePtr->status = MS_ON;
             for(ll=0;ll<cachePtr->numlabels; ll++) {



More information about the mapserver-commits mailing list