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


local Name = "Seal and Seabird Tracks: Pacific Ocean"
local Identifier = "noaa-sos-oceans-animal_tracking"
local Description = [["TOPP, Tagging of the Pacific Predators, began in 2000 as one of 
  17 projects of the Census of Marine Life, an ambitios 10-year, 80-nation endeavor to 
  assess and explain the diversity and abundance of life in the oceans, and where that
  life has lived, is living, and will live." - From TOPP website . Out of this came the
  Tagging of the Pacific Pelagics Project. Pelagaics are open ocean species such as sea
  birds and elephant seals. Scientists put satellite tags on animals that collect
  information about position, ocean temperature, pressure, salinity and more! This allows
  scientists to better understand the migration patterns and habits of these animals]]
local URL = "https://sos.noaa.gov/catalog/datasets/seal-and-seabird-tracks-pacific-ocean/"


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 = "TOPPMOVIE.%Y-%m-%d.png"
  },
  Description = Description
}

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