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


local Name = "Japan Earthquake - March 2011"
local Identifier = "noaa-sos-land-japan_quake"
local Description = [[On March 11, 2011 at 2:45 local time, a 9.0 magnitude earthquake 
occurred 81 miles (130 km) off the east coast of Sendai, Japan, triggering a massive 
tsunami. It is estimated that the initial tsunami wave took 10 to 30 minutes to make its 
first landfall. Forecasted wave heights were up to 33 ft (10 m) and there were many 
reports of tsunami waves three stories high in parts of Japan. Across the Pacific Ocean, 
many countries issued evacuations along the coasts because of the predicted tsunami 
waves]]
local URL = "https://sos.noaa.gov/catalog/datasets/japan-earthquake-march-2011/"


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

local imagesDestination = syncedDirectory .. "images"

local layer = {
  Identifier = Identifier,
  Name = Name,
  Enabled = asset.enabled,
  Type = "ImageSequenceTileLayer",
  FolderPath = imagesDestination,
  Description = Description
}

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

asset.onInitialize(function()
  if not openspace.directoryExists(imagesDestination) then
    openspace.printInfo("Extracting " .. Name)
    openspace.unzipFile(syncedDirectory .. "2048.zip", imagesDestination, true)
  end

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