开发者

How to find relation between change in latitudes at centre of map and top/bottom

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);

    } 


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.


This will depend greatly on the map projection of your original earth image. Without knowing the particular projection you're using, it's impossible to produce and equation which maps x-y pixel distances on your image to lat-long numbers (and vice-versa).

If you use an equal-area projection, like the Gall-Peters, then you will save yourself a great deal of time and fiddling since there are no equations to apply: pixel distances will relate linearly to lat-long numbers.

Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜