[Thuban-devel] scaling

Bernhard Herzog bh at intevation.de
Tue Jan 11 19:25:26 CET 2005


Russell Nelson <nelson at crynwr.com> writes:

> --- Thuban/Model/map.py	10 Jul 2003 14:53:15 -0000	1.18
> +++ Thuban/Model/map.py	11 Jan 2005 05:21:41 -0000
> @@ -170,6 +170,13 @@
>              self.changed(MAP_LAYERS_CHANGED, self)
>              self.changed(MAP_STACKING_CHANGED, self)
>  
> +    def AdjustScale(self, scale):
> +        """Adjust the scale of the map as requested by any layer."""
> +
> +        for layer in self.layers:
> +            scale = layer.AdjustScale(scale)
> +        return scale

If multiple layers want to adjust the scale the ones later in the list
only see the already adjusted scale.  Is that really the right approach?
I would have expected that all layers would base their adjustments on
the same initial scale.  If only one layer returns a different one or if
all layers that return a different one return the same one, that one
would be taken.  How to proceed if the layers that want a different
scale don't agree, I don't know.

Some test cases that check these different cases would be very useful
here.  

Thinking more about this, I think the AdjustScale method should work
differently.  It should be more like:

   def PreferredScale(self, scale):
       """Return a preferred scale factor near scale

       The default implementation simply returns None indicating that
       all scales are acceptable.  Derived classes can override this
       method to return a scale value they would prefer for their data.
       The new scale value should be near the given scale value.  The
       actual scale used to draw the layer may still not be the
       preferred scale, though.
       """

The reason is that that the simple approach outlined above doesn't
handle all situations well, even if only one layer returns a different
scale.  For instance you have two layers, one preferring scale1 and the
other scale2.  Say the actual scale to be used is scale1.  Then you will
only get one different scale, so the new scale will be scale2.  Then you
move the map with the pan tool so the scale should stay the same.  The
map's AdjustScale method is called with scale2 and now the adjusted
scale will be scale1!

> --- Thuban/UI/viewport.py	18 Nov 2004 20:17:43 -0000	1.19
> +++ Thuban/UI/viewport.py	11 Jan 2005 05:21:44 -0000
> @@ -410,7 +410,8 @@
>          elif scale < min_scale:
>              scale = min_scale
>  
> -        self.scale = scale
> +        # give the layers a chance to pick a better scale.
> +        self.scale = self.map.AdjustScale(scale)

I think this adjustment should be made before the scale is clamped to
the min/max scale.  The scale limits are there for a reason.  If you
zoom in too much, for instance, you can easily get rendering errors.


On the whole, I think this scale adjustment needs more thought before it
goes into CVS.

   Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Skencil                                           http://skencil.org/
Thuban                                  http://thuban.intevation.org/




More information about the Thuban-devel mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)