Re: [OpenMap Users] Dragging the Map

From: Philip Oliver-Paull <oliverpa_at_seis.sc.edu>
Date: Thu, 08 Sep 2005 21:09:05 -0400

I've done this before. Shapefile data disappears while dragging, but
the symbols drag smoothly. I'm not sure how convenient it would be to
you since it does that...

Basically, you need to make a MapMouseMode that is something along these
lines:
         

        private int[] startXYCoords;
        private int[] endXYCoords;
        private int[] centerXYCoords;

        public void mousePressed(MouseEvent e){
                if (isActive()){
                        super.mousePressed(e);
                        startXYCoords = new int[]{e.getX(), e.getY()};
                }
        }
        
        public void mouseDragged(MouseEvent e){
                if (isActive()){
                        translate(e);
                        startXYCoords = endXYCoords;
                }
        }
        
        public void mouseReleased(MouseEvent e){
                if (isActive()){
                        super.mouseReleased(e);
                        translate(e);
                }
        }
        
        private void translate(MouseEvent e){
                Proj proj = (Proj)openMap.getMapBean().getProjection();
                endXYCoords = new int[]{e.getX(), e.getY()};
                int[] diff = new int[]{endXYCoords[0] - startXYCoords[0], endXYCoords[1] - startXYCoords[1]};
                centerXYCoords = new int[]{proj.getWidth()/2 - diff[0], proj.getHeight()/2 - diff[1]};
                openMap.getMapBean().setCenter(proj.inverse(centerXYCoords[0], centerXYCoords[1]));
        }

There may be a more efficient way of doing it. I never really tried to
optimize it.

Hope this helps,
Philip

Klawetter, DG Darol (6274) _at_ IS wrote:

>Has anyone used Openmap to create a map that can be smoothly dragged. I
>would like to move the mouse cursor to a point on the map and then drag the
>map until its centered to the desired point. For example, Google Maps allows
>the user to do this and it's to be very convenient.
>
>Thanks,
>
>Darol
>
>--
>[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"]
>
>

--
[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 Thu Sep 08 2005 - 21:55:56 EDT

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