local globe = asset.require("../../earth")



local Name = "Earth's Magnetic Declination"
local Identifier = "noaa-sos-land-magnetic_declination"
local Description = [[Earth is like a giant magnet with a North and South Pole. However,
the magnetic North and South Pole are not aligned with the Geographic North and South
Pole. The Geographic North Pole is defined by the latitude 90° N and is the axis of the
Earth's rotation. The Magnetic North Pole is where the Earth's magnetic field points
vertically downward. The Earth creates its own magnetic field from the electric currents
created in the liquid iron-nickel core]]
local URL = "https://sos.noaa.gov/catalog/datasets/earths-magnetic-declination/"


local syncedDirectory = asset.syncedResource({
  Name = Name,
  Type = "HttpSynchronization",
  Identifier = Identifier,
  Version = 1,
  UnzipFiles = true
})


local Layer = {
  Identifier = Identifier,
  Name = Name,
  Enabled = asset.enabled,
  Type = "TemporalTileLayer",
  Mode = "Folder",
  Folder = {
    Folder = syncedDirectory .. "4096",
    -- @TODO: This dataset is not using equirectangular projection, so it will look
    -- strange on the planet right now

    -- See https://en.cppreference.com/w/cpp/io/manip/get_time for an explanation of the
    -- time formatting string
    Format = "%Y.png"
  },
  Description = Description
}


asset.onInitialize(function()
  openspace.printWarning(
    "The 'Magnetic Declination' map currently has an unsupported projection and thus " ..
    "will look strange when projected onto the spherical Earth"
  )

  openspace.globebrowsing.addLayer(globe.Earth.Identifier, "ColorLayers", Layer)
end)

asset.onDeinitialize(function()
  openspace.globebrowsing.deleteLayer(globe.Earth.Identifier, "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/"
}
