添加一个点来展开多边形而不将其附加到Google地图中? [英] Add a point to expand polygon without appending it in Google Maps?

查看:127
本文介绍了添加一个点来展开多边形而不将其附加到Google地图中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Google地图上通过可拖动标记重新构建多边形。因此,当有3个标记时,绘制多边形,并在形状中添加更多标记,将其展开。当用户只是想要遵循简单的顺时针/逆时针模式时,这很好,但是当他想通过其一个边缘扩展多边形时,它会附加标记,扭曲它自身。





此处在这个例子中,如果我们添加标记1,2和3,它将绘制一个简单的三角形。但是,如果添加了标记4,多边形就会自行扭曲。



相反,当我添加4时,它会插入标记1和2之间,如下图所示:





基本上,在多边形的顶点数组中,而不是:

  [
//标记1位置,
//标记2位置,
//标记3位置,
//当前标记4位置
]



我想拥有:

  [
// marker 1 position,
//所需标记4 position
// marker 2 position,
// marker 3 position
]

所以多边形将展开而不是扭曲。

有没有办法为了达成这个?或者我只是不得不告诉用户建立他的多边形时钟/逆时针?

解决方案

最后通过找到最近的边并将其插入到第一个顶点之后和第二个边之前。我使用这里的算法在javascript中使用它:

点和线段之间的最短距离


I'm building a polygon in Google Maps through markers that can be dragged to reshape it. So, when there are 3 markers, the polygon is drawn, and further markers are appended in the shape, expanding it. That's fine when the user just want to follow a simple clockwise/counterclockwise pattern, but when he wants to expand the polygon through one of its edges, instead it will append the marker, twisting itself.

Here in this example, if we add markers 1, 2 and 3, it will be drawn a simple triangle. But if marker 4 is added, the polygon just twists itself.

Instead, I want when 4 is added, it's inserted between markers 1 and 2, like this image:

Basically, in the polygon's vertex array, instead of:

[
    //marker 1 position,
    //marker 2 position,
    //marker 3 position,
    //current marker 4 position
]

I want to have:

[
    //marker 1 position,
    //desired marker 4 position
    //marker 2 position,
    //marker 3 position
]

So the polygon will expand instead of twist itself.

Is there a way to achieve this? Or I just will have to tell the user to build his polygon clock/counterclockwise?

解决方案

Finally solved it via finding the nearest edge and inserting it after the first vertex and before the second one of this edge. I used the algorithm from here to use it in javascript:

Shortest distance between a point and a line segment

这篇关于添加一个点来展开多边形而不将其附加到Google地图中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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