开发者

Using the SharpMap library to generate a Google Maps overlay

开发者 https://www.devze.com 2022-12-09 04:31 出处:网络
I wish to dynami开发者_高级运维cally generate a Google Maps overlay, that will consist of a single transparent GIF/PNG image with multiple dots on various locations.

I wish to dynami开发者_高级运维cally generate a Google Maps overlay, that will consist of a single transparent GIF/PNG image with multiple dots on various locations.

There will be a large quantity of dots and if I use normal markers, the performance will be unacceptable.

I came across the SharpMap library and it looks like an excellent, comprehensive library for dealing with maps.

Problem is, it's also very big and I'm not sure where to begin.

For starters I don't think I need to use the whole framework, and I may not even need to instantiate a 'Map' object.

All I need to do is convert a collection of latitude/longitude co-ordinates into a collection of pixel co-ordinates, given the current zoom level and the size of the viewport (which is fixed).

Can anyone who's had experience with SharpMap point me in the direction of what classes/namespaces I could/should be using to get this done?


Found an article somewhat related to this, but applied to Google Earth rather than the Maps API.

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

Trying to get the sample working.


I use the following class to convert from lat/long to 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);
    }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号