[Mapserver-users] Re: Clarifications about mapscript 4.2

Sean Gillies sgillies at frii.com
Wed May 12 17:17:26 EDT 2004


Hey Eric,

I'm unable to reproduce your problems with my Python interpreter.  Here
is a session below.  I'm using the mapfile from the mapserver tests.

     Python 2.3.3 (#1, Jan  4 2004, 11:27:28)
     [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
     Type "help", "copyright", "credits" or "license" for more 
information.
     >>> import mapscript
     >>> test_map = 
mapscript.mapObj('/home/sean/projects/ms_42/mapserver/tests/test.map')
     >>> class00 = test_map.getLayer(0).getClass(0)
     >>> s0 = class00.getStyle(0)
     >>> s0
     <C styleObj instance at _b0761808_p_styleObj>
     >>> s0.color.toHex()
     '#ff9966'
     >>> s0.color.setRGB(0,0,0)
     0
     >>> s0.color.toHex()
     '#000000'
     >>> s0.color.setRGB(51,51,51)
     0
     >>> s0.color.toHex()
     '#333333'
     >>> s0.color.setRGB(102,102,102)
     0
     >>> s0.color.toHex()
     '#666666'

I can't reproduce the sticking.  Next a test with defined colors.

     >>> blue = mapscript.colorObj(0,0,255)
     >>> blue.toHex()
     '#0000ff'
     >>> s0.color = blue
     >>> s0.color.toHex()
     '#0000ff'
     >>> red = mapscript.colorObj(255,0,0)
     >>> s0.color = red
     >>> s0.color.toHex()
     '#ff0000'
     >>> s0.color = blue
     >>> s0.color.toHex()
     '#0000ff'

So it appears that this is working OK as well.

Now, looking at your script, there is a line

	$point->draw($map, $layerObj, $img, undef, "$point_id");

The fourth arg of pointObj::draw is supposed to be the classindex of the
appropriate class of your layer.  I'm not at all sure what we'd expect
when we give it a NULL instead of an integer in the
range [0 .. $layerObj->{numclasses}).   In your script it looks like
you should be passing a value of 0 instead of undef.

BTW, this reminds me how awful are the API for the various draw() 
methods.
The above method should really be something like

    pointObj::draw( imageObj img, classObj class, string text )

Since the layer and classindex arguments only serve to point to a class
anyway.  It's awkward to be passing a mix of references and integer 
indexes
to the class.

cheers,
Sean

On May 12, 2004, at 2:27 PM, Eric Bridger wrote:

> Hi Sean,
>
> I've been having trouble with styles and colors in Mapscript4.2b2. I've
> attached a small perl script and map file which demonstrates the
> problem.
>
> Loop thru some points, get the one class and  style defined in the map
> file and change various attributes: size, symbol, color.  I have no
> problem changing the class symbol or symbol size.  But the color seems
> strangely "sticky".  Whichever color is set first using
> $style->{color}->setRGB() remains in force.  The color DOES change from
> the color defined in the mapfile but then will not change again.
>
> I've also  found that (this is a separate problem)
> my $red_color = $mapscript::colorObj(255,0,0);
> $style->{color} = $red_color;
>
> does not work as expected.  The color is always black in this case.
>
> Am I missing something?  I will next attempt a completely dynamic
> approach, new class, new sytle, etc. and see if that works better.
>
> Thanks,
> Eric
>
> On Fri, 2004-05-07 at 13:21, Sean Gillies wrote:
>> Hi Eric,
>>
>> Was just looking at your Wiki pages and have some clarifications
>> for you.
>>
>> 1) STYLES: Most users will want to dynamically add new styles to a
>> class by
>> this syntax:
>>
>>     $class = $layer.getClass(0);
>>     $new_style = mapscript::styleObj($class);
>>
>> insertStyle() is for more specialized cases where you really want to
>> change
>> the ordering of styles or pass a fully-defined style around in your 
>> app.
>>
>> 2) SYMBOLS: I'd like to recommend that symbols be accessed through
>> methods of symbolSetObj class rather than through methods of mapObj.
>> For example:
>>
>>     $foo_index = $map->{symbolset}->index("foo");
>>
>> is, IMO, the better way to go than
>>
>>     $foo_index = $map->getSymbolByName("foo");
>>
>> The later is a poorly named function because it returns an integer, 
>> not
>> a
>> symbol, compared to mapObj::getLayerByName which *does* return a 
>> layer.
>> We're going to leave this in mapscript for backwards compatibility, 
>> but
>> the future direction is to make mapObj, layerObj, classObj,
>> symbolSetObj,
>> etc more container-like with index() methods that return the index of
>> a "child" object given the child's name, and that getFoo() methods
>> uniformly return instances of Foo, not a mix of instances and indexes.
>>
>> 3) You might want to point folks to the development documentation 
>> which
>> is
>> committed in CVS under mapserver/mapscript/doc/mapscript.txt and to 
>> the
>> HTML document that I have been generating and keeping online at
>>
>>     http://users.frii.com/sgillies/projects/mapscript/
>>
>> cheers,
>> Sean
>>
>>
>> --
>> Sean Gillies
>> sgillies at frii dot com
>> http://users.frii.com/sgillies
>
>
>
> <test_color.cgi><test_color.map>




More information about the mapserver-users mailing list