What are the best practices for managing large amounts of GeoJSON data?

A common scenario is when we have multiple GeoJSON files that need to be managed collectively. Here’s an example:

const geoJsonList = [
  { url: 'water' },
  { url: 'roadLines' },
  { url: 'buildings' },
  { url: 'pipeLines' },
  { url: 'pipePolygons' },
  { url: 'grass' },
  { url: 'land' },
  //...
]

In this case, we need to handle their z-index in a unified way. Additionally, some of them are linestring, some are polygon, some need to be clampedToGround, some need to be show or hide by the distance of camera, and some require special material.

This situation often leaves me frustrated and leads to repetitive and poorly written code. I would like to seek advice from the community experts to find the best practices in this regard.
Much thx!

My code now looks like this:

geoJsonList.foreach(item=>{
//...
if (item.url === 'land' || item.url === 'grass') {
  const r = await fetch(
    `${import.meta.env.BASE_URL}geojson/${item.url}.json`
  )
  const res = await r.json()
  res.features.forEach(i => {
    let arr = []
    i.geometry.coordinates.forEach(j => {
      j.forEach(r => {
        r[2] = 0
        arr.push(r)
      })
    })

    const positions = Cesium.Cartesian3.fromDegreesArrayHeights(arr.flat())
    const line = viewer.entities.add({
      polygon: {
        hierarchy: positions,
        width: 4,
        material: Cesium.Color.fromCssColorString(`${item.fill}`).withAlpha(1),
        classificationType: Cesium.ClassificationType.TERRAIN,
        clampToGround: true,
        stRotation: 0
      }
    })
    line.show = defaultState
  })
  return
}
//..
}
viewer.camera.changed.addEventListener(() => {
  const height = viewer.camera.positionCartographic.height
  if (height >= 1000) {
    lineArr.length > 0 &&
      lineArr.forEach(i => {
        if (i.name == 'polygon') {
          i.polygon.show = false
        } else if (i.name == 'polyline') {
          i.polyline.show = true
        }
      })
    return
  }
})

I think that is so silly but I have no idea about how to improve that. :smiling_face_with_tear: