Mapsui: How to get Coordinates of an image Point?

Created on 5 May 2016  路  1Comment  路  Source: Mapsui/Mapsui

I'm using Viewport.ScreenToWorld() but I don't understand the return. How I can return Lat/Lon given a mouse image position?

Most helpful comment

There are two kind of transformations.

  1. Transforming between screen and world coordinates
    The screen coordinates are in the units of your screen (usually pixels). The world coordinates are in the coordinate system of your map (usually SphericalMercator).
  2. Transforming between different coordinate systems
    Lat/Lon is such a coordinate system (EPSG:4326). Google Maps and OpenStreetMap are using another coordinate system called SphericalMercator (EPSG:3857). These kind of transformation (or projections) can be complicated. Usually this is done with a projection library.

If you are using OpenStreetMap as your background ScreenToWorld will return coordinates in EPSG:3857. So you need to transform this to EPSG:4326. For this one scenario (and no other) there is a helper utility in Mapsui which is called SphericalMercator. You can use it like this:

var lonLat = Mapsui.Projection.SphericalMercator.ToLonLat(worldCoordinate);

For other kind of projections you need to attach a projection library to Map.Transformation. You have to find yourself a projection library, like this one, and wrap it in an ITransformation implementation.

>All comments

There are two kind of transformations.

  1. Transforming between screen and world coordinates
    The screen coordinates are in the units of your screen (usually pixels). The world coordinates are in the coordinate system of your map (usually SphericalMercator).
  2. Transforming between different coordinate systems
    Lat/Lon is such a coordinate system (EPSG:4326). Google Maps and OpenStreetMap are using another coordinate system called SphericalMercator (EPSG:3857). These kind of transformation (or projections) can be complicated. Usually this is done with a projection library.

If you are using OpenStreetMap as your background ScreenToWorld will return coordinates in EPSG:3857. So you need to transform this to EPSG:4326. For this one scenario (and no other) there is a helper utility in Mapsui which is called SphericalMercator. You can use it like this:

var lonLat = Mapsui.Projection.SphericalMercator.ToLonLat(worldCoordinate);

For other kind of projections you need to attach a projection library to Map.Transformation. You have to find yourself a projection library, like this one, and wrap it in an ITransformation implementation.

Was this page helpful?
0 / 5 - 0 ratings