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


local Name = "Earthquakes of the 20th Century"
local Identifier = "noaa-sos-land-earthquakes_1901_2000"
local Description = [[This animation shows every recorded earthquake in sequence as they 
occurred from January 1, 1901, through December 31, 2000, at a rate of 1 year per second. 
The earthquake hypocenters first appear as flashes then remain as colored circles before 
shrinking with time so as not to obscure subsequent earthquakes. The size of the circle 
represents the earthquake magnitude while the color represents its depth within the 
earth. At the end of the animation it will first show all quakes in this 100-year period. 
Next, it will show only those earthquakes greater than magnitude 6.5, the smallest 
earthquake size known to make a tsunami. It will then show only those earthquakes with 
magnitudes of 8.0 or larger, the "great" earthquakes most likely to pose a tsunami 
threat when they occur under the ocean or near a coastline and when they are shallow 
within the earth (less than 100 km or 60 mi. deep). The animation concludes by showing 
the plate boundary faults responsible for the majority of all of these earthquakes]]
local URL = "https://sos.noaa.gov/catalog/datasets/earthquakes-of-the-20th-century/"


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

local layer_allquakes = {
  Identifier = Identifier .. "-allquakes",
  Name = Name .. " (All Quakes)",
  FilePath = syncedDirectory .. "All_Quakes_1901-2000_4k.jpg",
  Description = Description
}

local layer_quake_basemap = {
  Identifier = Identifier .. "-quake-basemap",
  Name = Name .. " (Quake Basemap)",
  FilePath = syncedDirectory .. "quake_basemap_4k.jpg",
  Description = Description
}

local layer_plate_boundaries = {
  Identifier = Identifier .. "-plate_boundaries",
  Name = Name .. " (Plate Boundaries)",
  FilePath = syncedDirectory .. "Plate_Boundaries_4k.jpg",
  Description = Description
}

local layer_quakes_gte6_5 = {
  Identifier = Identifier .. "-gte6_5",
  Name = Name .. " (GTE 6.5)",
  FilePath = syncedDirectory .. "Quakes_gte6.5_1901-2000_4k.jpg",
  Description = Description
}

local layer_quakes_gte8 = {
  Identifier = Identifier .. "-gte8",
  Name = Name .. " (GTE 8.0)",
  FilePath = syncedDirectory .. "Quakes_gte8_1901-2000_4k.jpg",
  Description = Description
}

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

asset.onInitialize(function() 
  openspace.globebrowsing.addLayer(globeIdentifier, "ColorLayers", layer_allquakes)
  openspace.globebrowsing.addLayer(globeIdentifier, "ColorLayers", layer_quake_basemap)
  openspace.globebrowsing.addLayer(globeIdentifier, "ColorLayers", layer_plate_boundaries)
  openspace.globebrowsing.addLayer(globeIdentifier, "ColorLayers", layer_quakes_gte6_5)
  openspace.globebrowsing.addLayer(globeIdentifier, "ColorLayers", layer_quakes_gte8)
  openspace.addScreenSpaceRenderable(legend);  
end)

asset.onDeinitialize(function()
  openspace.globebrowsing.deleteLayer(globeIdentifier, "ColorLayers", layer_allquakes)
  openspace.globebrowsing.deleteLayer(globeIdentifier, "ColorLayers", layer_quake_basemap)
  openspace.globebrowsing.deleteLayer(globeIdentifier, "ColorLayers", layer_plate_boundaries)
  openspace.globebrowsing.deleteLayer(globeIdentifier, "ColorLayers", layer_quakes_gte6_5)
  openspace.globebrowsing.deleteLayer(globeIdentifier, "ColorLayers", layer_quakes_gte8)
  openspace.removeScreenSpaceRenderable(legend)
end)

asset.export(layer_allquakes)
asset.export(layer_quake_basemap)
asset.export(layer_plate_boundaries)
asset.export(layer_quakes_gte6_5)
asset.export(layer_quakes_gte8)


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