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


local Name = "Fire Observations and Vegetation - 2002 - 2011"
local Identifier = "noaa-sos-land-fire_veg"
local Description = [[This dataset leads viewers on a narrated global tour of fire 
  detections beginning in July 2002 and ending July 2011. The dataset also includes 
  vegetation and snow cover data to show how fires respond to seasonal changes. The tour 
  begins in Australia in 2002 by showing a network of massive grassland fires spreading 
  across interior Australia as well as the greener Eucalyptus forests in the northern and 
  eastern part of the continent. The tour then shifts to Asia where large numbers of 
  agricultural fires are visible first in China in June 2004, then across a huge swath of 
  Europe and western Russia in August, and then across India and Southeast Asia through
  the early part of 2005]]
local URL = "https://sos.noaa.gov/catalog/datasets/fire-observations-and-vegetation-2002-2011/"


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

local colorbar_veg = {
  Identifier = Identifier,
  Name = Name,
  Enabled = asset.enabled,
  Type = "ScreenSpaceImageLocal",
  TexturePath = syncedDirectory .. "veg_colorbar.png",
  FaceCamera = false,
  CartesianPosition = { 0.5, -0.5, -2.0 }
}

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

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

asset.export(layer)
asset.export(colorbar_fire)
asset.export(colorbar_veg)


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