Class Names not saved?
Lowell Filak
lfilak at MEDINACO.ORG
Fri Sep 2 06:48:02 PDT 2005
The following message was sent by Ben Loh <benpub at INQUIRIUM.NET> on Fri,
2 Sep 2005 00:43:45 -0500.
> Hi,
>
> I'm putting together a historical map application for high
> school/college level students and am running into some problems with
> setting class names.
>
> Perhaps I'm missing something obvious, but here's what's happening:
> I want to dynamically create classes for a given map (In the full
> app, I create classes, for the test app, I'm just changing an
> existing class). So, I read in the map, get the layer, and set the
> class name to a new name. Everything looks fine until I try to get
> the class name from the layer again: the class name reverts to the
> default name defined in the .map file! Is this some kind of
> referencing problem that I'm overlooking? Any help would be much
> appreciated.
>
> Thanks!
>
> Ben
>
>
> Here's a snippet of my map file:
> ============================================================
> LAYER
> NAME "PersonSqK"
> DATA states1790
> STATUS ON
> TYPE POLYGON
>
> CLASS
> NAME "Orig Class Name"
> EXPRESSION ([PERSONSSQK] <= 305)
> STYLE
> COLOR 255 255 255
> OUTLINECOLOR 153 153 153
> END #STYLE
> END #CLASS
>
> END #LAYER
>
>
>
> And here's some test code to generate the error:
> ============================================================
> <?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
More information about the MapServer-users
mailing list