右键点击谷歌地图多段线实际上并未“开启”折线 [英] right click on google map polyline isn't actually "on" the polyline

查看:274
本文介绍了右键点击谷歌地图多段线实际上并未“开启”折线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个标记都通过处理多段线上的右键单击方法放置在Google地图上,即:

  google .maps.event.addListener(折线,'rightclick',myMethodThatHandlesIt); 

问题是我试图通过C#空间来定位点(第一个顶部) Geography.Intersects(),以及它不相交。

完全取决于缩放。通过右键单击(缩小)折线创建的第一个距离实际多段线超过1公里。



是否有任何方法可以确保将标记置于行上,如在两行之间?



对于遇到这个问题的其他人,我无法弄清楚在Javascript中使用它的简单方法,最终我不需要这样做。制作者可能稍微有些偏离,但我需要坚持它作为与该线相交的点。因此,下面的方法可以在我存储它之前更改标记位置。



我选择使用Microsoft.SqlServer.Types.SqlGeography,它有一个



  Geography.ShortestLineTo(OtherGeography)

这给出了一个新的线,有两个点,一个在用户的标记位置,另一个在距离路线/折线/线串最近的十字路口。



新行的结尾是用户在多义线上点击的路径上最近的点。

  public static System.Data.Spatial.DbGeography GetClosestPointOnRoute(System.Data.Spatial.DbGeography line,System.Data.Spatial.DbGeography point)
{
SqlGeography sqlLine = SqlGeography.Parse(line.AsText()) .MakeValid(); // linelines
SqlGeography sqlPoint = SqlGeography.Parse(point.AsText())。MakeValid(); //我想要的点

SqlGeography shortestLine = sqlPoint.ShortestLineTo(sqlLine); //找到线串中最短的一行以指向

//线条有一个开始和一个结束
SqlGeography start = shortestLine.STStartPoint();
SqlGeography end = shortestLine.STEndPoint();

DbGeography newGeography = DbGeography.FromText(end.ToString(),4326);

var distance = newGeography.Distance(line);

return newGeography;
}

另外 Issue 5887 是在Googleland中创建的,希望能够解决。


Both of these markers were placed on a Google map by handling the right click method on a polyline, ie:

google.maps.event.addListener(polyline, 'rightclick', myMethodThatHandlesIt);

The problem is that I was trying to locate the point (the first one up top) via C# spatial Geography.Intersects() and, well, it doesn't intersect.

It's completely dependent upon the zoom it seems. The top one, which again was created by right clicking on the (zoomed out) polyline, is over 1km away from the actually polyline.

Is there any way to ensure that the marker is placed ON the line, as in between the two line ends?

解决方案

For anyone else who runs into this, I couldn't figure out a clean way of doing it in Javascript and ultimately I didn't need to. The maker can be a little off but I need to persist it as a point that intersects the line. So the following method is in place to change the marker location before I store it.

I opted to use Microsoft.SqlServer.Types.SqlGeography which has a method of

Geography.ShortestLineTo(OtherGeography)

That gives a new line with two points, one at the user's marker location, the other at the closest intersection to the route/polyline/linestring.

The end of the new line is the closest point on the route to where the user right clicked on the polyline.

        public static System.Data.Spatial.DbGeography GetClosestPointOnRoute(System.Data.Spatial.DbGeography line, System.Data.Spatial.DbGeography point)
    {
        SqlGeography sqlLine = SqlGeography.Parse(line.AsText()).MakeValid(); //the linestring
        SqlGeography sqlPoint = SqlGeography.Parse(point.AsText()).MakeValid(); //the point i want on the line

        SqlGeography shortestLine = sqlPoint.ShortestLineTo(sqlLine); //find the shortest line from the linestring to point

        //lines have a start, and an end
        SqlGeography start = shortestLine.STStartPoint();
        SqlGeography end = shortestLine.STEndPoint();

        DbGeography newGeography = DbGeography.FromText(end.ToString(), 4326);

        var distance = newGeography.Distance(line);

        return newGeography;
    }

Additionally Issue 5887 was created over in Googleland to hopefully address.

这篇关于右键点击谷歌地图多段线实际上并未“开启”折线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆