Skip to content

Instantly share code, notes, and snippets.

@argentinaluiz
Created February 6, 2019 18:05
Show Gist options
  • Save argentinaluiz/d4ac2051fc63ee771ef4f991de48fb08 to your computer and use it in GitHub Desktop.
Save argentinaluiz/d4ac2051fc63ee771ef4f991de48fb08 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<body>
<p>Looping through arrays inside arrays.</p>
<p id="demo"></p>
<script>
var myObj, i, j, x = "";
var obj = {"prop1": "valor1", "prop2": "valor2"};
obj['prop1']
var array = [1, 10, "luiz", true, obj];
array[0]
array[1]
array[4].prop1
array.forEach()
var meuJson = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "GeometryCollection",
"geometries": [
{
"type": "Point",
"coordinates": [
-5698017.38277553,
-3485280.06946211
]
},
{
"type": "Point",
"coordinates": [
-5698189.36608918,
-3486426.62488639
]
},
{
"type": "LineString",
"coordinates": [
[
-5697845.39946189,
-3485987.11197375
],
[
-5695762.49044112,
-3486388.40637225
],
[
-5694940.79238706,
-3485681.36386061
]
]
},
{
"type": "Polygon",
"coordinates": [
[
[
-5697233.90323561,
-3484630.35472169
],
[
-5696584.18849519,
-3485299.17871918
],
[
-5695533.17935627,
-3484496.58992219
],
[
-5697233.90323561,
-3484630.35472169
]
]
]
}
]
},
"properties": null
},
{
"type": "Feature",
"geometry": {
"type": "GeometryCollection",
"geometries": []
},
"properties": null
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-5696044.351982923,
-3485719.5823747497
]
},
"properties": null
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-5695432.855756641,
-3485490.271289894
]
},
"properties": null
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-5696006.133468781,
-3485270.514833574
]
},
"properties": null
}
]
}
class Polygon{
coord: Array<Point>
toJson(){
}
}
class Feature{
geometry: Point | GeometryCollection
constructor(dado){
dado.geometry.type = "point"
this.geometry = new Point(dado.geometry)
}
}
class GeometryCollection{
}
class PointAncestral{
coordinates: Array<int> = [];
constructor(data){
}
toJson(){
return {
'coor'
'outrocampo'
}
}
}
class Point extends PointAncestral{
}
var myObj, i, j, x = "";
var listaDeObjetosFiltrados = [];
for(i in meuJson.features){
switch(myObj.features[i].geometry.type){
case "GeometryCollection":
break;
case "Point":
break;
case "Feature":
const variavel = myObj.features[i].geometry;
listaDeObjetosFiltrados.push(new Feature(variavel))
break;
}
}
listadeobjetos = [
Point,
GeometryCollection
Feature
];
listadeobjetos
var json = [];
for key in listadebojetos
json.push(listadebojetos[key].toJson())
[
{type: "alguma", prop1: "algumacoisa"},
{type: "alguma", prop1: "algumacoisa"},
{type: "alguma", prop1: "algumacoisa"},
{type: "alguma", prop1: "algumacoisa"},
{type: "alguma", prop1: "algumacoisa"},
{type: "alguma", prop1: "algumacoisa"},
{type: "alguma", prop1: "algumacoisa"},
{type: "alguma", prop1: "algumacoisa"},
]
/*
for (i in meuJson.features) {
//alert (myObj.features[i].geometry.type)
if (myObj.features[i].geometry.type != "GeometryCollection"){
for (j in myObj.features[i].geometry) {
x += myObj.features[i].geometry[j] ;
}
}
if(myObj.features[i].geometry.type != "Point"){
for( key in myObj.features[i].geometry.coordinates){
myObj.features[i].geometry.geometries[key]
}
}
/* if (myObj.features[i].geometry.type == "GeometryCollection"){
for (j in myObj.features[i].geometry) {
alert(j);
x += myObj.features[i].geometry[j].geometries ;
}
}
*/
// }
geometry.hasOwnProperty('propx')
meuJson.features.forEach(nivel1 => {
var container = nivel1.geometry.geometries
container.forEach(nivel2 => {
if(nivel2.coordinates.length > 0 && nivel2.coordinates != undefined){
listaDeObjetosFiltrados.push (nivel2);
alert (nivel2.type +nivel2.coordinates);
//alert (nivel2.coordinates)
x += nivel2.type +nivel2.coordinates;
}
});
});
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment