Adding shapefile dynamically with php_mapscript 4.4.2

Stephen Woodbridge woodbri at SWOODBRIDGE.COM
Mon Jun 13 23:03:23 EDT 2005


Jacob,

The way I do this is to create a normal in the mapfile with the STATUS 
OFF and no DATA statement. Then in mapscript all I do it set the STATUS 
ON and assign the path to the DATA like you are doing below.

It is MUCH easier to create a template layer in the mapfile and then 
manipulate it, rather than creating the whole thing from scratch.

YMMV,
   -Steve W.

Jacob Delfos wrote:
> Hi All,
>  
> I am trying to dynamically add a shapefile which I created at runtime. 
> The shapefile is created successfully (it opens up ok). But I am not 
> having any luck adding it as a layer.
>  
> This is the code I have:
>  
>       $queryResultlayer = ms_newLayerObj( $oMap );
>       $queryResultlayer->set( "name", "Queryresult" );
>       $queryResultlayer->set( "type", $shapetype );
>       $queryResultlayer->set( "status", MS_ON );
>       $queryResultlayer->set( "data", 
> $szSessionDir."/queryResultShapefile");
>       $queryResultlayer->set( "template", "ttt" );
>       $queryResultlayer->set( "tolerance", 5 );
>       $queryResultlayer->set( "toleranceunits", MS_PIXELS);
>       $queryResultlayer->setProjection($mapprojection);
>       $queryclass = ms_newClassObj($queryResultlayer);
>       $queryclass->set("name", "Query result");
>       $queryclass->set("status", MS_ON);
>       $style = ms_newStyleObj($queryclass);
>       $style->color->setRGB(255, 255, 0);
>       $style->outlinecolor->setRGB(255, 0, 0);
>  
> The layer is not showing (extents of map are correct). I am not getting 
> any errors either. The temporary mapfile being created in the session 
> directory does not contain my layer. Am I missing something?
>  
> The $oMap object is a reference to the $oMap from the session (using 
> Chameleon). I am loading the session from an Iframe, and creating the 
> $oMap object like:
>  
> $oMap =& $oMapSession->oMap;
>  
> So if I add a layer to the map object, the layer should show if the map 
> image is reloaded in the main frame, right?
>  
> Any help would be much appreciated.
>  
> Regards,
>  
> Jacob
>  
> 
> JACOB DELFOS
> SPATIAL INFORMATION ANALYST
> Maunsell Australia Pty Ltd
> 629 Newcastle Street, Leederville, WA 6007
> PO Box 81, Leederville, WA 6902
> Western Australia
> ABN 20 093 846 925
>  
> Tel     + 61 8 9281 6185
> Fax    + 61 8 9281 6297
> jacob.delfos at maunsell.com <mailto:jacob.delfos at maunsell.com>



More information about the mapserver-users mailing list