msDrawShape does not set labelObj annotext #4577

Closed
akrherz opened this Issue Jan 30, 2013 · 3 comments

Projects

None yet

3 participants

@akrherz
Contributor
akrherz commented Jan 30, 2013

Below is a example of rectObj->draw not placing any labels. I believe the problem is that msDrawShape does not set the labelObj's annotext, here's a suggested patch (I am not at all confident about this patch!)

diff --git a/mapdraw.c b/mapdraw.c
index acd6e4f..6acc305 100644
--- a/mapdraw.c
+++ b/mapdraw.c
@@ -1963,6 +1963,7 @@ int polygonLayerDrawShape(mapObj *map, imageObj *image, layerObj *layer,
 int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, imageObj *image, int style, int drawmode)
 {
   int c,s,ret=MS_SUCCESS;
+  labelObj *label=NULL;
   shapeObj *anno_shape, *unclipped_shape = shape;
   int bNeedUnclippedShape = MS_FALSE;
   int bNeedUnclippedAnnoShape = MS_FALSE;
@@ -1973,6 +1974,17 @@ int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, imageObj *image,
   msDrawStartShape(map, layer, image, shape);
   c = shape->classindex;

+  if(shape->text && layer->class[c]->numlabels > 0) {
+    label = layer->class[c]->labels[0];
+
+    msFree(label->annotext); /* free any previously allocated annotation text */
+    if(shape->text && (label->encoding || label->wrap || label->maxlength))
+      label->annotext = msTransformLabelText(map,label,shape->text); /* apply wrap character and encoding to the label text *
+    else
+      label->annotext = msStrdup(shape->text);
+  }
+
+
   /* Before we do anything else, we will check for a rangeitem.
      If its there, we need to change the style's color to map
      the range to the shape */

rect.map

MAP

NAME base4326
STATUS ON
SIZE 640 480
EXTENT -104 37 -87 49
UNITS DD

CONFIG "MS_ERRORFILE" "/tmp/ms_error.txt"
CONFIG "CPL_DEBUG" "ON"
CONFIG "PROJ_DEBUG" "ON"
DEBUG 5

LAYER
  DEBUG 5
  NAME rect
  TYPE POLYGON
  TRANSFORM FALSE
  STATUS ON
  LABELCACHE FALSE
  CLASS
      LABEL
       OFFSET 25 25
       COLOR 0 0 0
       OUTLINECOLOR 255 255 255
       SIZE 50
       TYPE BITMAP
       SIZE LARGE
      END
      STYLE
        COLOR 255 255 255
        OUTLINECOLOR 0 0 0
      END
  END
END

END

rect.php

$map = ms_newMapObj('rect.map');

$img = $map->prepareImage();

$layer = $map->getLayerByName("rect");

$rect = ms_newRectObj();
$rect->setextent(200,200,100,100);
$bol = $rect->draw($map, $layer, $img, 0, "TEST");

header("Content-type: image/png");
$img->saveImage('');
@aboudreault aboudreault was assigned Jan 30, 2013
@aboudreault
Member

@akrherz I prefered to fix this in php/mapscript since it seems that all the work of setting the label should be done before msDrawShape. I think swig mapscript has the same bug. Will verify this tomorrow.

@aboudreault aboudreault pushed a commit that closed this issue Feb 7, 2013
Alan Boudreault Fix rectObj/shapeObj draw function rendering when setting text proper…
…ty in mapscript (closes #4577)
44cfa83
@aboudreault aboudreault pushed a commit that referenced this issue Feb 7, 2013
Alan Boudreault Fix rectObj/shapeObj draw function rendering when setting text proper…
…ty in mapscript (closes #4577)
327eb31
@mkofahl mkofahl pushed a commit to faegi/mapserver that referenced this issue Apr 9, 2013
Alan Boudreault Fix rectObj->draw fails to render text in php/mapscript (#4577) eb4b54e
@mkofahl mkofahl pushed a commit to faegi/mapserver that referenced this issue Apr 9, 2013
Alan Boudreault Fix rectObj->draw fails to render text in php/mapscript (#4577) d2812f8
@mkofahl mkofahl pushed a commit to faegi/mapserver that referenced this issue Apr 9, 2013
Alan Boudreault Fix rectObj/shapeObj draw function rendering when setting text proper…
…ty in mapscript (closes #4577)
4626a6d
@mkofahl mkofahl pushed a commit to faegi/mapserver that referenced this issue Apr 9, 2013
Alan Boudreault Fix rectObj/shapeObj draw function rendering when setting text proper…
…ty in mapscript (closes #4577)
d128298
@tbonfort
Member

@aboudreault : you first stated "I prefered to fix this in php/mapscript since it seems that all the work of setting the label should be done before msDrawShape." but your fix was to add mapscript specific workarounds in mapdraw.c, which I dislike. Re-opening until this is clarified.

@tbonfort tbonfort reopened this Apr 13, 2013
@tbonfort tbonfort added a commit to tbonfort/mapserver that referenced this issue Apr 18, 2013
@tbonfort tbonfort Move #4577 fixes out of libmapserver 0fb99fc
@tbonfort
Member

I have moved the fix out of libmapserver in 0fb99fc, as this issue was holding on the release of 6.2.1

@aboudreault: please, no mapscript specific workarounds inside libmapserver
@sdlime: I think we're ready to release 6.2.1 :shipit:

@tbonfort tbonfort closed this Apr 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment