Sam wrote:
> Apologies if this has been asked previously but I had no luck searching 
> the archive.

nope, this is s new one.

> I am using FloatCanvas to construct a mapping tool and my 
> world coordinates are in the projection I am using (NZTM).  This is all 
> working quite nicely but I wish to add scale and direction images such 
> that they are placed using pixel coordinates.

That does make sense. It's interesting that I've never had the use case 
myself yet.

>  This is so they remain in 
> place unscaled as the user pans and zooms.  Is there a simple way of 
> doing this?  I have tried subclassing Bitmap (and creating a new 
> PixelBitmap class) where I have edited the _Draw function to not scale 
> the coordinates (pixel coordinates are passed in).

You'd think that would work, but...

   I don't see the
> print message I put in the modified _Draw function and I don't get any 
> error messages and when I zoomtofit everything disappears (obviously the 
> pixel coords are still being treated as world coords, which is not what 
> I want!!).

I thin the problem is that FloatCanvas doesn't try to draw objects that 
aren't within the present view. It does that by checking if the bounding 
box of the object overlaps with the windows, and it does that in world 
coordinates.

This is a bit of a design error -- It would be better if the Canvas told 
each object to draw, and the object itself would figure out whether to 
draw or not, so you could have objects that would always be drawn.

You can't simple make the bounding box of your object huge, as the 
bounding box is also used to determine the global bounding box (used for 
zoom_to_fit, etc).

However for your use case, if you know the bounds of your map ahead of 
time, you could set the BoundingBox of your object to the full extent 
you need, then it would always have its _draw method called, and I think 
your trick would work.

Another option is to make it a Grid object, and put it on the top of the 
canvas with:

Canvas.GridOver = Grid

That feature is there so that you can draw a grid (or graticule) over 
everything else, and it will always get drawn, without a bounding box 
check. This isn't a grid, but it should work for you use case also. All 
you need is an object with a _Draw method:

def _Draw(self, dc, Canvas):
     do some drawing...


You've got the Canvas object, so you can get other attributes you may 
need, like Canvas.

I've enclosed and example of that approach, along with the bitmap it needs.

Vitor Bosshard wrote:
> The canvas has PixelToWorld and WorldToPixel conversion functions.
> 
> So, having your fixed pixel coords, you can just redraw your objects
 > at the recalculated world coords whenever you pan or zoom.

I don't think the events are in place to be able to do that at the right 
time.

-Chris

-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[email protected]
_______________________________________________
FloatCanvas mailing list
[email protected]
http://paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to