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


local Name = "Topography and Bathymetry with Nighttime Lights"
local Identifier = "noaa-sos-land-hot_topo"
local Description = [[This planet Earth visualization shows a rotating planet in order 
to display both a nighttime and daytime view. The daytime side of the visualization shows 
the bathymetry and topography of the globe. Color coding is used to distinguish between 
the elevations. Red and gray represent the highest terrain on the land, green and yellow 
represent the lowest. In the ocean, the darker colors are the deeper ocean floors while 
the lighter colors indicate shallower areas as well as mountain ranges on the sea floor. 
The very light blue shading in the ocean, near the land forms, is generally the shallow 
continental shelf. Some interesting features that can be seen are the mountain ranges in 
the oceans, such as the mid-Atlantic Ridge in the middle of the Atlantic Ocean, which is 
spreading. Also in the ocean is the Marianas Trench, which is south of Japan. This trench 
is the deepest location in the ocean with an amazing depth of 36,201 feet, almost 7 
miles. On land, the Himalayas are a noteworthy feature, as they are the home of Mount 
Everest, the tallest point on earth at a height of 29,035 feet, almost 5.5 miles]]
local URL = "https://sos.noaa.gov/catalog/datasets/topography-and-bathymetry-with-nighttime-lights/"


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-1.zip", imagesDestination, true)
    openspace.unzipFile(syncedDirectory .. "4096-2.zip", imagesDestination, true)
    openspace.unzipFile(syncedDirectory .. "4096-3.zip", imagesDestination, true)
    openspace.unzipFile(syncedDirectory .. "4096-4.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/"
}
