
function entitiesToPrimitives(features) {
  const instances = []
  for (let i = 0; i < features.length; i++) {
    for (let j = 0; j < features[i].geometry.coordinates.length; j++) {
      const polygonArray = features[i].geometry.coordinates[j].toString().split(',')
      let polygonHierarchy
      if (features[i].geometry.coordinates[0][0][0].length === 2) {
        polygonHierarchy = new Cesium.PolygonHierarchy(
          Cesium.Cartesian3.fromDegreesArray(polygonArray)
        ) // fromDegreesArray
      } else {
        polygonHierarchy = new Cesium.PolygonHierarchy(
          Cesium.Cartesian3.fromDegreesArrayHeights(polygonArray)
        ) // fromDegreesArray
      }
      const polygon = new Cesium.PolygonGeometry({
        polygonHierarchy: polygonHierarchy,
        // 设置面的拉伸高度
        extrudedHeight: 20
      })
      const geometry = Cesium.PolygonGeometry.createGeometry(polygon)
      instances.push(new Cesium.GeometryInstance({
        geometry: geometry
        // attributes: {
        //   color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.GREEN)
        // }
      }))
    }
  }
  // 合并单个geometry,提高渲染效率
  const img = 'static/Cesium/Assets/Textures/waterNormals.jpg'
  const primitive = new Cesium.Primitive({
    geometryInstances: instances,
    appearance: new Cesium.EllipsoidSurfaceAppearance({
      material: new Cesium.Material({
        fabric: {
          type: 'Water',
          uniforms: {
            baseWaterColor: new Cesium.Color(62 / 255.0, 96 / 255.0, 98 / 255.0, 0.8),
            normalMap: img,
            frequency: 200.0, // 频率 1000
            animationSpeed: 0.01, // 动画速度 0.1
            amplitude: 10, // 变化幅度 10
            specularIntensity: 0.5// 反射强度 10
          }
        }
      })
    })
  })
  viewer.scene.primitives.add(primitive)
}

export default entitiesToPrimitives
