New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

This comment has been minimized.

Show comment
Hide comment
@akrherz

akrherz Jan 23, 2013

Contributor

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

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

This comment has been minimized.

Show comment
Hide comment
@akrherz

akrherz Jan 30, 2013

Contributor

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);
  }
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

This comment has been minimized.

Show comment
Hide comment
@aboudreault

aboudreault Feb 6, 2013

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);
Member

aboudreault commented Feb 6, 2013

@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 pushed a commit to faegi/mapserver that referenced this issue Apr 9, 2013

mkofahl pushed a commit to faegi/mapserver that referenced this issue Apr 9, 2013

aboudreault pushed a commit that referenced this issue Apr 29, 2013

aboudreault pushed a commit that referenced this issue Apr 29, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment