1

How can I set attribute values of a layer object with MapScript?

I'm using MapServer version 5.0.3, the php_mapscript.so lib is loaded in my app context

I have a simple Mapfile:

MAP
    SIZE 500 500
    EXTENT -180 -90 180 90
    UNITS dd
    CONFIG "CPL_DEBUG" "ON"
    CONFIG      "MS_ERRORFILE" "/var/www/Data/Data/mapserver/mapserver.log"
    SYMBOLSET "/var/www/Data/Data/mapserver/symbols.sym"
    FONTSET "/var/www/Data/Data/mapserver/fontset.txt"

#--------------------------------------------------------------------------------
# load lines
#--------------------------------------------------------------------------------

    LAYER
        NAME "loadlines"
        TYPE POLYGON
        DATA "/var/www/Data/Data/mapserver/data/loadlines/loadlines.shp"
        STATUS ON
        OPACITY 100
        DEBUG 5

        CLASS #default coloring
            STYLE
              COLOR 0 0 0
              WIDTH 6
              #PATTERN 40 10 END
            END
            NAME "gust"
            OUTLINECOLOR 254 254 254
            COLOR 100 100 100
            #OPACITY 50
        END

        TEMPLATE "blank.html"
        DUMP TRUE # allow GML export
        PROJECTION
            "init=epsg:4326"
        END
        METADATA 
            "wms_title"     "ffg_test"     
            "wms_srs"       "EPSG:54004 EPSG:4269 EPSG:4326" 
        END 
    END 
END

Which I want to view by calling this PHP script:

<?php
$map_path="/var/www/Data/Data/mapserver/routeguardTemp/test/";

$map = ms_newMapObj($map_path."loadlines.map");
$layer = $map->getLayerByName('loadlines');
$layer->set('opacity', 10);
$image=$map->draw();
$image_url=$image->saveWebImage();

?>

 <HTML>
  <HEAD>
      <TITLE>Map</TITLE>
  </HEAD>
  <BODY>
      <IMG SRC=<?php echo $image_url; ?> >
  </BODY>
 </HTML>

The script should alter the opacity value of the layer, but there is no effect.

How can I do this?

1 Answer 1

0

Not sure about the old version of mapscript, the documentation is not available anymore. But for the latest version of PHP mapscript, the property of layer object is set via 'set' method.

int set(string property_name, new_value)
    Set object property to a new value.

So maybe you can try with:

$layer->set('opacity', 10);
2
  • allright, i'll have a try in the morning!
    – jorrebor
    Sep 17, 2013 at 17:26
  • Great it works!
    – jorrebor
    Sep 18, 2013 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.