首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用SharpMap库生成Google覆盖

使用SharpMap库生成Google覆盖
EN

Stack Overflow用户
提问于 2009-10-21 01:21:45
回答 1查看 3.2K关注 0票数 4

我希望动态生成谷歌地图覆盖,这将包括一个单一的透明GIF/PNG图像与多个点在不同的位置。

会有大量的点,如果我使用正常的标记,表现将是不可接受的。

我偶然发现了SharpMap库,它看起来是一个处理地图的极好的、全面的库。

问题是,它也很大,我不知道从哪里开始。

首先,我不认为我需要使用整个框架,我甚至可能不需要实例化一个“Map”对象。

我所需要做的就是将一个纬度/经度坐标集合转换成一个像素坐标集合,考虑到当前的缩放级别和视口大小(这是固定的)。

有过SharpMap经验的人能为我指明我可以/应该使用哪些类/名称空间来完成这个任务吗?

找到了一篇与此相关的文章,但应用于Google,而不是Maps API。

http://web.archive.org/web/20080113140326/http://www.sharpgis.net/PermaLink,guid,f5bf2808-4cda-4f41-9ae5-98109efeb8b0.aspx

试着让样本正常工作。

EN

回答 1

Stack Overflow用户

发布于 2010-12-23 13:26:57

我使用以下类将lat/long转换为x/y:

代码语言:javascript
复制
public static class StaticMapHelper
{
    private const long offset = 268435456;
    private const double radius = offset / Math.PI;

    private static double LongitudeToX(double longitude)
    {
        return Math.Round(offset + radius * longitude * Math.PI / 180);
    }

    private static double LatitudeToY(double latitude)
    {
        return Math.Round(offset - radius * Math.Log((1 + Math.Sin(latitude * Math.PI / 180)) / (1 - Math.Sin(latitude * Math.PI / 180))) / 2);
    }

    private static double XToLongitude(double x)
    {
        return ((Math.Round(x) - offset) / radius) * 180 / Math.PI;
    }

    private static double YToLatitude(double y)
    {
        return (Math.PI / 2 - 2 * Math.Atan(Math.Exp((Math.Round(y) - offset) / radius))) * 180 / Math.PI;
    }

    public static GeoPoint XYToLongitudeLatitude(int offsetX, int offsetY, double centerLongitude, double centerLatitude, int googleZoom)
    {
        double zoom_factor = Math.Pow(2, 21 - googleZoom);
        double longitude = XToLongitude(LongitudeToX(centerLongitude) + (offsetX * zoom_factor));
        double latitude = YToLatitude(LatitudeToY(centerLatitude) + (offsetY * zoom_factor));
        return new GeoPoint(longitude, latitude);
    }

    public static GeoPoint LongitudeLatitudeToXY(int offsetX, int offsetY, double centerLongitude, double centerLatitude, int googleZoom)
    {
        double zoom_factor = Math.Pow(2, 21 - googleZoom);
        double x = (LongitudeToX(offsetX) - LongitudeToX(centerLongitude)) / zoom_factor;
        double y = (LatitudeToY(offsetY) - LatitudeToY(centerLatitude)) / zoom_factor;
        return new GeoPoint(x, y);
    }

}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1598268

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档