How Do I Constrain the Maximum Extent Of an Image?
Hello Daniel,
is it possible to implement a constraint for a max extent of a picture or map. I think there could be a case where I wouldn't show the whole image to a user but only 2/3 of the pic.
In my case I would show several maps in a MultiScaleContainer and they have to be georeferenced, e.g. the upper left corner of the map is at a value of 48.197 for x and 11.4302 for y (lat,lon) or at values for UTM Coordinates. Therefore I think manual bounds are the best way to do this or do you know an other solution to my problem.
Thank you!
Cheers Mane
is it possible to implement a constraint for a max extent of a picture or map. I think there could be a case where I wouldn't show the whole image to a user but only 2/3 of the pic.
In my case I would show several maps in a MultiScaleContainer and they have to be georeferenced, e.g. the upper left corner of the map is at a value of 48.197 for x and 11.4302 for y (lat,lon) or at values for UTM Coordinates. Therefore I think manual bounds are the best way to do this or do you know an other solution to my problem.
Thank you!
Cheers Mane
1
person has this question
I have this question, too!
Tell me when someone answers.
The more people who ask this question, the more it gets noticed.
The more people who ask this question, the more it gets noticed.
The company marked this question as answered.
The best answer from the company
-
Mane,
I've tried what you're suggesting and it works! What's keeping you from implementing your own BoundsConstraint?
Any IViewport implementation you create receives the current transform of the viewport and you can manipulate it in any way you want, including limiting its bounds.
Give it a shot and let me know if you get stuck!
Cheers,
Daniel
I’m confident
The company says
this answers the question
-
Inappropriate?Mane,
Absolutely, this is exactly what IViewportConstraint was built for. Have you had a look at it? ZoomConstraint, ScaleConstraint & VisibilityConstraint are great candidates for studying!
Cheers,
Daniel
I’m confident
-
Inappropriate?Hello Daniel,
thanks again. I will have a closer look at constraints.
Mane -
Inappropriate?Hello Daniel,
I had a closer look at IViewportConstraint. What I miss is a possibility to limit the viewport to specific bounds on a bitmap, not only on a smaller or taller band around th pic what VisibilityConstraint does.
This has the advantage to slide the bounds of a viewport afterwards and you can also use one bitmap source for more implementations with different viewport extents.
This would advance the Constaintsettings. I imagine this like following lines:
//bitmap extents: e.g. 2000x1000
var rect:Rectangle = new Rectangle(100, 100, 200, 200);
var boundConstraint:BoundConstraint = new BoundConstraint()
boundConstraint.bounds = rect;
//with this constraint the viewport is limited to 100x100 px.
mapper always want to set boundaries :-)
Cheers,
Mane
I’m happy
-
Inappropriate?Mane,
I've tried what you're suggesting and it works! What's keeping you from implementing your own BoundsConstraint?
Any IViewport implementation you create receives the current transform of the viewport and you can manipulate it in any way you want, including limiting its bounds.
Give it a shot and let me know if you get stuck!
Cheers,
Daniel
I’m confident
The company says
this answers the question
-
Inappropriate?Hi,
I just implemented my own BoundConstraint. It is working if your Viewport Rect is inside of the Bound Rect, but I think this is how it schould work, because bounds have no sense if viewport is bigger than the bounds.
This is my BoundConstraint:
package org.openzoom.flash.viewport.constraints
{
import flash.geom.Rectangle;
import org.openzoom.flash.core.openzoom_internal;
import org.openzoom.flash.viewport.IViewportConstraint;
import org.openzoom.flash.viewport.IViewportTransform;
use namespace openzoom_internal;
/**
* Makes Bound to the IViewport
*/
public final class BoundConstraint implements IViewportConstraint
{
include "../../core/Version.as"
//--------------------------------------------------------------------------
//
// Class constants
//
//--------------------------------------------------------------------------
private static const DEFAULT_BOUNDS:Rectangle = new Rectangle(0, 0, 1, 1)
//--------------------------------------------------------------------------
//
// Constructor
//
//--------------------------------------------------------------------------
/**
* Constructor.
*/
public function BoundConstraint()
{
}
//----------------------------------
// Bounds
//----------------------------------
private var _bounds:Rectangle = DEFAULT_BOUNDS
/**
* Maximum bounds the Viewport can reach.
*/
public function get bounds():Rectangle
{
return _bounds
}
public function set bounds(value:Rectangle):void
{
_bounds = value
}
//--------------------------------------------------------------------------
//
// Methods: IViewportConstraint
//
//--------------------------------------------------------------------------
/**
* @inheritDoc
*/
public function validate(transform:IViewportTransform,
target:IViewportTransform):IViewportTransform
{
var viewportBounds:Rectangle = transform.getBounds()
var x:Number = viewportBounds.x // 0 //transform.x
var y:Number = viewportBounds.y //transform.y
//outside of bound
if (!bounds.containsRect(viewportBounds)) {
if (viewportBounds.left < bounds.left) {
// left bound
x = bounds.left
}
if (viewportBounds.top < bounds.top) {
// top bound
y = bounds.top
}
if (viewportBounds.right > bounds.right) {
// right bound
x = bounds.right - viewportBounds.width
}
if (viewportBounds.bottom > bounds.bottom) {
// bottom bound
y = bounds.bottom - viewportBounds.height
}
}
//inside of bounds
//if (bounds.containsRect(viewportBounds)) {
//trace("innen");
//
//x = viewportBounds.x
//y = viewportBounds.y
//}
// validate bounds
transform.panTo(x, y)
return transform
}
}
}
You have only to intit the bounds in the CompositeConstraint:
var constraint:CompositeConstraint = new CompositeConstraint();
var boundConstraint:BoundConstraint = new BoundConstraint();
bounds = new Rectangle(0.5312538146972657, 0.3466752370198569, 0.0026041666666666665, 0.001953125);
boundConstraint.bounds = bounds;
constraint.constraints = [zoomConstraint, scaleConstraint, centerConstraint, boundConstraint];
Cheers,
Mane
I’m happy
-
This reply was removed on 01/05/10.
see the change log
Loading Profile...




EMPLOYEE