views:

107

answers:

2

Hi,

Im having little trouble finding a relation between the movement at centre and edge of a circle, Im doing for panning world map,my map extent is 180,89:-180,-89, my map pans by adding change(dx,dY) to its extents and not its centre. Now a situation has arrrised where I have to move the map to a specific centre, to calculate the change in longitudes is very easy and simple, but its the change in lattitudes that has caused problem. It seems the change in centreY of map is more than the change at edge of the mapY, or simply if I have to move the map centre from 0long,0lat to 73long,33lat, for dX I simply get 73, but for dY apparently it looks 33 but if i add 33 to top of map that is 89 , it will be 122 which is incorrect since Latitudes are between 90 and -90 . It seems a case a projection of a circle on 2D plane where the edge of circle since is moving backward due to angle expereinces less change and the centre expereinces more change, now is there a relation between these two factors? I tried converting the difference between OriginY and destinationY into radians and then add to Top and Bottom of Map, but it did'nt really work for me. Please note that the map is project on a virtual canvas whose width starts from 256 and increases by 256*2^z , z=0 is default and whole world is visible at that extent of canvas

public void moveMapTo(double destinationLongitude,double destinationLattitude) // moves map to the new centre
        {
            double dXLong=destinationLongitude-centreLongitude; // centreLongitude and centreLattitude are centre of current map position
            double atanhsinO = atanh(Math.sin(destinationLattitude * Math.PI / 180.00));
            double atanhsinD = atanh(Math.sin(centreLatitude * Math.PI / 180.00));
            double atanhCentre = (atanhsinD + atanhsinO) / 2;
            double latitudeSpan =destinationLattitude - centreLatitude;
            double radianOfCentreLatitude = Math.atan(Math.sinh(atanhCentre));
            double dXLat=latitudeSpan / Math.cos(radianOfCentreLatitude);
            dXLat*=getLattitudeSpan()*(Math.PI/180); //<--- HERE IS THE PORBLEM

            System.out.println("dxLong:"+dXLong+"_dxLat:"+dXLat);
    //map left.right.top,bottom are current extents of map
            mapLeft+=dXLong;
            mapRight+=dXLong;
                         mapTop+=dXLat;
            mapBottom+=dXLat;




    }
    private double getLattitudeSpan()
    {

            double latitudeSpan = mapTop - mapBottom;
            latitudeSpan = latitudeSpan / Math.cos(radianOfCentreLatitude);
            return Math.abs(latitudeSpan);

    } 
A: 
Mike Cialowicz
Ok thanks for the idea but I`m using simple WGS84 Datum Geographical Projection, the equal area projection seems great but the problem comes when you do tranformation between world and screen coordinates
Imran
+1  A: 

I solved a similar problem a while back and may be able to give you some hints.

Panning in all 4 directions by adding a scaled longitude or latitude only works for a Mercator projection; is this what you have? If so, good.

To pan north and south, I think the only thing you can do is show a white (empty) background north of the pole if you've panned north; i.e. you show less of the map.

To pan east and west, you have to replace the part of the world that's gone offscreen with the wrapped-around edge of the opposite side.

I've found that my code becomes very simple if I create a map like this:

ws ws ws ws ws ws ws ws
eu po PO NA EU PO po na
af po PO SA AF PO po sa
ws ws ws ws ws ws ws ws

The central part, in uppercase letters, is your original world map: NA, SA, EU and AF stand for North America, South America, Europe and Africa, respectively (grossly simplified map here). PO is the Pacific Ocean. Around that original map I've stitched another copy of the map horizontally and white space (ws) vertically.

Initially, your view is centered at 0/0, i.e. between NA/SA and EU/AF, and clipped to show you 90° north and south and east and west from there, for a total of 180° in both directions. From there, you can pan up to 180° east or west and still see the same amount of the world. You can, for example pan 180° east to the International Date Line (in the Pacific) and see Europe and Africa to the left and North/South America on the right.

You can also pan up and down by 90°. Since wrapping around wouldn't make any sense here, part of your view will then be white space.

The downside to this is that your map image will be about twice as big in compressed file size and four times as big in pixel size. You could achieve the same effect by stitching in code, but using the super-sized world map is a fair bit easier.

Carl Smotricz
my panning works like this : say for horizontal : extentVirtual.mapLeft-=extentVirtual.currentSpanLong/100)*0.75; extentVirtual.mapRight-=((extentVirtual.currentSpanLong/100)*0.75); for vertical:extentVirtual.mapTop-=(extentVirtual.currentSpanLat/100)*0.75; extentVirtual.mapBottom-=((extentVirtual.currentSpanLat/100)*0.75); as you can see the extents move some percent of the span of the current view
Imran