labelObj in mapscript ?

Doyon, Jean-Francois Jean-Francois.Doyon at CCRS.NRCan.gc.ca
Thu Jun 22 14:56:20 EDT 2000


Thanks a bunch ...

Now, I'm just stumped ...

I've setup a system where the mapfile type parameters are now stored in a
database (At least all the ones that I can).

So it cycles through the database, determining classes and labels and so on
.. It's been working well so far. I've managed
to color all canadian provinces and territories using a classitem and an
expression, and storing all the classes in the DB
and so on. Now I'm trying to generate an annotation layer that is the city
names, but I'm having no luck, the labels simply
won't draw it seems, and I'm running out of ideas as to why this might be
...

Assuming the back end data is correct (which it IS !), can anybody find a
problem with the code below ? It's fairly straightforward ...
I know it's ugly, I'm just toying around for now, the production version
will be much nicer :)

I've commented some lines of code as well , meaning I've toyed around with
them without success ...

Any help would be greatly appreciated !

oh BTW, I'm using a nightly build from a couple of nights ago, and
$class->{label}->{backgroundcolor} does not seem to "exist" ...

J.F.

sub getmap {
	checklayers();
	checksrs();
	checkformat();
	$map = new mapObj('/home/mapdata/canada/perltest.map');
	$map->{name} = 'Test';
	$map->{status} = $mapscript::MS_ON;
	$map->{height} = $height;
	$map->{width} = $width;
	$map->{interlace} = $mapscript::MS_OFF;
	$map->{transparent} = $mapscript::MS_OFF;
	$map->{shapepath} = 'data';
	$map->{imagecolor}->{red} = 255;
	$map->{imagecolor}->{green} = 255;
	$map->{imagecolor}->{blue} = 255;
	my $ext = new rectObj();
	my @bb = split(/,/,$bbox);
	$ext->{minx} = $bb[0];
	$ext->{miny} = $bb[1];
	$ext->{maxx} = $bb[2];
	$ext->{maxy} = $bb[3];
	$map->{extent} = $ext;
	$map->{units} = $mapscript::MS_METERS;
	foreach ( @reqlayer ) {
		$res = $conn->exec("SELECT id,data,type,classitem,labelitem
FROM layers WHERE name='$_'");
		my @laydata = $res->fetchrow;
		$layer = new layerObj($map);
		$layer->{name} = $_;
		if ( $laydata[2] eq "p" ) { $layer->{type} =
$mapscript::MS_POLYGON }
		elsif ( $laydata[2] eq "l" ) { $layer->{type} =
$mapscript::MS_LINE }
		elsif ( $laydata[2] eq "t" ) { $layer->{type} =
$mapscript::MS_POINT }
		elsif ( $laydata[2] eq "a" ) { $layer->{type} =
$mapscript::MS_ANNOTATION }
		else { showerror('There seems to be a server configuration
error. Layer <B>'.$_.'</B> specifies an unsupported shape type :
',$laydata[1],'Please contact the server administrator listed below.') }
		$layer->{status} = $mapscript::MS_ON;
		$layer->{data} = $laydata[1];
		if ( $laydata[3] ) { $layer->{classitem} = $laydata[3] }
		elsif ( $laydata[4] ) { $layer->{labelitem} = $laydata[4] }
		$res = $conn->exec("SELECT
id,color,outlinecolor,expression,symbol,size FROM classes WHERE
layid=$laydata[0]");
		while ( @classdata = $res->fetchrow ) {
			$class = new classObj($layer);
			$class->{symbol} = $classdata[4];
			@colors = getcol($classdata[2]);
			$class->{outlinecolor} =
$map->addColor($colors[0],$colors[1],$colors[2]);
			@colors = getcol($classdata[1]);
			$class->{color} =
$map->addColor($colors[0],$colors[1],$colors[2]);
			if ( $classdata[5] ) { $class->{size} =
$classdata[5] }
			if ( $laydata[3] ) {
$class->setExpression($classdata[3]) }
			elsif ( $laydata[4] ) {
				$res2 = $conn->exec("SELECT
backgroundcolor,color,relposition,size,type FROM classlabels WHERE
classid=$classdata[0]");
				while ( @labeldata = $res2->fetchrow ) {
					@colors = getcol($labeldata[1]);
					$class->{label}->{color} =
$map->addColor($colors[0],$colors[1],$colors[2]);
					$class->{label}->{position} =
$mapscript::MS_AUTO;
					$class->{label}->{size} = 'GIANT';
					$class->{label}->{type} =
$mapscript::MS_BITMAP;
					$class->{label}->{wrap} = " ";
				}
			}
		}
	}
#	$map->prepareImage();
	$img = $map->draw();
#	$map->drawLabelCache($img);
	print "Content-Type: image/gif\n\n";
	
mapscript::msSaveImage($img,undef,$map->{interlace},$map->{transparent});


> ----------
> From: 	Stephen Lime[SMTP:steve.lime at dnr.state.mn.us]
> Sent: 	Thursday, June 22, 2000 11:43 AM
> To: 	Jean-Francois.Doyon at CCRS.NRCan.gc.ca;
> mapserver-users at lists.gis.umn.edu
> Subject: 	Re: labelObj in mapscript ?
> 
> Since there are no formal methods for label objects most of the
> documentation
> is simply the labelObj parameters in the map file docs. Labels are part of
> classes,
> scalebar and legend objects and are accessed through those. Syntax is
> simple:
> 
>   $class->{label}->{size} = 12;
>   $map->{scalebar}->{label}->{color} = $map->addColor(0,0,0);
> 
> There are 2 exceptions to the params in the mapfile docs, ANGLE and
> MINFEATURESIZE
> when using the AUTO keyword. Instead use:
> 
>   $class->{label}->{autoangle} = 1;
>   $class->{label}->{autominfeaturesize} = 1;
>   
> Will add this to the new site...
> 
> Steve
> 
> >>> "Doyon, Jean-Francois" <Jean-Francois.Doyon at CCRS.NRCan.gc.ca> 06/22/00
> 09:22AM >>>
> Exactly how are Label Objects handled with mapscript ? I don't see any
> labelObj type method defined in the docs ...
> 
> I'm trying to put labels together for a class for an annotation type layer
> ... (Cites w/ names)
> 
> Or ar the Label parameters just part of the class ? can I go
> $class->{type}
> = 'Bitmap' ?
> 
> Thanks,
> 
> 
> Jean-Francois Doyon
> Internet Service Development and Systems Support
> GeoAccess Division
> Natural Resources Canada
> (613) 992-4902
> 
> 
> Stephen Lime
> Internet Applications Analyst
> 
> Minnesota DNR
> 500 Lafayette Road
> St. Paul, MN 55155
> 651-297-2937
> 



More information about the mapserver-users mailing list