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


local Name = "Sea Turtle Track: Pacific Ocean"
local Identifier = "noaa-sos-oceans-pac_turtle"
local Description = [[It is common for scientists to tag animals and release them into 
their natural environment in order to study their behaviors and migration. Adelita, a 
loggerhead (Caretta caretta) sea turtle, was originally captured off of Baja, Mexico as 
an 8-pound juvenile. After being raised in captivity, Adelita was released on August 10, 
1996 from Santa Rosaliita, a small town in Mexico on the Baja Peninsula. Adelita weighed 
223 pounds when she was released. Before she was released, Wallace J. Nichols, then a 
Ph.D. student at the University of Arizona, outfitted Adelita with a satellite tag. The 
tag transmitted a signal that allowed Adelita's track to be monitored post-release]]
local URL = "https://sos.noaa.gov/catalog/datasets/sea-turtle-track-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 = "pac-turtle-migration-%y%j-%H%M.jpg"
  },
  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)
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/"
}
