简体   繁体   English

如何将OSMSharp视点映射到地理坐标?

[英]How to map OSMSharp view point to Geo coordinate?

I am using OSMSharp for an iOS project. 我正在将OSMSharp用于iOS项目。

I'll like to be able to convert a given point in the view/map to GeoCoordinates (based on the current MapCenter, view size, zoom, etc). 我希望能够将视图/地图中的给定点转换为GeoCoordinates(基于当前的MapCenter,视图大小,缩放等)。

I thought mapView.Map.Project.ToGeoCoordinates would do that, but the result is not correct. 我以为mapView.Map.Project.ToGeoCoordinates可以做到,但是结果不正确。 The inverse function (mapView.Map.Project.ToPixel) returns values in a coordinate system that doesn't correspond to the actual view (it returns value up to 10000 or so, and the size of my view is 1024x768). 逆函数(mapView.Map.Project.ToPixel)在与实际视图不对应的坐标系中返回值(它返回的值最大为10000左右,并且我的视图的大小为1024x768)。

So, how do I convert a given pixel coordinate in a OsmSharp.iOS.UI.MapView to its corresponding GeoCoordinate?. 那么, 如何将OsmSharp.iOS.UI.MapView中的给定像素坐标转换为其对应的GeoCoordinate?

Right now there's no method to get it. 目前没有任何方法可以得到它。 But it's easy to get 但是很容易得到

Add below method to MapView class in OsmSharp.iOS.UI project 在OsmSharp.iOS.UI项目中的MapView类中添加以下方法

    public GeoCoordinate PointToCoordinate(int PointX, int PointY)
    {
        View2D view = _cacheRenderer.Create(this.Width, this.Height, this.Map,
               (float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter, false, true);

        // get scene coordinates.
        double x, y;
        var fromMatrix = view.CreateFromViewPort(this.Width, this.Height);
        fromMatrix.Apply(PointX, PointY, out x, out y);

        return this.Map.Projection.ToGeoCoordinates(x, y);
    }

If you want the Point from Geocoordinate, add below method to the same class 如果要从地理坐标指向点,请将以下方法添加到同一类

    public Point CoordinateToPoint(GeoCoordinate gc)
    {
        var gcPx = this.Map.Projection.ToPixel(gc);
        View2D view = _cacheRenderer.Create(this.Width, this.Height, this.Map,
               (float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter, false, true);

        // get scene coordinates.
        double x, y;
        var fromMatrix = view.CreateFromViewPort(this.Width, this.Height);
        fromMatrix.Remove(gcPx[0], gcPx[1], out x, out y);

        return new Point((int)System.Math.Round(x, 0), (int)System.Math.Round(y, 0));
    }

And below method to Matrix2D class in OsmSharp.UI.Renderer project 以及OsmSharp.UI.Renderer项目中Matrix2D类的以下方法

    public void Remove(double x, double y, out double xNew, out double yNew)
    {
        xNew = (x * this.E11 - this.E02 * this.E11 + this.E01 * this.E12 - this.E01 * y) / (this.E00 * this.E11 - this.E01 * this.E10);
        yNew = (y - this.E12 - this.E10 * xNew) / this.E11;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用故事板给出位置坐标以在ios中绘制地图中的点? - How to give a location coordinate to plot a point in a map in ios using storyboard? 如何在 Swift 中确定窗口坐标系中的点是否在视图内 - How to determine if a point in the window's coordinate system is within a view, in Swift 将坐标点转换为视点的问题 - issues converting coordinate point to view point 在地图视图中的同一坐标中查找批注的数量 - Finding numbers of annotation in same coordinate in map view 如何计算给定坐标列表的GEO中位数,并为Google Map View提供缩放级别 - How to calculate GEO median of given list of coordinates and come up with zooming level for Google Map View 如何获取所选地图图钉的坐标数据? - How to get coordinate data of selected map pin? 如何在 flutter 中找到两个地理点之间的确切路线距离 - How to find exact route distance between two geo point in flutter 如何检查坐标并将其加载到Google Map(iOS)中? - How to check and load coordinate into Google Map (iOS)? 如何计算用户当前位置和多个地理坐标之间的最短距离 - How to calculate shortest distance between user current location and multiple geo coordinate 谷歌地图视图如何在地图缩放时获得注释的原始点或框架? - Google map view how can i get original point or frame for annotation while map zoom?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM