Class Names not saved?
Lowell Filak
lfilak at MEDINACO.ORG
Fri Sep 2 08:57:52 PDT 2005
The following message was sent by Ben Loh <ben at inquirium.net> on Fri, 2
Sep 2005 10:15:50 -0500.
> At 9:48 a -0400 9/2/05, Lowell Filak wrote:
> >
> > > <?php
> >> dl('php_mapscript.so');
> >>
> >> function dbgout( $text ) { echo $text.'<br>'; }
> >>
> >> $map = ms_newMapObj( 'classtest.map' );
> >>
> >> $allLayers = $map->getAllLayerNames();
> >> foreach($allLayers as $a) {
> >> $theLayer = $map->getLayerByName($a);
> >>
> > > $baseClass = $theLayer->getClass( 0 );
> >> dbgout( 'baseClass default name = '.$baseClass->name);
> >> // This displays: "Orig Class Name"
> >>
> >> // Try setting the name to something new
> > > $baseClass->name = 'Replaced Name';
> >> dbgout( 'baseClass changed name = '.$baseClass->name);
> >> // This displays: "Replaced Name", so far everything is fine.
> >>
> >> }
> >>
> >> foreach($allLayers as $a) {
> >> $theLayer = $map->getLayerByName($a);
> >>
> >> $baseClass = $theLayer->getClass( 0 );
> >> dbgout( 'baseClass reread name = '.$baseClass->name);
> >> // This displays: "Orig Class Name"!!!! Where did the replaced
> >name go?
> >> }
> >>
> >> ?>
> >
> >Ben,
> >
> >I'm not sure where in your code you change $a to 'Replaced Name' before
> >running the 2nd $map->getLayerByName($a)?
> >If $a is not changed, aren't you asking for $map->getLayerByName("Orig
> >Class Name")?
> >
> >Lowell
>
>
> Hi Lowell,
>
> Thanks for answering.
>
> Hmm...maybe I'm missing something about the way that mapscript works.
> $a refers to the layer names. So $a is being set in the "foreach..."
> calls. I then loop through the layers, setting $theLayer to each
> layer in turn.
>
> I'm setting the name of the classes in the line $baseClass->name =
> 'Replaced Name';. The $baseClass is being retrieved from the layer
> by the line $baseClass = $theLayer->getClass( 0 );.
>
> So if I grab a layer, then grab a class, then change the name of the
> class, am I working with a reference to the actual class, or am I
> somehow working with a copy of the class? Is this the source of my
> problem?
>
> Thanks,
Ben,
I believe you're working with the layer with the changed name up until
the point when the code re-selects the layer based on the old name. But
I could be missing something in the code.
Lowell
More information about the MapServer-users
mailing list