转换为mapbox传单中的像素

转换为mapbox传单中的像素

本文介绍了如何将半径(以米为单位)转换为mapbox传单中的像素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,我试图在地图上运行一些算法并计算坐标,但它们略有偏差,因为我在纬度和经度上运行计算,最终结果变得扭曲。

I am working on an application where I am trying to run some algorithms on a map and calculate coords but they are slightly off because I am running the calculations on latitude and longitudes and the final results are getting distorted.

现在我正在尝试将所有坐标转换为EPSG3857 Web Mercator坐标,如下所示:

Now I am trying to convert all coordinates to EPSG3857 Web Mercator coordinates like so:

var crs = L.CRS.EPSG3857;
var zoom = terrainAnalysisMap.getZoom();

markerToPoint = crs.latLngToPoint(marker.getLatLng(), zoom);
markerOnRadiusToPoint = crs.latLngToPoint(markerOnRadius.getLatLng(), zoom);

现在我还有一个半径,我必须将其从米转换为像素,但我无法弄清楚怎么样。 1米像素多少钱?我的意思是它也取决于缩放级别,对吗?那么如何在mapbox和leaflet中将半径转换为像素?

Now I also have a radius which I will have to convert from metres to pixels but I cannot figure out how. How much is 1 metre in pixels? I mean it would depend on the zoom level too, right? So how to go about converting radius to pixels in mapbox and leaflet?

推荐答案

如果你碰巧有这个地方的纬度如果您希望将半径转换为像素,可以使用的。这是我的javascript实现:

If you happen to have the latitude of the place where you are looking to convert the radius to pixels, you can make use of the "Meters per pixel" function described at http://wiki.openstreetmap.org/wiki/Zoom_levels. Here's my javascript implementation:

var metersPerPixel = function(latitude, zoomLevel) {
  var earthCircumference = 40075017;
  var latitudeRadians = latitude * (Math.PI/180);
  return earthCircumference * Math.cos(latitudeRadians) / Math.pow(2, zoomLevel + 8);
};

var pixelValue = function(latitude, meters, zoomLevel) {
  return meters / metersPerPixel(latitude, zoomLevel);
};

这篇关于如何将半径(以米为单位)转换为mapbox传单中的像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 02:23