如何找到地图中心纬度变化与顶部/底部纬度变化之间的关系
我在找到圆心和边缘的运动之间的关系方面没有什么困难,我正在平移世界地图,我的地图范围是180,89:-180,-89,我的地图通过向其范围而不是中心添加变化(dx,dY)来进行平移。现在出现了一种情况,我必须将地图移动到特定的中心,计算经度的变化非常容易和简单,但纬度的变化引起了问题。看来地图centerY的变化大于mapY边缘的变化,或者简单地说,如果我必须将地图中心从0long,0lat移动到73long,33lat,对于dX我只需得到73,但对于dY显然它看起来 33 但如果我将 33 添加到地图顶部(即 89 ),它将是 122 ,这是不正确的,因为纬度在 90 和 -90 之间。似乎是一个圆在 2D 平面上的投影,其中圆的边缘由于角度而向后移动,变化较小,而中心变化较大,现在这两个因素之间有关系吗?我尝试将 OriginY 和 destinationY 之间的差异转换为弧度,然后添加到地图的顶部和底部,但它对我来说并没有真正起作用。请注意,地图投影在虚拟画布上,其宽度从 256 开始并以 256*2^z 增加,默认情况下 z=0,整个世界在该画布范围内可见
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);
}
Im having little trouble finding a relation between the movement at centre and edge of a circle, I
m 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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不久前解决了类似的问题,也许可以给你一些提示。
通过添加缩放的经度或纬度在所有 4 个方向上平移仅适用于墨卡托投影;这是你拥有的吗?如果是这样,那就好。
要向北和向南平移,我认为如果您向北平移,您唯一能做的就是在极北显示一个白色(空)背景;即您显示的地图较少。
要向东和向西平移,您必须用另一侧的环绕边缘替换屏幕外的世界部分。
我发现如果我创建这样的地图,我的代码会变得非常简单:
中心部分(大写字母)是您原来的世界地图: NA、SA、EU 和 AF 分别代表北美、南美、欧洲和非洲,分别(这里是非常简化的地图)。 PO是太平洋。围绕原始地图,我水平缝合了地图的另一个副本,垂直缝合了空白 (ws)。
最初,您的视图以 0/0 为中心,即在 NA/SA 和 EU/AF 之间,并进行剪辑以向您显示从那里开始的南北和东西 90°,总共 180° 在两个方向上。从那里,您可以向东或向西平移 180°,仍然可以看到相同大小的世界。例如,您可以向东平移 180° 到国际日期变更线(位于太平洋),并在左侧看到欧洲和非洲,在右侧看到北美/南美。
您还可以上下平移 90°。由于环绕在这里没有任何意义,因此您的视图的一部分将是空白。
这样做的缺点是,您的地图图像的压缩文件大小大约是原来的两倍,像素大小大约是原来的四倍。您可以通过拼接代码来实现相同的效果,但使用超大世界地图要容易一些。
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:
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.
这在很大程度上取决于原始地球图像的地图投影。如果不知道您正在使用的特定投影,就不可能生成将图像上的 xy 像素距离映射为经纬度数字的方程(反之亦然)。
如果您使用 等面积 投影,例如 Gall-Peters,那么你会节省大量的时间和摆弄,因为有无需应用方程式:像素距离将与经纬度数字线性相关。
祝你好运!
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!