Files
qt5-legatus-legacy/Lts/Tools/EsriHTML/TestModule/parse.js
T
2026-08-13 18:33:10 +02:00

196 lines
5.1 KiB
JavaScript
Executable File

class Polygon {
constructor() {
this.vertex = [];
}
addVertext(vertex) {
this.vertex.push(vertex);
}
closeRing() {
this.vertex.push(this.vertex[0]);
}
}
var parser, xmlDoc, PolyArray;
var PolygonObj = [];
var text = `<Group>
<Name>FOOTPRINT</Name>
<BBox_Min Z="2.850" Y="2.181" X="3.896" />
<BBox_Max Z="2.851" Y="6.766" X="6.175" />
<Polygon>
<Name>p6739</Name>
<Vertex>
<Name>p6739/V1</Name>
<Coord X="4.166" Y="6.766" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V2</Name>
<Coord X="4.151" Y="6.692" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V3</Name>
<Coord X="3.914" Y="6.694" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V4</Name>
<Coord X="3.896" Y="5.925" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V5</Name>
<Coord X="4.158" Y="5.923" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V6</Name>
<Coord X="4.089" Y="2.181" Z="2.851" />
</Vertex>
<Vertex>
<Name>p6739/V7</Name>
<Coord X="5.178" Y="2.203" Z="2.851" />
</Vertex>
<Vertex>
<Name>p6739/V8</Name>
<Coord X="5.178" Y="2.253" Z="2.851" />
</Vertex>
<Vertex>
<Name>p6739/V9</Name>
<Coord X="5.863" Y="2.253" Z="2.851" />
</Vertex>
<Vertex>
<Name>p6739/V10</Name>
<Coord X="5.879" Y="3.634" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V11</Name>
<Coord X="6.024" Y="3.632" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V12</Name>
<Coord X="6.028" Y="4.383" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V13</Name>
<Coord X="5.888" Y="4.385" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V14</Name>
<Coord X="5.898" Y="5.830" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V15</Name>
<Coord X="6.171" Y="5.829" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V16</Name>
<Coord X="6.175" Y="6.554" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V17</Name>
<Coord X="5.902" Y="6.555" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V18</Name>
<Coord X="5.903" Y="6.760" Z="2.850" />
</Vertex>
</Polygon>
<Polygon>
<Name>p6739</Name>
<Vertex>
<Name>p6739/V1</Name>
<Coord X="4.166" Y="6.766" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V2</Name>
<Coord X="4.151" Y="6.692" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V3</Name>
<Coord X="3.914" Y="6.694" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V4</Name>
<Coord X="3.896" Y="5.925" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V5</Name>
<Coord X="4.158" Y="5.923" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V6</Name>
<Coord X="4.089" Y="2.181" Z="2.851" />
</Vertex>
<Vertex>
<Name>p6739/V7</Name>
<Coord X="5.178" Y="2.203" Z="2.851" />
</Vertex>
<Vertex>
<Name>p6739/V8</Name>
<Coord X="5.178" Y="2.253" Z="2.851" />
</Vertex>
<Vertex>
<Name>p6739/V9</Name>
<Coord X="5.863" Y="2.253" Z="2.851" />
</Vertex>
<Vertex>
<Name>p6739/V10</Name>
<Coord X="5.879" Y="3.634" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V11</Name>
<Coord X="6.024" Y="3.632" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V12</Name>
<Coord X="6.028" Y="4.383" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V13</Name>
<Coord X="5.888" Y="4.385" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V14</Name>
<Coord X="5.898" Y="5.830" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V15</Name>
<Coord X="6.171" Y="5.829" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V16</Name>
<Coord X="6.175" Y="6.554" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V17</Name>
<Coord X="5.902" Y="6.555" Z="2.850" />
</Vertex>
<Vertex>
<Name>p6739/V18</Name>
<Coord X="5.903" Y="6.760" Z="2.850" />
</Vertex>
</Polygon>
</Group>`
parser = new DOMParser();
xmlDoc = parser.parseFromString(text, "text/xml");
PolyArray = Array.from(xmlDoc.getElementsByTagName("Polygon"));
PolyArray.forEach(polygon => {
polyObj = new P1();
var vertexes = Array.from(polygon.children);
for (var x = 1; x < vertexes.length; x++) {
var vertextChildren = vertexes[x].children[1].attributes;
var vertex = {};
for (var y = 0; y < 3; y++) {
switch (y) {
case 1:
vertex.x = parseFloat(vertextChildren[y].nodeValue);
break;
case 2:
vertex.y = parseFloat(vertextChildren[y].nodeValue);
case 3:
vertex.z = parseFloat(vertextChildren[y].nodeValue);
}
}
polyObj.addVertext(vertex);
}
P1.push(polyObj);
});
P1.forEach(polygon => {
polygon.closeRing();
});