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);