transparency with dynamically added shapes.

Sylvain Pasche sylvain.pasche at CAMPTOCAMP.COM
Wed Sep 1 11:37:33 EDT 2004


Hello,

I wanted to dynamically add shapes to a layer, and have the added shapes
inherits the transparency of the underlying layer.

However, these objects are drawn opaque on the map. I guess the
transparency is not computed after the Map->draw(). Heres the code I
used:


dl('php_mapscript.so');
$map = ms_newMapObj('test/test.map');

$outline_layer = $map->getLayerByName('polygon_triangle');

$shape = ms_newShapeObj(MS_SHAPE_POLYGON);

$r = ms_newRectObj();
$r->setextent(-0.2, 51.6222, 0.5, 51.977222);

$img = $map->draw();

$r->draw($map, $outline_layer, $img, 0, false);

$img->saveImage('out.jpeg');


Mapfile:

MAP
  NAME "Testing"
  EXTENT -0.5 50.977222 0.5 51.977222
  IMAGETYPE JPEG
  IMAGECOLOR 255 255 255
  STATUS ON
  SIZE 200 200

  PROJECTION
    "init=epsg:4326"
  END

  LAYER
    NAME "polygon_rectangle"
    TYPE POLYGON
    PROJECTION
      "init=epsg:4326"
    END
    STATUS ON
    DATA "polygon"

    CLASS
      NAME "0"
      STYLE
        COLOR 0 0 255
        OUTLINECOLOR 0 0 255
      END
    END
  END

  LAYER
    NAME "polygon_triangle"
    TYPE POLYGON
    PROJECTION
      "init=epsg:4326"
    END
    STATUS DEFAULT
    DATA "theme1"

    TRANSPARENCY 20

    CLASS
      NAME "0"
      STYLE
        COLOR 0 255 255
        OUTLINECOLOR 0 255 255
      END
    END
  END
END

The produced image is out.jpeg. We see there that there is no
transparency.

I noticed by the way a strange behaviour (bug?) when using png image
format: The colour of the dynamically added shape is taken from the
previous layer, as it can be seen on the attached image out.png.

As an alternative to the shape->draw() method, I wanted to use the
addFeature method:

$outline_layer = $map->getLayerByName('polygon_triangle');

$shape = ms_newShapeObj(MS_SHAPE_POLYGON);

$r = ms_newRectObj();
$r->setextent(-0.2, 51.6222, 0.5, 51.977222);

$outline_layer->addFeature($r);

$img = $map->draw();

But I got the following:

"Fatal error:  Object has an invalid _handle_ property" on the line
"map->draw()".

Thanks for any infos,

Sylvain

-------------- next part --------------
A non-text attachment was scrubbed...
Name: out.jpeg
Type: image/jpeg
Size: 2367 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/mapserver-users/attachments/20040901/7e56bd8a/out.jpeg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: out.png
Type: image/png
Size: 689 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/mapserver-users/attachments/20040901/7e56bd8a/out.png


More information about the mapserver-users mailing list