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


local Name = "Sea Surface Salinity"
local Identifier = "noaa-sos-oceans-sss"
local Description = [[Processes that took place through Earth's history, such as the 
weathering of rocks, evaporation of ocean water, and the formation of sea ice, have made 
the ocean salty. Those are still at work today and are counterbalanced by processes that 
decrease the salt in the ocean, like freshwater input from rivers, precipitation, and the 
melting of ice. The result is an ocean surface where the salinity - the concentration of 
salt - changes and these changes, small as they may be, have large-scale effects on 
Earth's water cycle and ocean circulation]]
local URL = "https://sos.noaa.gov/catalog/datasets/sea-surface-salinity/"


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 colorbar = {
  Identifier = Identifier,
  Name = Name,
  Enabled = asset.enabled,
  Type = "ScreenSpaceImageLocal",
  TexturePath = syncedDirectory .. "colorbar.png",
  FaceCamera = false,
  CartesianPosition = { 0.0, -0.5, -2.0 }
}

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)
  openspace.addScreenSpaceRenderable(colorbar);  
end)

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

asset.export(layer)
asset.export(colorbar)


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