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


local Name = "Tsunami Locations - 2000 BCE - 2014"
local Identifier = "noaa-sos-oceans-tsunami_locations"
local Description = [[Earthquakes, landslides, volcanoes, explosions, and atmospheric 
processes - all of these disasters have caused tsunamis in the past. But by far, the most 
common generator of tsunamis is earthquakes, as has recently been seen in Sumatra, Chile, 
and Japan. The NOAA National Geophysical Data Center archives academic and historical 
reports from around the world of where tsunamis are estimated to have originated, and 
have compiled a database of over 2,500 events from 2,000 B.C. through 2014t. This image 
plots about half of those events - tsunamis that are classified as a "definite tsunami" 
or "probable tsunami." The icons are shaded according to the devastation of the event by 
the number of fatalities caused where white = none, yellow = 1-50, orange = 51-100, and 
red = >101. Since earthquakes are the most common tsunami generator, the highest density 
of event origins are located around the Pacific "Ring of Fire" known for its prevalence 
of volcanic and tectonic activity. The points are overlaid on top of a map of ocean 
bathymetry (Natural Earth 2 from the Natural Earth project), which indicates many of the 
pronounced ocean features, such as volcanic islands, rift zones, and plate boundaries
 that are often associated with generating tsunamis]]
local URL = "https://sos.noaa.gov/catalog/datasets/tsunami-locations-2000-bce-2014/"


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

local layer_base = {
  Identifier = Identifier,
  Name = Name,
  FilePath = syncedDirectory .. "4096.jpg",
  Description = Description
}

local layer_gray = {
  Identifier = Identifier .. "-gray",
  Name = Name .. " (Gray)",
  FilePath = syncedDirectory .. "gray_earth_with_countries_4096.png",
  Description = Description
}

local layer_neutral = {
  Identifier = Identifier .. "-neutral",
  Name = Name .. " (Neutral)",
  FilePath = syncedDirectory .. "natural_earth_with_countries_4096.png",
  Description = Description
}

local layer_events = {
  Identifier = Identifier .. "-events",
  Name = Name .. " (Events)",
  FilePath = syncedDirectory .. "tsunami_events.png",
  Description = Description
}

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


asset.onInitialize(function() 
  openspace.globebrowsing.addLayer(globeIdentifier, "ColorLayers", layer_base)
  openspace.globebrowsing.addLayer(globeIdentifier, "ColorLayers", layer_gray)
  openspace.globebrowsing.addLayer(globeIdentifier, "ColorLayers", layer_neutral)
  openspace.globebrowsing.addLayer(globeIdentifier, "ColorLayers", layer_events)
  openspace.addScreenSpaceRenderable(legend);  
end)

asset.onDeinitialize(function()
  openspace.globebrowsing.deleteLayer(globeIdentifier, "ColorLayers", layer_base)
  openspace.globebrowsing.deleteLayer(globeIdentifier, "ColorLayers", layer_gray)
  openspace.globebrowsing.deleteLayer(globeIdentifier, "ColorLayers", layer_neutral)
  openspace.globebrowsing.deleteLayer(globeIdentifier, "ColorLayers", layer_events)
  openspace.removeScreenSpaceRenderable(legend)
end)

asset.export(layer_base)
asset.export(layer_gray)
asset.export(layer_neutral)
asset.export(layer_events)


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