[Mapserver-users] How to add text to a legend

Eric Bridger eric at gomoos.org
Fri Jul 9 16:01:47 EDT 2004


On Fri, 2004-07-09 at 15:50, Attri, Abhishek wrote:
> 
> There is one layer, and two classes. All are set to "ON". Everything
> works right except the legend. I get only one legend image for two
> classes, and also the legend text is missing.
> 
> Here is a sample of the code I am using to create layer, legend, and
> classes:-
> 
> // create a legend
>     $map->legend->set(keysizex, 12);
>     $map->legend->set(keysizey, 12);
>     //$map->legend->imagecolor->setRGB(200, 225, 124);
>     $map->legend->label->set(type, MS_BITMAP);
>     $map->legend->label->set(size, MS_MEDIUM);
>     //$map->legend->label->set(font, test);
>     $map->legend->label->color->setRGB(0, 0, 89);
>     $map->legend->set(status, MS_ON);
>     $image2 = $map->drawLegend();
>     $image_url2=$image2->saveWebImage();
> 
> 
> // create layer
>         $layer = ms_newLayerObj($map);
> 
>         $layer->set(name,"county");
>         $layer->set(type,MS_LAYER_POLYGON);
>         $layer->set(status,MS_ON);
>         $layer->set(data,"counties");
>         $layer->set(tolerance,10);
>         $layer->set(classitem,"POP_2000");
> 
>  // create class1
>             $class1 = ms_newClassObj($layer);
>             $class1->set(status, MS_ON);
>             $class1->set(name, 'myclass');
>             //$class1->set(title, test1);
>             $class1->setexpression('([POP_2000]<50000)');
>                 // create style
>                 $style = ms_newStyleObj($class1);
>                 $style->color->setRGB(255, 185, 15);
>                 $style->outlinecolor->setRGB(0, 0, 0);
> 
> // create class2
>             $class2 = ms_newClassObj($layer);
>             $class2->set(status, MS_ON);
>             $class2->set(name, 'myclass2');
>             //$class2->set(title, test2);
>             $class2->setexpression('([POP_2000]>50000)');
>                 $style = ms_newStyleObj($class2);
>                 $style->color->setRGB(139, 0, 0);
>                 $style->outlinecolor->setRGB(0, 0, 0);
> 
> Please help me understand what I am missing here.

I think you will need to draw your legend after you have created your 2
classes, not before.

Eric





More information about the mapserver-users mailing list