[OpenMap Users] AbstractMouseMode contribution

From: Stéphane Wasserhardt <swasserhardt_at_cls.fr>
Date: Wed, 21 Feb 2007 12:12:26 +0100
Hello !

Here is a very simple addition to AbstractMouseMode.
It doesn't change anything in it's current state. You must set AbstractMouseMode.mouseWheelCenters to true if you want to activate the modification.
When set to true, this only change the way AbstractMouseMode handles mouseWheelEvents : instead of simply zooming in, mouse wheel negative rotations also center the projection towards the mouse location.

For instance, if the current projection is centered on location A, and the mouse pointer is on location B, if you zoom in using the mouse wheel, the projection's center will be moved towards location B (at a constant rate : WHEEL_CENTERING_PERCENTS percents of the distance between A and B).

I think this simple feature can be usefull for most openMap applications. Any feedbacks are welcome :-)


PS : Added code is below (complete modified file is attached) :

     * Set this value to <code>true</code> in order to have the mapBean centered on mouse position each time
     * the mouseWheel is used for zooming.<br>
     * TODO This should be part of "Environment" or another general configuration.
    public static transient boolean mouseWheelCenters = false;
     * When <code>mouseWheelCenters</code> is set to <code>true</code>, this constant indicates how much
     * the projection's center is moved towards the mouse location in percent of the distance between the
     * current projection's center and the mouse location.
    public static final transient int WHEEL_CENTERING_PERCENTS = 15;
private static final transient float WHEEL_CENTERING_RATIO = WHEEL_CENTERING_PERCENTS / 100f;

     * Invoked from the MouseWheelListener interface.
    public void mouseWheelMoved(MouseWheelEvent e) {
int rot = e.getWheelRotation();
if (e.getSource() instanceof MapBean) {
            MapBean mb = (MapBean) e.getSource();
if (rot > 0) {
// Positive, zoom out
                mb.zoom(new ZoomEvent(mb, ZoomEvent.RELATIVE, 1.1f));
else {
                // When zooming in, if mouseWheelCenters mode is set ...
                if (mouseWheelCenters) {
// The projection's center is moved by WHEEL_CENTERING_PERCENTS percents of the distance
                    // to the mouse's location.
                    Projection projection = mb.getProjection();

float centerX = projection.getWidth() / 2f;
float centerY = projection.getHeight() / 2f;
int newX = Math.round(centerX + (e.getX() - centerX) * WHEEL_CENTERING_RATIO);
int newY = Math.round(centerY + (e.getY() - centerY) * WHEEL_CENTERING_RATIO);
                    LatLonPoint llp = projection.inverse(newX, newY);
new CenterEvent(mb, llp.getLatitude(), llp.getLongitude()));

                mb.zoom(new ZoomEvent(mb, ZoomEvent.RELATIVE, .9f));

[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Wed Feb 21 2007 - 06:13:56 EST

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:08 EDT