[Mapserver-users] Re: html-type legends with perl mapscript
Puneet Kishor
pkishor at geoanalytics.com
Tue May 27 07:41:41 PDT 2003
Thanks Sean, Daniel, for responding. However...
> On Monday, May 26, 2003, at 11:00 PM, pkishor_98 wrote:
>
>> ..
>> so, to those who know... please, what is the difference between
>> createLegendIcon and
>> drawLegendIcon?
>>
>> I want to draw a separate legend icon for each layer, but if a layer
>> has a more than
>> one classes, I would like to be able to draw a single image file with
>> icons for all the
>> classes...
On Tuesday, May 27, 2003, at 08:43 AM, Sean Gillies wrote:
> createLegendIcon makes an imageObj of the proper format and size.
> drawLegendIcon draws colors/shapes into the imageObj (passed in
> as the 5th argument).
On Tuesday, May 27, 2003, at 08:41 AM, Daniel Morissette wrote:
> CreateLegendIcon() creates a brand new image with the icon drawn on it.
>
> DrawLegendIcon() draws the legend icon at the specified location in an
> already existing image.
Ok, that is what I figured out late last night, but couldn't validate
that because I reached no success with my shenanigans. createLeg does
its job fine, but drawLeg creates a badly formed image... the image is
formed but can't be opened by either my browser (which hangs) or
Photoshop which croaks "badly formed file" or some such.
I am not sure how I am going to implement this eventually, but for now
I want to try out a separate legend icon for each layer. If a layer has
more than one classes then I want a single image with all the key boxes
for each class stacked one below another. So, this is what I tried in
my read-write perl ;-) --
#======
for (0..$mapObj->{numlayers} - 1) {
# grab the layer
my $layerObj = $mapObj->getLayer($_);
# name this layer's legend image
my $layer_legimg = 'leg_'.$layerObj->{name}.'.png';
# create a new image object for this layer's legend
# as wide as the keysize width, and
# as high as the sum of the heights of all the keys in this layer
# plus the vertical spacing between the keys
my $imgObj = new mapscript::imageObj(
$mapObj->{legend}->{keysizex},
(
(
$layerObj->{numclasses} *
($mapObj->{legend}->{keysizey} + $mapObj->{legend}->{keyspacingy})
) -
$mapObj->{legend}->{keyspacingy}
)
);
# loop over each class
for (0..$layerObj->{numclasses} - 1) {
# grab the class
my $classObj = $layerObj->getClass($_);
# calculate the vertical offset for this keybox
my $y_offset = ($_ * ($mapObj->{legend}->{keysizey} +
$mapObj->{legend}->{keyspacingy}));
# draw the keybox in the image
$classObj->drawLegendIcon(
$mapObj,
$layerObj,
$mapObj->{legend}->{keysizex},
$mapObj->{legend}->{keysizey},
$imgObj,
0,
$y_offset
);
} # end class loop
# save the image
$imgObj->saveImage(
$imgdir.$layer_legimg,
$mapscript::MS_PNG,
$mapObj->{interlace},
$mapObj->{transparent},
$mapObj->{imagequality}
);
} # end layer loop
#======
As I said above... I get an image, but it is no good. Is there anything
wrong in my logic?
>
> Maybe use Perl-GD or ImageMagick to copy and paste individual
> class legendIcons into one image per layer?
>
that is definitely an option, but I'd rather not, since I am accessing
gd anyway via Mapserver. And drawLegendIcon is supposed to do exactly
that... the fewer modules I have to depend on, the more portable my
application.
Many thanks,
Puneet.
More information about the MapServer-users
mailing list