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


local Name = "Light Pollution - Artificial Sky Brightness"
local Identifier = "noaa-sos-land-nightsky"
local Description = [[Light pollution in urban centers creates a sky glow that can blot 
out the stars. The brighter the area in this map the harder it is to see stars and 
constellations in the night sky]]
local URL = "https://sos.noaa.gov/catalog/datasets/light-pollution-artificial-sky-brightness/"


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

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

local legend = {
  Identifier = Identifier,
  Name = Name,
  Enabled = asset.enabled,
  Type = "ScreenSpaceImageLocal",
  TexturePath = syncedDirectory .. "nightsky_lights_legend.jpg",
  FaceCamera = false,
  CartesianPosition = { 0.75, 0.0, -2.0 }
}

asset.onInitialize(function() 
  openspace.globebrowsing.addLayer(globeIdentifier, "ColorLayers", layer)
  openspace.addScreenSpaceRenderable(legend);  
end)

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

asset.export(layer)
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/"
}
