简体   繁体   English

JMapViewer,获取OSM地图比例,Java

[英]JMapViewer, get the OSM map scale, Java

In my Java application I am using JmapViewer; 在我的Java应用程序中,我使用的是JmapViewer; the map is drawn on the jPanel. 地图绘制在jPanel上。 Is it possible to get the map scale corresponding to the current zoom level? 是否可以获得与当前缩放级别相对应的地图比例? The map is based on the well-known Mercator projection: 该地图基于众所周知的墨卡托投影:

X = R * lon * cos(lat1);
Y = R * log(tan(lat/2 + 45)), lat1 = 0;

The projection is conformal, so the local linear scale is independent of the direction. 投影是共形的,因此局部线性标度与方向无关。 My idea uses two points sharing the same parallel: 我的想法使用两个点共享相同的并行:

 Point p1 = new Point(0,0);
 Point p2 = new Point(100,0);

 final double dlon = getPosition(p2).getLon() - getPosition(p1).getLon();
 final double scale = 6380000 * abs(dlon) * PI / 180 / 100;  //scale = (R * dlon)/||p1-p2||

An improvement: the initial point p1 may be a center of the view. 改进:初始点p1可以是视图的中心。

Point p1 = new Point(jPanel1.width()/2,jPanel1.height()/2);
Point p2 = new Point(jPanel1.width()/2  + 100, jPanel1.height()/2);

The pixel coordinates are evaluated "in meters"; 像素坐标以“米为单位”进行评估; the formula lacks the pixel size... 公式缺少像素大小......

The JMapViewer method getMeterPerPixel() returns the number of meters per pixel at the current zoom level. JMapViewer方法getMeterPerPixel()返回当前缩放级别的每像素的米数。 It uses TileSource::getDistance , which "Gets the distance using the spherical law of cosines ." 它使用TileSource::getDistance ,“使用余弦球面定律获取距离”。 In org.openstreetmap.gui.jmapviewer.Demo , you can see how the value varies inversely with the zoom; org.openstreetmap.gui.jmapviewer.Demo ,您可以看到值与缩放的反向变化; level 10 and 98.5 meters/pixel are shown below. 等级10和98.5米/像素如下所示。 See OsmMercator::getDistance for a typical implementation. 有关典型实现,请参阅OsmMercator::getDistance

地图图片

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM