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

Attri, Abhishek aattri at cba.ua.edu
Fri Jul 9 15:50:04 EDT 2004


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.

With thanks in advance,

-Abhishek





-----Original Message-----
From: Eric Bridger [mailto:eric at gomoos.org] 
Sent: Friday, July 09, 2004 1:02 PM
To: Attri, Abhishek
Cc: Mapserver List
Subject: Re: [Mapserver-users] How to add text to a legend

On Fri, 2004-07-09 at 12:02, Attri, Abhishek wrote:
> Hi All,
> 
> I want to add name or text in front of my legend image. For example,
if
> a layer has two classes which are highlighted according to a
particular
> criterion, then I would like to show the legend for each class, and
the
> criterion (text) along with it.
> 
> It should look like: - Legend image1 text 1(or label)
> 
>                              Legend image2 text2
> 
> I tried giving different names to classes, but that didn't help. I
guess
> it has something to do with symbols. I am using PHP Map script, but
any
> sort of explanation would be helpful.

The CLASS NAME is the text used for the legend text, so what you
describe doing should work.  In mapscript you must make sure to set the
status of each layer to MS_ON first.

Eric







More information about the mapserver-users mailing list