Using SharpMap Library to Create Google Maps Overlay

I want to dynamically create a Google Maps overlay that will consist of one transparent GIF / PNG image with multiple dots in different locations.

There will be a lot of points and if I use regular markers the performance will be unacceptable.

I came across the SharpMap library and it looks like a great, comprehensive library for working with maps.

The problem is that it is also very big and I'm not sure where to start.

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

All I have to do is convert the latitude / longitude coordinate collection to a pixel coordinate collection, given the current zoom level and viewport size (which is fixed).

Can anyone who has experience with SharpMap point me in the direction of which classes / namespaces I could / should use to do this?


Found an article related to this but applied to Google Earth and not 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 to work.

+2


source to share


1 answer


I am using 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);
    }

}

      

+2


source







All Articles