Mouse Wheel Event

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Mouse Wheel Event

Pablo Echenique
Hello everyone:

I'm trying to active the mouseWheel event to make zoom in / out into a
map (JMapPane).  I mean when a user move the mouse's wheel into a
jMapPane the zoom in /out event automatically takes place.

Can someone help me? Any example or code.

Greetings!!!!

------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|

Re: Mouse Wheel Event

mbedward
Perhaps the easiest way of doing it, without sub-classing JMapPane, is
something like this...

    // somewhere in your code...
    double clickToZoom = 0.1;  // 1 wheel click is 10% zoom

    // wheel event handler
    public void handleMouseWheelEvent(MouseWheelEvent ev) {
        int clicks = ev.getWheelRotation();
        // -ve means wheel moved up, +ve means down
        int sign = (clicks < 0 ? -1 : 1);

        Envelope env = mapPane.getMapArea();
        double width = env.getWidth();
        double delta = width * clickToZoom * sign;

        env.expandBy(delta);
        mapPane.setMapArea(env);
        mapPane.repaint();
    }


Warning: I can't test this because I don't have a mouse wheel :-)

Michael

------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|

Re: Mouse Wheel Event

jody.garnett
Thanks; once again added to the user guide:

I actually think we could set up a tool to respect mousewheel events; but have not looked at it.

On Thu, Feb 5, 2009 at 10:48 AM, Michael Bedward <[hidden email]> wrote:
Perhaps the easiest way of doing it, without sub-classing JMapPane, is
something like this...

   // somewhere in your code...
   double clickToZoom = 0.1;  // 1 wheel click is 10% zoom

   // wheel event handler
   public void handleMouseWheelEvent(MouseWheelEvent ev) {
       int clicks = ev.getWheelRotation();
       // -ve means wheel moved up, +ve means down
       int sign = (clicks < 0 ? -1 : 1);

       Envelope env = mapPane.getMapArea();
       double width = env.getWidth();
       double delta = width * clickToZoom * sign;

       env.expandBy(delta);
       mapPane.setMapArea(env);
       mapPane.repaint();
   }


Warning: I can't test this because I don't have a mouse wheel :-)

Michael

------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users


------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|

Re: Mouse Wheel Event

mbedward
Cool - thanks Jody.

Yep, a mouse wheel tool sounds like a good idea...

Since posting that I also thought I'd hack my local JMapPane to get
the same behaviour with up and down arrow key strokes... actually '+'
and '-' would probably be better.  Also the class is crying out for a
method to set the zoom factor.

I suspect there are a few people who, like me, have a locally modified
version of JMapPane.  The class still seems to be used a lot judging
by messages here, while there are very few mentions of Johann's
'pending' classes.  I know at some stage there is meant to be a
beautiful new rendering system but in the meantime perhaps it would be
useful to do some housekeeping and tweaks of the JMapPane code.  Ian's
last commit was mid-2007.

Michael

2009/2/16 Jody Garnett <[hidden email]>:

> Thanks; once again added to the user guide:
> - http://docs.codehaus.org/display/GEOTDOC/MapPane
> I actually think we could set up a tool to respect mousewheel events; but
> have not looked at it.
>
> On Thu, Feb 5, 2009 at 10:48 AM, Michael Bedward <[hidden email]>
> wrote:
>>
>> Perhaps the easiest way of doing it, without sub-classing JMapPane, is
>> something like this...
>>
>>    // somewhere in your code...
>>    double clickToZoom = 0.1;  // 1 wheel click is 10% zoom
>>
>>    // wheel event handler
>>    public void handleMouseWheelEvent(MouseWheelEvent ev) {
>>        int clicks = ev.getWheelRotation();
>>        // -ve means wheel moved up, +ve means down
>>        int sign = (clicks < 0 ? -1 : 1);
>>
>>        Envelope env = mapPane.getMapArea();
>>        double width = env.getWidth();
>>        double delta = width * clickToZoom * sign;
>>
>>        env.expandBy(delta);
>>        mapPane.setMapArea(env);
>>        mapPane.repaint();
>>    }
>>
>>
>> Warning: I can't test this because I don't have a mouse wheel :-)
>>
>> Michael
>>
>>
>> ------------------------------------------------------------------------------
>> Create and Deploy Rich Internet Apps outside the browser with
>> Adobe(R)AIR(TM)
>> software. With Adobe AIR, Ajax developers can use existing skills and code
>> to
>> build responsive, highly engaging applications that combine the power of
>> local
>> resources and data with the reach of the web. Download the Adobe AIR SDK
>> and
>> Ajax docs to start building applications
>> today-http://p.sf.net/sfu/adobe-com
>> _______________________________________________
>> Geotools-gt2-users mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
>

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Reply | Threaded
Open this post in threaded view
|

Re: Mouse Wheel Event

jody.garnett
Actually *lots* of people have locally modified copies - I keep encouraging the user community to come forward and share (in the hopes of getting a better example).

You do have commit access; feel free to add to that class (and rename the reset method) as needed.

Jody

On Mon, Feb 16, 2009 at 10:43 AM, Michael Bedward <[hidden email]> wrote:
Cool - thanks Jody.

Yep, a mouse wheel tool sounds like a good idea...

Since posting that I also thought I'd hack my local JMapPane to get
the same behaviour with up and down arrow key strokes... actually '+'
and '-' would probably be better.  Also the class is crying out for a
method to set the zoom factor.

I suspect there are a few people who, like me, have a locally modified
version of JMapPane.  The class still seems to be used a lot judging
by messages here, while there are very few mentions of Johann's
'pending' classes.  I know at some stage there is meant to be a
beautiful new rendering system but in the meantime perhaps it would be
useful to do some housekeeping and tweaks of the JMapPane code.  Ian's
last commit was mid-2007.

Michael

2009/2/16 Jody Garnett <[hidden email]>:
> Thanks; once again added to the user guide:
> - http://docs.codehaus.org/display/GEOTDOC/MapPane
> I actually think we could set up a tool to respect mousewheel events; but
> have not looked at it.
>
> On Thu, Feb 5, 2009 at 10:48 AM, Michael Bedward <[hidden email]>
> wrote:
>>
>> Perhaps the easiest way of doing it, without sub-classing JMapPane, is
>> something like this...
>>
>>    // somewhere in your code...
>>    double clickToZoom = 0.1;  // 1 wheel click is 10% zoom
>>
>>    // wheel event handler
>>    public void handleMouseWheelEvent(MouseWheelEvent ev) {
>>        int clicks = ev.getWheelRotation();
>>        // -ve means wheel moved up, +ve means down
>>        int sign = (clicks < 0 ? -1 : 1);
>>
>>        Envelope env = mapPane.getMapArea();
>>        double width = env.getWidth();
>>        double delta = width * clickToZoom * sign;
>>
>>        env.expandBy(delta);
>>        mapPane.setMapArea(env);
>>        mapPane.repaint();
>>    }
>>
>>
>> Warning: I can't test this because I don't have a mouse wheel :-)
>>
>> Michael
>>
>>
>> ------------------------------------------------------------------------------
>> Create and Deploy Rich Internet Apps outside the browser with
>> Adobe(R)AIR(TM)
>> software. With Adobe AIR, Ajax developers can use existing skills and code
>> to
>> build responsive, highly engaging applications that combine the power of
>> local
>> resources and data with the reach of the web. Download the Adobe AIR SDK
>> and
>> Ajax docs to start building applications
>> today-http://p.sf.net/sfu/adobe-com
>> _______________________________________________
>> Geotools-gt2-users mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
>

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users


------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users