# title:  ISS Position
# user:   thrukadmin
# groups: [{"*" : "read-only"}]

# get actual position
$dashboard = load_data();
my $panlet_1 = $dashboard->{'panlet_1'}->{'xdata'};

# get actual position
my $raw = `curl -s http://api.open-notify.org/iss-now.json`;
my $data = decode_json($raw);

# set current iss position
$panlet_1->{'map'}->{'lat'} = $data->{'iss_position'}->{'latitude'};
$panlet_1->{'map'}->{'lon'} = $data->{'iss_position'}->{'longitude'};
$panlet_1->{'label'}->{'labeltext'} = sprintf("<center>Lat: %.3f / Lon: %.3f<br>Last Update: %s</center>",
                                               $panlet_1->{'map'}->{'lat'},
                                               $panlet_1->{'map'}->{'lon'},
                                               POSIX::strftime("%H:%M:%S UTC", gmtime($data->{'timestamp'})),
                                               );

# set map center
my $_nearest_int = sub {
    my($x, $val) = @_;
    $x = int($x);
    my $rem = $x % $val;
    return($x-$rem);
};
$dashboard->{'tab'}->{'xdata'}->{'map'}->{'lat'}  = &{$_nearest_int}($data->{'iss_position'}->{'latitude'},  20);
$dashboard->{'tab'}->{'xdata'}->{'map'}->{'lon'}  = &{$_nearest_int}($data->{'iss_position'}->{'longitude'}, 20);
$dashboard->{'tab'}->{'xdata'}->{'map'}->{'zoom'} = 4;

# make dashboard update every x seconds
$dashboard->{'ts'} = time() - time() % 10;

__DATA__
{
   "tab" : {
      "xdata" : {
         "refresh" : 10,
         "map" : {},
      }
   },
   "panlet_1" : {
      "xdata" : {
         "appearance" : {
            "type" : "icon"
         },
         "cls" : "TP.StaticIcon",
         "general" : {
            "src" : "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAeCAYAAABqpJ3BAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4AgKCRgtTUjlJAAACMlJREFUWMPVmGuMG9UVx3/3zoxnbK937fV6H97dFAIhAZqG8FIThRRo1AcCQqNS+kJFfasf+hBCRUWiVR9f2qpIpVKLVNEvVVrRUhSgKICESKs0hAAhQEPT3U2AXe/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QajXdFyfSnUAo0TRKPWwxl+xBCoOkrt9GDB15vrxFCSN44McMPv//gijv33HsH1++4iRPHc5RKFX507+/am2o8ESWZSjQVHywt1SgslNF1rWNFEfRlkvh+0J7imUySIFDMzy2eukrUag6zM4W2HrBrLrMzhaYeCM56nzcto02ihqEjNYloolutOm22aQHR+fgWqMXFpVCRNWl8cXHpDPRAc0UwTYNU6sz0wNme1sJ4+juCRCKGZZn4zcmb6IoRi76jHgDfD8d0Sw/4QYDr1tF0eVo98G7HMPR2XZ+dJAPPa+C6XrsCPK+B5zVoNBon6QEhcBwX1w0FTBAEOLbDQqNOJGK0l7ezOY/t2c+/j03ieT4L+RKe1zhLSakolZeoVmo0vPD75XKZatXGcU4OYIVYkB227LDP7hw6eJRDB4/+t8XW/H7n7ilXiBq9taBFrQhdiThSCqSUWFGTZDKBpv/ve+DM+kSQ7EkQtSxKxWUAenoSxGJRik17hSKTuoZpRdoNpmmhsNc0+a4N9/+JAIyIAR00bkRCNuvUJ20arbse5dIymiYJVNC2dUNrL2rn+meVaqWGbbvh/ACqFRvXdbHtkwZZqbjMr3/1MGYz4omxKY796y0s00AIwZGXx895AC88f5T7fl4n8AMcp04ul2difApUuIaUS5UwUe/1H3f/A2qiDnEIg9p7AAAAAElFTkSuQmCC"
         },
         "label" : {
            "bgcolor" : "#7eb4d9",
            "bordercolor" : "#71a4c9",
            "bordersize" : 1,
            "fontcolor" : "#000000",
            "fontitalic" : "",
            "fontsize" : 12,
            "labeltext" : "",
            "orientation" : "horizontal",
            "position" : "below",
         },
         "popup" : {
            "type" : "off"
         },
         "layout" : {},
         "map" : {}
      }
   }
}
