Re: create a zoom event

From: Adrian Lumsden <Adrian.Lumsden@sss.co.nz>
Date: Tue Feb 12 2002 - 17:43:17 EST

Sorry. The formatting of the code example got mashed by Outlook wrapping it.

I've appended it to this to make it easier to read.

regards,

Adrian

-----Original Message-----
From: Adrian Lumsden [mailto:Adrian.Lumsden@sss.co.nz]
Sent: Wednesday, 13 February 2002 11:08
To: openmap-users@bbn.com
Subject: Re: create a zoom event

Good Morning,

The following might help you.

I have a ZoomMouseMode which extends CoordMouseMode. It overrides the mouseClicked
handler to provide support for zooming in (left click) and zooming out (right click).

My code gets the click position (x,y) and goes through the projection to get lat, lon
and then uses that as the new map centre. The map is zoomed in or out by a factor of
two. Both these operations are carried out on the projection and then the projection
is set into the bean. This avoids the need for the bean to redraw itself twice.

Knowing the centre and the scale will allow you to zomm to where you want.
Alternatively there's some useful code in NavMouseMode.java that handles zooming
into a rectangle that is selected by the user.

public void mouseClicked(MouseEvent e) { //////////////////////////// mouseClicked()
                                                                   //
    Object obj = e.getSource(); // Get source of click
    if (! mouseSupport.fireMapMouseClicked(e)) { //
        if (!(obj instanceof MapBean)) // If not from MapBean
            return; // then return
        MapBean map = (MapBean)obj; // Get as MapBean
        Projection projection = map.getProjection(); // Get projection
        Proj p = (Proj)projection; // Cast to Proj
        LatLonPoint llp = p.inverse(e.getPoint()); // Get click point -> lat,lon
        p.setCenter(llp); // Centre map on this point
        if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) // If left button click
            p.setScale(map.getScale() * 0.5f); // zoom in
        else // Else other button click
            p.setScale(map.getScale() * 2.0f); // zoom out
        map.setProjection(p); // Set map to new projection
        } //
    return; //
                                                                   //
    } /////////////////////////////////////////////////////////////// End of mouseClicked()

best regards,

Adrian

- -------------------------------------------
Adrian Lumsden Product Specialist
Scientific Software and Systems Limited

DDI: +64 4 917-6680
Tel: +64 4 917-6670
Fax: +64 4 917-6671
E-mail: Adrian.Lumsden@spam.trap.sss.co.nz

Visit us on the Web at: http://www.sss.co.nz
_____________________________________________

This e-mail passed SSS's content security scan.
It is covered by the confidentiality clauses at
http://www.sss.co.nz/content_and_confidentiality

-----Original Message-----
From: owner-openmap-users@bbn.com [mailto:owner-openmap-users@bbn.com]On
Behalf Of Marklund David
Sent: Wednesday, 13 February 2002 03:11
To: 'openmap-users@bbn.com'
Subject: create a zoom event

Hi all,
I have a sweden map in my mapBean. When the user starts my application I
want them to see the whole
map for a few seconds, and then automatically zoom in to my area of
interest. I know how to create
threads to solve the waiting part, but how can I zoom in to a area for which
I know the geographical extent
in lat/long (south-west and north-east corner) ?

I have looked at the zoom-method but can not really understand how to use
it.

cheers

David

--
[To unsubscribe to this list send an email to "majdart@bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]

--
[To unsubscribe to this list send an email to "majdart@bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Tue Feb 12 17:42:05 2002

This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:32 EDT