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



local Name = "Agriculture: Cropland Yield (current)"
local Identifier = "noaa-sos-land-land_production-cropland_current"
local Description = [[A major component of the 2 Billion More Coming to Dinner film,
this dataset shows the current yield for the three top global crops, corn, wheat and
rice, measured in tons per hectare. Similarly, Cropland Yield - Potential, illustrates
the potential yield for a given area, determined by using the productivity of another
region with analogous environmental conditions and optimized water and nutrient input as
a benchmark. For both maps, darker areas show smaller yields, while bright pink areas
indicate higher yields]]
local URL = "https://sos.noaa.gov/catalog/datasets/agriculture-cropland-yield-current/"


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


local Layer = {
  Identifier = Identifier,
  Name = Name,
  Enabled = asset.enabled,
  FilePath = syncedDirectory .. "4096.png",
  Description = Description
}

local LayerCountries = {
  Identifier = Identifier .. "-countries",
  Name = Name .. " (w/ countries)",
  Enabled = asset.enabled,
  FilePath = syncedDirectory .. "4096_countries.png",
  Description = Description
}

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


asset.onInitialize(function()
  openspace.globebrowsing.addLayer(globe.Earth.Identifier, "ColorLayers", Layer)
  openspace.globebrowsing.addLayer(globe.Earth.Identifier, "ColorLayers", LayerCountries)
  openspace.addScreenSpaceRenderable(Legend)
end)

asset.onDeinitialize(function()
  openspace.removeScreenSpaceRenderable(Legend)
  openspace.globebrowsing.deleteLayer(globe.Earth.Identifier, "ColorLayers", LayerCountries)
  openspace.globebrowsing.deleteLayer(globe.Earth.Identifier, "ColorLayers", Layer)
end)

asset.export(Layer)
asset.export(LayerCountries)
asset.export(Legend)



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