[Mapserver-users] Coloring Problem

Norbert Thieme norbert.thieme at ilmenau.baw.de
Tue May 4 09:37:05 EDT 2004


Norbert Thieme schrieb:
> Sam Choudry schrieb:
> 
>> Hello,
>>
>>     Here is the same old problem still not solved. I want to change the
>> color of my area layer "nal-blk" according to user input. For that I am
>> using the code:
>>
>>     if($r!='' && $g!='' && $b!='')
>>     {
>>         $layer = $map->getlayerbyname("nal-blks");
>>         $class = $layer->getclass(0);
>>         $layer->open($map->shapepath);
>>         $index = findindex($r,$g,$b);
>>         $class->set('color',index);
>>     }
>>
>>
>>
>>     I am using a function I received from one of the list members,
>>     
>>     function findindex($r,$g,$b)
>>      {
>>            GLOBAL $map;
>>               $r1=(int) $r;
>>            $g1=(int) $g;
>>            $b1=(int) $b;
>>  
>>            for($i=-10;$i<0;$i++)
>>             {
>>                   $col=$map->getColorByIndex($i);
>>                         $tr=$col->red;
>>                   $tg=$col->green;
>>                   $tb=$col->blue;
>>
>>                   if(($r1 == $tr) && ($g1 == $tg) && ($b1 == $tb))
>>                    {
>>                      $in=$i;
>>                      break;                         }               }
>>            $in=$in+1;
>>            return($in);
>>      }
>>
>>
>>   The Error message are :
>>     Warning: Wrong parameter count for open() in 
>> c:\inetpub\wwwroot\php\nalbari.php on line 21
>>
> 
> Hi,
> 
> The layer->open() function don't except any paramters I think so simply 
> leave it empty.
> 
>>     Fatal error: Property 'color' does not exist in this object.
>>     in c:\inetpub\wwwroot\php\nalbari.php on line 23
>>
> 
> The next message say that there is no color in the class-object. So you 
> can't change it and I just had a look in the mapscript docs - there seem 
> to be no color-object. If I don't have missed something there will be no 
> way to change that but I think there should be one.
> 
> I hope someone more experienced knows a workaround or can point us to 
> the right objects/functions or docs.
> 
> Regards,
> Norbert
> 
>>
>>   The Map File snippet is also provided:
>>
>>     LAYER             #DISTRICT BLOCKS#
>>       NAME "nal-blks"
>>       DATA nal-blks
>>       STATUS ON
>>       TYPE POLYGON
>>       CLASS
>>        NAME '0'
>>        COLOR 219 250 253
>>        OUTLINECOLOR 154 181 250
>>       END
>>     END       
>>   What can be the possile solution to this? Regards,
>>
>>                     Samuzzal
>>
>>
>> _____________________________________________________________
>> Linux.Net -->Open Source to everyone
>> Powered by Linare Corporation
>> http://www.linare.com/
>> _______________________________________________
>> Mapserver-users mailing list
>> Mapserver-users at lists.gis.umn.edu
>> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
>>
>>
> 
> 


Hi,

sorry I was wrong. It was in the docs I only looked on the wrong point. 
This is the way to go:

       $addlyr_layer = ms_newLayerObj($map);
       $addlyr_layer->set(status, MS_ON);
       $addlyr_layer->set(name, $addlyr_file);
       $addlyr_layer->set(data, $addlyr_string);
       $addlyr_layer->set(type, 1);

       $addlyr_class = ms_newClassObj($addlyr_layer);
       $addlyr_class->set(name, "Class");

       $addlyr_style = ms_newStyleObj($addlyr_class);
       $addlyr_style->color->setRGB(10, 100, 10);

       $image=$map->draw();
       $image_url = $image->saveWebImage();

Regards,
Norbert



More information about the mapserver-users mailing list