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


local Name = "Blue Marble: with Topography and Bathymetry"
local Identifier = "noaa-sos-land-blue_marble-next_gen-topo_bathy"
local Description = [[The Blue Marble is an incredibly detailed, true-color depiction of 
  the Earth. The Blue Marble Next Generation is an update on the original that has greater 
  detail. "The original Blue Marble was a composite of four months of MODIS observations 
  with a spatial resolution (level of detail) of 1 square kilometer per pixel. Blue Marble: 
  Next Generation offers a years worth of monthly composites at a spatial resolution of 
  500 meters]]
local URL = "https://sos.noaa.gov/catalog/datasets/blue-marble-with-topography-seasonal/"


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 = "TemporalTileLayer",
  Mode = "Folder",
  Folder = {
    Folder = imagesDestination,
    -- See https://en.cppreference.com/w/cpp/io/manip/get_time for an explanation of the
    -- time formatting string
    Format = "world.topo.bathy.%Y%m.3x5400x2700.jpg"
  },
  Description = Description
}

asset.onInitialize(function()
  if not openspace.directoryExists(imagesDestination) then
    openspace.printInfo("Extracting " .. Name)
    openspace.unzipFile(syncedDirectory .. "5400.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/"
}
