local globe = asset.require("../../earth")



local Name = "Hurricane Harvey: Clouds with Precipitation - 2017"
local Identifier = "noaa-sos-atmosphere-harvey-clouds_precip"
local Description = [[Hurricane Harvey was an extremely destructive Atlantic hurricane
  which became the first major hurricane to make landfall in the U.S. since Wilma in 2005.
  In a four-day period, many areas of eastern Texas received over 40 inches of rain as the
  system meandered along the gulf coast causing catastrophic flooding. With a record of
  51.88 inches, Harvey is the wettest tropical hurricane on record in the contiguous U.S.
  The resulting floods inundated hundreds of thousands of homes, displaces more than
  30,000 people, and prompted more than 17,000 rescues]]
local URL = "https://sos.noaa.gov/catalog/datasets/hurricane-harvey-clouds-with-precipitation-2017/"


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


local Layer = {
  Identifier = Identifier,
  Name = Name,
  Enabled = asset.enabled,
  Type = "TemporalTileLayer",
  Mode = "Folder",
  Folder = {
    Folder = syncedDirectory .. "4096",
    -- See https://en.cppreference.com/w/cpp/io/manip/get_time for an explanation of the
    -- time formatting string
    Format = "combined_image_%Y%m%d_%H%M.jpg"
  },
  Description = Description
}

local ColorbarRain = {
  Identifier = Identifier .. "-rain",
  Name = Name .. " (Rain)",
  Enabled = asset.enabled,
  Type = "ScreenSpaceImageLocal",
  TexturePath = syncedDirectory .. "rainbar_white.png",
  FaceCamera = false,
  CartesianPosition = { -0.5, -0.5, -2.0 }
}

local ColorbarSnow = {
  Identifier = Identifier .. "-snow",
  Name = Name ..  " (Snow)",
  Type = "ScreenSpaceImageLocal",
  TexturePath = syncedDirectory .. "snowbar_white.png",
  FaceCamera = false,
  CartesianPosition = { 0.5, -0.5, -2.0 }
}


asset.onInitialize(function()
  openspace.globebrowsing.addLayer(globe.Earth.Identifier, "ColorLayers", Layer)
  openspace.addScreenSpaceRenderable(ColorbarRain)
  openspace.addScreenSpaceRenderable(ColorbarSnow)
end)

asset.onDeinitialize(function()
  openspace.removeScreenSpaceRenderable(ColorbarSnow)
  openspace.removeScreenSpaceRenderable(ColorbarRain)
  openspace.globebrowsing.deleteLayer(globe.Earth.Identifier, "ColorLayers", Layer)
end)

asset.export(Layer)
asset.export(ColorbarRain)
asset.export(ColorbarSnow)



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/"
}
