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?

nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
asked Sep 17, 2013 at 14:04

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);
answered Sep 17, 2013 at 14:44
2
  • allright, i'll have a try in the morning! Commented Sep 17, 2013 at 17:26
  • Great it works! Commented Sep 18, 2013 at 7:26

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.