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


local Name = "Typhoon Haiyan: Water Vapor and SST - Oct - Nov 2013"
local Identifier = "noaa-sos-atmosphere-typhoon_haiyan-wvsst"
local Description = [[Typhoon Haiyan, also known in the Phillippines as Typhoon Yolanda, 
may be the strongest recorded tropical cyclone to make landfall with sustained speeds up 
to 195 mph. If confirmed, it would beat the previous record holder, Hurricane Camille 
(1969). This dataset is taken from the Real-Time Linear IR satellite dataset and 
Real-time: SST from October 30th to November 12th, 2013]]
local URL = "https://sos.noaa.gov/catalog/datasets/typhoon-haiyan-water-vapor-and-sst-oct-nov-2013/"


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
}

local track = {
  Identifier = Identifier .. "-track",
  Name = Name .. " (Track)",
  Enabled = asset.enabled,
  FilePath = syncedDirectory .. "track.png",
  Description = Description
}

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

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

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

asset.export(layer)
asset.export(track)


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