export const polygonMaterial = (color, opacity) => {
  return new Cesium.ImageMaterialProperty({
    image: drawImage(color),
  })
}

function drawImage(color) {
  // console.log(color)
  const canvas = document.createElement('canvas')
  canvas.width = 256 * window.devicePixelRatio
  canvas.height = 256 * window.devicePixelRatio
  let ctx = canvas.getContext('2d')
  const centerX = canvas.width / 2
  const centerY = canvas.height / 2
  const grad = ctx.createRadialGradient(
    centerX,
    centerY,
    0, // 内圆中心点和半径
    centerX,
    centerY,
    Math.min(canvas.width, canvas.height) / 2
  )
  grad.addColorStop(0, `rgba(0,0,0,0)`)
  grad.addColorStop(1, color)
  // grad.addColorStop(1, '#fff')
  ctx.fillStyle = grad // 设置fillStyle为当前的渐变对象
  ctx.fillRect(0, 0, canvas.width, canvas.height) // 绘制渐变图形
  return canvas
}
