Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.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/1/typescript/8.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
Angular 如何动态创建多多边形阵列?_Angular_Typescript_Geojson_Turfjs - Fatal编程技术网

Angular 如何动态创建多多边形阵列?

Angular 如何动态创建多多边形阵列?,angular,typescript,geojson,turfjs,Angular,Typescript,Geojson,Turfjs,我的目标是构建一个turp.jsmultiPolygon。 这种硬编码工作正常: const searchWithin = turf.multiPolygon( [ [[ [-0.607051, 44.840753], [-0.543708, 44.832962], [-0.52225, 44.820544], [-0.566367, 44.808853], [-0.586367, 44.788853

我的目标是构建一个
turp.js
multiPolygon。 这种硬编码工作正常:

const searchWithin = turf.multiPolygon(
[
    [[
        [-0.607051, 44.840753], 
        [-0.543708, 44.832962], 
        [-0.52225, 44.820544], 
        [-0.566367, 44.808853], 
        [-0.586367, 44.788853], 
        [-0.607051, 44.840753]
    ]],
    [[
        [5.39014, 43.279295], 
        [5.393069, 43.279249], 
        [5.391814, 43.278421], 
        [5.390709, 43.278749], 
        [5.3909, 43.2785], 
        [5.39014, 43.279295]
    ]]
]);
如您所见,在获取坐标数组之前,有3级括号。 从数据库中,我得到:

[
    [
        [-0.607051, 44.840753], 
        [-0.543708, 44.832962], 
        [-0.52225, 44.820544], 
        [-0.566367, 44.808853], 
        [-0.586367, 44.788853], 
        [-0.607051, 44.840753]
    ],
    [
        [5.39014, 43.279295], 
        [5.393069, 43.279249], 
        [5.391814, 43.278421], 
        [5.390709, 43.278749], 
        [5.3909, 43.2785], 
        [5.39014, 43.279295]
    ]
]
要从数据库中获取数据,请执行以下操作:

.subscribe((response) => {
      this.locations = response;
      this.polygonsArray.push(this.locations);
      this.locations.forEach(element => {          
this.polygons.push(element.geoDefinition.features['0'].geometry.coordinates);
多边形声明为:

polygons: number[][][] = [];
我试过:

this.polygons.push('['+element.geoDefinition.features['0'].geometry.coordinates)+']';
但坐标是数字,所以我不能连接

我怎样才能把这个结构用三个方括号括起来呢?任何帮助都会很有帮助


我提前感谢您的帮助。

不清楚预期的结构。但首先值得注意的是:

  • 如果多边形是三维数组,如
    polygons:number[][]=[],您不能直接将数字推送到它,如多边形。推(5)
    ,您必须考虑结构:
  • 多边形[0][0]。按(5)
    多边形。按([[5]])

  • 另一件事是
    this.polygonsArray.push(this.locations)-它至少应该是
    this.polygonsArray.push(…this.locations)作为推送将整个
    this.locations
    数组添加为
    this.polygonsArray
    的第一个元素

  • 最后一个。如果你推动类似于
    this.polygons.push('['+something+']')的东西-只需将字符串推到简单数组。相反,你可以使用

    this.polygons[0]。推(某物)


  • 希望它能为您的案例提供一些如何组织三维结构的想法。

    目前还不清楚您将在哪些内容中嵌入哪些内容。请你澄清一下位置、多边形、多边形阵列等的预期结构好吗?我想用正确的turf.multiPolygon格式,即在每个多边形坐标声明之前添加[[添加,在每个多边形坐标声明之后添加]]。是的,我想我仍然需要使用它。谢谢你,我是根据你的想法来的。1st/this.polygons.push('['+something+']');无法工作,因为某些内容是数字格式,必须保留。第二个/
    元素。地理定义。特征['0']。几何体。坐标
    是一个数组数组。事实上,我只需要添加额外的括号,我不知道如何添加。另一个注释:this.polygons是数组和turf.multiPolygon[也是数组数组使用this.polygons.push([element.geoDefinition.features['0'].geometry.coordinates]);或者this.polygons[0]=[];this.polygons[0].push(element.gement.geoDefinition.features['0'].geometry.coordinates);this.polygons.push('['+something+']')-在您的描述中,不应该是这样。相反,我建议使用此.polygons[0].push(something);