Opened 21 years ago

Closed 21 years ago

Last modified 21 years ago

#276 closed defect (fixed)

Vector layers grayed out when map image is first loaded after editing mapfile or dynamically changing a mapfile parameter

Reported by: keon@… Owned by: warmerdam
Priority: high Milestone:
Component: GDAL Support Version: 4.0
Severity: normal Keywords:
Cc:

Description

MS 3.7 CVS (Jan 31), GDAL 1.1.8, GD 2.0.11, using IMAGEMODE PC256.  I am able to
reproduce this in a couple of ways:

1)  If I make any change to the mapfile (or just open and save without editing),
the first time I load the application (or refresh the map) the vector layers in
the map image are grayed out.  This only happens to vector layers, not raster
layers.  In this case it isn't such a big deal since I can just refresh the map
twice after editing the mapfile, after which the problem goes away.

2)  This also happens when changing mapfile parameters dynamically.  For
example, in my PHP app I generate a larger image to use in the PDF when the user
requests PDF output (e.g., $map->set('width',1350); $map->set('height',900);). 
This also causes the vector layers in the resulting image to be grayed out. 
This is a problem, because anytime something is altered dynamically the user has
to refresh the map twice before the proper image appears.  And the images I'm
sending to PDFlib are grayed out.

However, I have not been able to reproduce this with a simple mapfile and PHP
interface, just with the more complicated mapfile and PHP app I've been working
with.  So, it's possible this is a problem with my app, but I can't think what
could be causing it.

Attachments (1)

graymap_problem.gif (58.1 KB ) - added by keon@… 21 years ago.
top image is grayed out, bottom image is correct

Download all attachments as: .zip

Change History (7)

by keon@…, 21 years ago

Attachment: graymap_problem.gif added

top image is grayed out, bottom image is correct

comment:1 by fwarmerdam, 21 years ago

Dylan, 

I don't really have any idea what is going on here.  I need a situation I
can reproduce. 

In case 1) above you mention that just loading and saving the map causes the
problem.  I assume you mean rendering with the copy of the map that was saved
from PHP, is that right?  I suspect this is an issue with mapscript not 
saving outputformat information, but it is hard for me to know since I don't
work with mapscript much.  Isn't there a before an after map you can compare
with diff? 

I will have to punt on this till you can provide something I can reproduce. 

Best regards,

comment:2 by keon@…, 21 years ago

OK, it might be a MapScript thing.  Here are some more details, but let me begin
by saying I don't know whether this is a bug or normal behavior; maybe Daniel
can let me know.  To me it seems strange, but maybe I'm missing something.

With PC256 output the mapfile must be loaded more than once within a PHP script
when dynamically changing some of the mapfile parameters.  For example, see the
short script below.  The first image renders just fine.  The second image has
problems unless I load the mapfile again prior to changing the image width and
height via mapscript.  In this case there are a couple of rendering problems --
a grayed out map (if layer transparency is set) and line layers changing color
each time the page is reloaded, plus fill color missing from polygon (if layer
transparency is not set).

In my testing this ONLY happens with PC256 output.  RGB and RGBA each do the
right thing without having to load the mapfile a second time in the script.

I copied the PHP script and mapfile below.  The shapefiles are about 1 MB
zipped.  If you want that file, let me know and I'll upload it.

======================================================
<?php
dl('php_mapscript.so');

$map = ms_newMapObj('/gis/mapfiles/test2.map');
$image0=$map->draw();
$image0_url=$image0->saveWebImage();

//$map = ms_newMapObj('/gis/mapfiles/test2.map');
$map->set('width', 630);
$map->set('height', 420);
$image1 = $map->draw();
$image1_url = $image1->saveWebImage();
?>

<html>
<body>

First image generated...<br>
<img src="<?php echo $image0_url?>">
<br><br>
Second image generated...<br>
<img src="<?php echo $image1_url?>">

</body>
</html>
======================================================

======================================================
NAME CRYPTO
SIZE 480 320
STATUS ON
SYMBOLSET "/gis/symbols/symbols.sym"
EXTENT 371000 5250000 492000 5353000 #minx miny maxx maxy
UNITS METERS
SHAPEPATH "/gis/data/crypto"

IMAGETYPE png8
#IMAGETYPE png24

OUTPUTFORMAT
  NAME png8
  DRIVER "GD/PNG"
  MIMETYPE "image/png"
  IMAGEMODE PC256
END
OUTPUTFORMAT
  NAME png24
  DRIVER "GD/PNG"
  MIMETYPE "image/png"
  IMAGEMODE RGB
END

WEB
  IMAGEPATH "/www/temp/"
  IMAGEURL "/temp/"
END

LAYER
  NAME boundary
  TYPE POLYGON
  STATUS DEFAULT
  DATA onp_bnd_83
  #TRANSPARENCY 60
  CLASS
    NAME "ONP boundary"
    OUTLINECOLOR 0 0 0
    COLOR 243 248 245
  END
END

LAYER
  NAME roads
  TYPE LINE
  STATUS DEFAULT
  DATA road83
  CLASSITEM "LEGEND"
  CLASS
    NAME "Paved"
    EXPRESSION /Paved/ #contains "Paved"
    COLOR 180 0 0
    SYMBOL "circle"
    SIZE 2
  END
  CLASS
    NAME "Gravel"
    EXPRESSION /Gravel/ #contains "Gravel"
    COLOR 0 180 0
    SYMBOL "circle"
    SIZE 1
  END
  CLASS
    NAME "Closed"
    EXPRESSION /Closed/ #contains "Closed"
    COLOR 0 0 180
    SYMBOL "circle"
    SIZE 1
  END
END

END
======================================================

comment:3 by dmorissette, 21 years ago

I suspect that the cause for this may be related to the same issue as bug 275.  
See bug 275 comment #1: I think there is something wrong with the way the 
rendering functions in mapgd.c allocate their colors:

In msDrawLineSymbolGD() you find the following code:

  if(style->backgroundcolor.pen == MS_PEN_UNSET) msImageSetPenGD(img, 
&(style->backgroundcolor));
  if(style->outlinecolor.pen == MS_PEN_UNSET) msImageSetPenGD(img, 
&(style->outlinecolor));
  if(style->color.pen == MS_PEN_UNSET) msImageSetPenGD(img, &(style->color));

I haven't tested this yet, but I believe that the problem is that after the 
first map draw, the pen index is set, but refers to a color index in a different 
imageObj.  The best solution would probably be to maintain the pen indexes 
inside the imageObj, but this could become complex.  Another option could be to 
reset the pen index in every colorObj in the mapfile everytime that a new 
imageObj is allocated, but side-effects could still happen.  Finally, a third 
option could be to simply remove the if () statements in the code blocks above 
and always call msImageSetPenGD() even if the pen appears to be set already, but 
this may not be very efficient.

comment:4 by sdlime, 21 years ago

Looks to me like msClearPenValues or msClearLayerPenValues need to be
strategically placed, most likely in msDrawLayer and that should fix it.
Could've swarn I already did that but I guess not. Will add the calls now...

Steve

comment:5 by sdlime, 21 years ago

Resolution: fixed
Status: newclosed
I added code to clear layer pen values each time a layer is drawn. That should
fix this problem within MapScript when multiple images are rendered without
reloading the map file. If someone would test and confirm the fix that would be
helpful. Marking fixed for the time being, Can always reopen...

Steve

comment:6 by keon@…, 21 years ago

Steve, I've tested this against two apps that were giving me problems, and both
are now working perfectly.  Thank you for fixing this!!
Note: See TracTickets for help on using tickets.