[Mapserver-users] Bug 663 (Re: Clarifications about mapscript 4.2)

Sean Gillies sgillies at frii.com
Thu May 13 13:19:58 EDT 2004


On May 13, 2004, at 7:09 AM, Eric Bridger wrote:

> On Wed, 2004-05-12 at 17:13, Sean Gillies wrote:
>> Hey Eric,
>>
>> I'm unable to reproduce your problems with my Python interpreter.  
>> Here
>> is a session below.  Note that I'm using the next generation class
>> names ... 'Map' is exactly the same as 'mapObj', 'Color' == 
>> 'colorObj',
>> &c.
>>
>>      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.Map('/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.Color(0,0,255)
>>>>> blue.toHex()
>>      '#0000ff'
>>>>> s0.color = blue
>>>>> s0.color.toHex()
>>      '#0000ff'
>>>>> red = mapscript.Color(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");
>>
> Sean,
>
> Perl mapscript4.2b2 works in the above cases as well.  The problem 
> seems
> to lie deeper, in the point->draw() method, i.e. even when
> style->toHex() reports #0000ff, point->draw() draws a black or whatever
> color was first set.  I will continue to investigate.
>
> Eric
>

Eric, add your email to the tracker if you want to follow this

http://mapserver.gis.umn.edu/bugs/show_bug.cgi?id=663

I've figured it out.  Has to do with the MapServer "pens", when setting
style colors we are not resetting the value of pens, hence the set color
appears to stick.  The following works:

     def testDrawPoints(self):
         points = [mapscript.pointObj(-0.2, 51.5),
                   mapscript.pointObj(0.0, 51.0),
                   mapscript.pointObj(0.2, 51.5)]
         colors = [mapscript.colorObj(255,0,0),
                   mapscript.colorObj(0,255,0),
                   mapscript.colorObj(0,0,255)]
         img = self.mapobj1.prepareImage()
         layer = self.mapobj1.getLayerByName('POINT')
         class0 = layer.getClass(0)
         for i in range(len(points)):
             style0 = class0.getStyle(0)
             style0.color = colors[i]
             style0.color.pen = -4
             assert style0.color.toHex() == colors[i].toHex()
             points[i].draw(self.mapobj1, layer, img, 0, "foo")
         img.save('test_draw_points.png')

and results in red, green, and blue points.  I'm going to find a 
solution
that's better than explicitly setting the pen attribute of a color.

cheers,
Sean


--
Sean Gillies
sgillies at frii dot com
http://users.frii.com/sgillies




More information about the mapserver-users mailing list