Opened 20 years ago

Closed 20 years ago

#497 closed defect (invalid)

ColorObj & Styles verson 3.6 to 4.0

Reported by: tmelhuish@… Owned by: sdlime
Priority: high Milestone:
Component: MapScript Version: 4.1
Severity: normal Keywords:
Cc: sgillies@…

Description

In mapscript 3.6 I was able to change a color of a class object. I see in 4.0 
you are now using styles to set the class colors. I see that the $style->color 
is set to a colorObj not an integer as before with a class. How do you get a 
colorObj that already exists so you can pass it to $style->color? I assume 
this is my problem.

Here is my code in MS 3.6 
+++++++++++++++++++++++++++
        local $lyrstr;
	foreach $lyrstr (@ChgPrtLayerColor) {
		local @name=split />/ , $lyrstr;
		$layer = $map->getLayerByName($name[0]) or &AppletMsg('Unable 
to get PrintColor layer',"error");
		$class= $layer->getClass(0);
		$class->{color}= 8;
	}

#############################################

I tried this in 4.0 with no luck

++++++++++++++++++++++++++++++++++++++
        local $lyrstr;
	foreach $lyrstr (@ChgPrtLayerColor) {
		local @name=split />/ , $lyrstr;
		$layer = $map->getLayerByName($name[0]) or &AppletMsg('Unable 
to get PrintColor layer',"error");
		$class= $layer->getClass(0);
                $style= $class->{styles};  # I get a hash from this
		$style->{color}= 8;  # Bombs here brcause I need a colorObj
                                        not an integer
	}

 ++++++++++++++++++
Thanks,
tom

Change History (1)

comment:1 by sgillies@…, 20 years ago

Cc: sgillies@… added
Resolution: invalid
Status: newclosed
This is not a bug, but a change to mapscript.  The map palette is no
longer exposed to mapscript in 4.0.  We now use the colorObj class.
A style's color attributes are instances of colorObj.

Use something like this:

$c = new mapscript::colorObj;
$c{red} = 255;
$c{green} = 255;
$c{blue} = 255;
$style->{color} = $c;

I hope I haven't mangled the Perl mapscript syntax too badly.


Note: See TracTickets for help on using tickets.