【问题标题】:Using the SharpMap library to generate a Google Maps overlay使用 SharpMap 库生成 Google 地图叠加层
【发布时间】:2010-12-08 13:39:35
【问题描述】:

我希望动态生成一个 Google 地图叠加层,它包含一个透明的 GIF/PNG 图像,在不同的位置有多个点。

会有大量的点,如果我使用普通标记,性能将无法接受。

我偶然发现了 SharpMap 库,它看起来是一个出色的综合性地图处理库。

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

对于初学者,我认为我不需要使用整个框架,甚至可能不需要实例化“地图”对象。

在给定当前缩放级别和视口大小(固定)的情况下,我需要做的就是将纬度/经度坐标集合转换为像素坐标集合。

任何有 SharpMap 经验的人都可以指出我可以/应该使用哪些类/命名空间来完成这项工作吗?


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

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

尝试让示例正常工作。

【问题讨论】:

    标签: c# google-maps mapping


    【解决方案1】:

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

    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);
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-20
      • 2020-10-05
      • 1970-01-01
      • 2013-09-24
      • 2011-11-06
      相关资源
      最近更新 更多