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



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 LayerAllquakes = {
  Identifier = Identifier .. "-allquakes",
  Name = Name .. " (All Quakes)",
  FilePath = syncedDirectory .. "All_Quakes_1901-2000_4k.jpg",
  Description = Description
}

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

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

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

local LayerQuakesGte8 = {
  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(globe.Earth.Identifier, "ColorLayers", LayerAllquakes)
  openspace.globebrowsing.addLayer(globe.Earth.Identifier, "ColorLayers", LayerQuakeBasemap)
  openspace.globebrowsing.addLayer(globe.Earth.Identifier, "ColorLayers", LayerPlateBoundaries)
  openspace.globebrowsing.addLayer(globe.Earth.Identifier, "ColorLayers", LayerQuakesGte6p5)
  openspace.globebrowsing.addLayer(globe.Earth.Identifier, "ColorLayers", LayerQuakesGte8)
  openspace.addScreenSpaceRenderable(Legend)
end)

asset.onDeinitialize(function()
  openspace.removeScreenSpaceRenderable(Legend)
  openspace.globebrowsing.deleteLayer(globe.Earth.Identifier, "ColorLayers", LayerQuakeBasemap)
  openspace.globebrowsing.deleteLayer(globe.Earth.Identifier, "ColorLayers", LayerQuakesGte8)
  openspace.globebrowsing.deleteLayer(globe.Earth.Identifier, "ColorLayers", LayerQuakesGte6p5)
  openspace.globebrowsing.deleteLayer(globe.Earth.Identifier, "ColorLayers", LayerPlateBoundaries)
  openspace.globebrowsing.deleteLayer(globe.Earth.Identifier, "ColorLayers", LayerAllquakes)
end)

asset.export(LayerAllquakes)
asset.export(LayerQuakeBasemap)
asset.export(LayerPlateBoundaries)
asset.export(LayerQuakesGte6p5)
asset.export(LayerQuakesGte8)



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