MapScriptException for point->draw() when no LABEL defined in LAYER CLASS #4572

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

Projects

None yet

2 participants

@akrherz
Contributor
akrherz commented Jan 23, 2013

Testing an update of PHP mapscript from 6.0.3 to 6.2.0, I ran into this issue. If no LABEL is defined in the LAYER->CLASS, then php mapscript bombs out with (snipped)

PHP Warning:  pointObj::draw(): [MapServer Error]: 
msEvalExpression(): Cannot evaluate expression, no item index defined.    
PHP Fatal error:  Uncaught exception 'MapScriptException' in test.php:9
Stack trace: test.php(9): pointObj->draw(...)

Defining an empty LABEL END in the layer class makes this error go away. I will attach a simple reproducer.

@akrherz
Contributor
akrherz commented Jan 23, 2013

Ewww, can't seem to upload files, will dump code instead, sorry.

test.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"
DEBUG 5

Symbol
  NAME 'logo'
  TYPE PIXMAP
  IMAGE 'logo.png'
  TRANSPARENT 0
END

# IEM Logo
LAYER
  DEBUG 5
  NAME logo
  TYPE POINT
  STATUS default
  TRANSFORM FALSE
  FEATURE
    WKT "POINT(100 100)"
  END
  CLASS
    # Uncomment to make error go away
    #LABEL
    #END
    STYLE
        SYMBOL 'logo'
    END
  END
END

test.php

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

$img = $map->prepareImage();

$layer = $map->getLayerByName("logo");
$point = ms_newpointobj();
$point->setXY(40, 26);
$point->draw($map, $layer, $img, 0, "");

header("Content-type: image/png");
$img->saveImage('');

logo.png

logo

@akrherz
Contributor
akrherz commented Jan 30, 2013

I think the "problem" is this check in msDrawPoint, if there is no LABEL in the CLASS, then we fail the check and annotext is not set.

  if(labeltext && theclass->numlabels > 0) {
    label = theclass->labels[0];

    msFree(label->annotext); /* free any previously allocated annotation text */
    if(labeltext && (label->encoding || label->wrap || label->maxlength))
      label->annotext = msTransformLabelText(map,label,labeltext); /* apply wrap character and encoding to the label text */
    else
      label->annotext = msStrdup(labeltext);
  }
@aboudreault aboudreault was assigned Jan 30, 2013
@aboudreault aboudreault pushed a commit that referenced this issue Feb 6, 2013
Alan Boudreault Fix point->draw() fails when no LABEL defined (closes #4572) e794f67
@aboudreault
Member

@akrherz I've also modified one thing in php/mapscript. I've put the last argument (text) optional, you can now simply call:

$point->draw($map, $layer, $img, 0);
@mkofahl mkofahl pushed a commit to faegi/mapserver that referenced this issue Apr 9, 2013
Alan Boudreault Fix point->draw() fails when no LABEL defined (closes #4572) 6f7a187
@mkofahl mkofahl pushed a commit to faegi/mapserver that referenced this issue Apr 9, 2013
Alan Boudreault Fix point->draw() fails when no LABEL defined (closes #4572) b742a3c
@aboudreault aboudreault pushed a commit that referenced this issue Apr 29, 2013
Alan Boudreault The text param of point->draw in php is now optional, no need of strl…
…en(labeltext) in libmapserver (#4572)
b8c297c
@aboudreault aboudreault pushed a commit that referenced this issue Apr 29, 2013
Alan Boudreault The text param of point->draw in php is now optional, no need of strl…
…en(labeltext) in libmapserver (#4572)
9a7bb09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment