JMapViewer,获取OSM地图比例,Java

时间:2016-09-08 23:24:56

标签: java scale jmapviewer

在我的Java应用程序中,我正在使用JmapViewer;地图绘制在jPanel上。是否可以获得与当前缩放级别相对应的地图比例?该地图基于众所周知的墨卡托投影:

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

投影是共形的,因此局部线性标度与方向无关。我的想法使用两个共享相同并行的点:

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

改进:初始点p1可能是视图的中心。

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

以米为单位评估像素坐标""公式缺少像素大小...

1 个答案:

答案 0 :(得分:3)

JMapViewer方法getMeterPerPixel()返回当前缩放级别的每像素的米数。它使用CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); // Create the blob client. CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve reference to a previously created container. CloudBlobContainer container = blobClient.GetContainerReference("agentdocuments"); foreach (var doc in expiredDocs) { if (doc.ContentLength == 1) { // Retrieve reference to blob CloudBlockBlob blockBlob = container.GetBlockBlobReference($"{doc.SubDomain.ToLower()}/{doc.ClientId}/{doc.FileId}"); await blockBlob.DeleteIfExistsAsync(); } } ,"使用spherical law of cosines获取距离。"在TileSource::getDistance中,您可以看到值与缩放的反转方式;等级10和98.5米/像素如下所示。有关典型实施,请参阅org.openstreetmap.gui.jmapviewer.Demo

map image