Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用mapbox gl Draw创建包含8个点的矩形?_Javascript_Html_Mapbox Gl Js_Mapbox Gl Draw - Fatal编程技术网

Javascript 如何使用mapbox gl Draw创建包含8个点的矩形?

Javascript 如何使用mapbox gl Draw创建包含8个点的矩形?,javascript,html,mapbox-gl-js,mapbox-gl-draw,Javascript,Html,Mapbox Gl Js,Mapbox Gl Draw,我在使用Mapbox gl Draw时遇到了一个独特的问题。Mapbox Draw允许您轻松创建多点多边形,但我需要它仅使用8个点,因为我在其他地方使用的算法接受8个lnglat元素。我想知道当点击绘图按钮时,屏幕上是否会显示一个包含8个点的矩形,并且可以拖动每个点 下面是单击draw的预期结果。 目前我可以画一个矩形,但只有4个点,矩形的每个角 您不应该试图弄乱mapbox gl draw,而应该只获取输出,然后以编程方式添加中点。您可以为此目的使用函数。比如: const coords =

我在使用Mapbox gl Draw时遇到了一个独特的问题。Mapbox Draw允许您轻松创建多点多边形,但我需要它仅使用8个点,因为我在其他地方使用的算法接受8个lnglat元素。我想知道当点击绘图按钮时,屏幕上是否会显示一个包含8个点的矩形,并且可以拖动每个点

下面是单击draw的预期结果。
目前我可以画一个矩形,但只有4个点,矩形的每个角

您不应该试图弄乱mapbox gl draw,而应该只获取输出,然后以编程方式添加中点。您可以为此目的使用函数。比如:

const coords = rectangle.geometry.coordinates[0];
const newcoords = [];
coords.forEach((point, i) => {
   newcoords.push(point);
   if (i < coords.length - 1) {
       newcoords.push(midpoint(point, coords[i+1]).geometry.coords);
   }
});
rectangle.geometry.coordinates = newcoords;
const coords=rectangle.geometry.coordinates[0];
常数newcoords=[];
coords.forEach((点,i)=>{
推(点);
如果(i
谢谢史蒂夫,你的答案很准确,在我费尽周折之后,我想出了解决方案。我要是早点把这个问题贴出来就好了。