radioman / greatmaps

GMap.NET - Great Maps for Windows Forms & Presentation
912 stars 408 forks source link

How to get pixels to meter scaling #105

Open ludwigring opened 6 years ago

ludwigring commented 6 years ago

I'm trying to do some custom markers with visualization of standard deviation for position in meters. To do this I want to find the meters to pixel conversion to be able to draw a circle in the OnRender function.

I found the code below (Core.pxResX in particular) in the GMapControl and though I could use parts of it to calculate a Meter to pixel scale in my extended GMapControl but most parts were internal which limited me from doing it.

Have someone else tried to do something similar? Am I missing something obvious in how to do it (I can, but don't want to calculate it by checking the distance between two PointLatLng). If no-one has done this before could/should I update the GMapControl in the git repo with a meter to pixel property? if (MapScaleInfoEnabled) { if (Width > Core.pxRes5000km) { g.DrawRectangle(ScalePen, 10, 10, Core.pxRes5000km, 10); g.DrawString("5000Km", ScaleFont, Brushes.Blue, Core.pxRes5000km + 10, 11); }

Edit: After some more digging I found that it should be possible to do it via GetGroundResolution in the map provider double resolutionMetersToPixels = 1.0 / Overlay.Control.MapProvider.Projection.GetGroundResolution((int)Math.Round(Overlay.Control.Zoom), Position.Lat); But is there some better way? This means that each marker has to calculate the resolution which does not feel optimal if you have a lot of markers. On the other hand if you are zoomed out you will have some inaccuracies if you apply the same scaling on the entire image due to the world not being flat.

Best regards and thanks for a great map! /Ludwig