local globeIdentifier = asset.require("../../earth").Earth.Identifier


local Name = "Dams and Reservoirs: Yangtze - 1800 - 2010"
local Identifier = "noaa-sos-land-dams-yangtze"
local Description = [[Humans have manipulated rivers for thousands of years, but over 
the last 200 years dams on rivers have become rampant. Reservoirs and dams are 
constructed for water storage, to reduce the risk of river flooding, and for the 
generation of power. They are one of the major footprints of humans on Earth and change 
the world's hydrological cycle]]
local URL = "https://sos.noaa.gov/catalog/datasets/dams-and-reservoirs-yangtze-1800-2010/"


local syncedDirectory = asset.syncedResource({
  Name = Name,
  Type = "HttpSynchronization",
  Identifier = Identifier,
  Version = 1
})

local imagesDestination = syncedDirectory .. "images"

local layer = {
  Identifier = Identifier,
  Name = Name,
  Enabled = asset.enabled,
  Type = "ImageSequenceTileLayer",
  FolderPath = imagesDestination,
  Description = Description
}

asset.onInitialize(function()
  if not openspace.directoryExists(imagesDestination) then
    openspace.printInfo("Extracting " .. Name)
    openspace.unzipFile(syncedDirectory .. "4096.zip", imagesDestination, true)
  end

  openspace.globebrowsing.addLayer(globeIdentifier, "ColorLayers", layer)
end)

asset.onDeinitialize(function()
  openspace.globebrowsing.deleteLayer(globeIdentifier, "ColorLayers", layer)
end)

asset.export(layer)


asset.meta = {
  Name = Name,
  Version = "1.0",
  Description = Description .. "Data provided by the National Oceanic and Atmospheric Administration",
  Author = "National Oceanic and Atmospheric Administration",
  URL = URL,
  License = "https://sos.noaa.gov/copyright/"
}
