GliderMap = figure;
clf
%% MBARI
mosslat = 36.80594819607352;
mosslon = -121.786377002975;

%% CalCOFI Line 67
CalCOFI67 = ...
[50	36.7869600000000	-122.056330000000
55	36.6202900000000	-122.414820000000
60	36.4536300000000	-122.772540000000
65	36.2869600000000	-123.129480000000
70	36.1202900000000	-123.485650000000
75	35.9536300000000	-123.841060000000
80	35.7869600000000	-124.195710000000
85	35.6202900000000	-124.549620000000
90	35.4536300000000	-124.902780000000
95	35.2869600000000	-125.255200000000
100	35.1202900000000	-125.606890000000];

CalCOFI67Description = strsplit(num2str(CalCOFI67(:,1)')); 

%% M1 and C1
M1Lat = 36.75901;
M1Lon = -122.02019;

% need to add C1

%% Spray 034
SprayLatHist = s.lat(end-4:end-1);
SprayLonHist = s.lon(end-4:end-1);
SprayLat = s.lat(end);
SprayLon = s.lon(end);

%% Datetimes
date = datetime(datevec(s.sdn_(2,:))); 
date.TimeZone = "UTC"; % Set timezone for the datetime var type
date.TimeZone = "America/Los_Angeles"; % change timezone to local

SprayHistDescription = cellstr(date(end-4:end-1))';
SprayDescription = cellstr(date(end))';

Maptitle = ['Last Update: ', datestr(date(end)),' PST'];

%% Create a geographic axes
ax = geoaxes('Basemap','satellite',MapCenter=[SprayLat SprayLon],Position=[0, 0, 1, .95]);
ax.Title.String = Maptitle;
ax.Title.Visible = "on";
%% Hold the current plot
hold(ax, 'on');
%% Plot CalCOFI Line 67
geoplot(ax, CalCOFI67(:,2), CalCOFI67(:,3), 's', 'MarkerFaceColor', '#FFFF00', 'MarkerEdgeColor', 'none', 'DisplayName', 'CalCOFI Line 67', 'MarkerSize', 10);
%% Add descriptions for CalCOFI Line 67
offset = -0.01; % adjust this value to control the offset
for i = 1:length(CalCOFI67Description)
    text(CalCOFI67(i,2) + offset, CalCOFI67(i,3) + offset, CalCOFI67Description{i}, 'Color', '#FFFF00', 'FontSize', 10, 'HorizontalAlignment', 'right');
end
%% Plot M1
geoplot(ax, M1Lat, M1Lon, 'p', 'Color', '#00FFFF', 'MarkerFaceColor', '#00FFFF', 'DisplayName', 'M1 Mooring', 'MarkerSize', 10);
% Plot MBARI
geoplot(ax, mosslat, mosslon, "^", 'Color', '#FF00FF', 'MarkerFaceColor', '#FF00FF', 'DisplayName', 'MBARI', 'MarkerSize', 10);
%% Plot Spray 034 Location
geoplot(ax, SprayLat, SprayLon, 'o', 'MarkerFaceColor', '#FFA500', 'MarkerEdgeColor', '#FFA500', 'DisplayName', 'Spray 034 Location', 'MarkerSize', 10);
%% Plot Spray 034 Location History
geoplot(ax, SprayLatHist, SprayLonHist, '.', 'Color', '#D3D3D3', 'DisplayName', 'Spray 034 Location History', 'MarkerSize', 10);
%% Plot Rachel Carson Location
geoplot(ax, CrsnLat, CrsnLon, 'v', 'MarkerFaceColor', '#32CD32', 'MarkerEdgeColor', '#32CD32', 'DisplayName', 'Carson Location', 'MarkerSize', 10);
%% Add a legend
legend(ax, 'Location', 'northwest');
%% Release the hold on the plot
ax.Box = "on";
grid on
hold(ax, 'off');

ZoomRadius = 25;
% Define the latitude and longitude offsets in degrees (approximately 50 km)
offset_km = ZoomRadius / 111; % Assuming 1 degree of latitude is approximately 111 km

% Calculate bounding box coordinates
lat_min = SprayLat - offset_km;
lat_max = SprayLat + offset_km;
lon_min = SprayLon - offset_km / cosd(SprayLat); % Correcting for longitude distance change with latitude
lon_max = SprayLon + offset_km / cosd(SprayLat);

% Set geographic limits
geolimits(ax, [lat_min lat_max], [lon_min lon_max]);

%

% Define the URL
url = 'https://odss.mbari.org/odss/tracks?platformID=54065b5560d0e168c88d4085&returnSRS=4326&lastNumberOfFixes=5&returnFormat=html';
% Read the HTML content from the website
html = webread(url);
% Use the htmlTree class to parse the HTML content
tree = htmlTree(html);
% Extract the table rows
rows = findElement(tree, 'tr');
% Initialize cell arrays to store the extracted data
dates = {};
lats = {};
lons = {};
% Loop through the rows to extract the date, lat, and lon
for i = 2:length(rows)  % Start from 2 to skip the header row
    % Extract cells from the row
    cells = findElement(rows(i), 'td');
    
    % Extract date, lat, and lon
    date = extractHTMLText(cells(1));
    lon = extractHTMLText(cells(2));
    lat = extractHTMLText(cells(3));
    
    % Store the extracted data in cell arrays
    dates{end+1} = date;
    lats{end+1} = lat;
    lons{end+1} = lon;
end

CrsnDates = dates;
CrsnLat = str2double(lats{1});
CrsnLon = str2double(lons{1});

%

% % Create inset axes for submap
% ax_inset = geoaxes('Position', [.75, 0, .25, .25],'Basemap','bluegreen',MapCenter=[SprayLat SprayLon]); % Define position for inset map
% 
% % Plot submap
% geoplot(ax_inset, SprayLatHist, SprayLonHist, '.', 'Color', [0 0.75 0.75], 'DisplayName', 'Spray 034 Location History');
% hold(ax_inset, 'on');
% geoplot(ax_inset, SprayLat, SprayLon, 'd', 'MarkerFaceColor', [1 0.5 0], 'MarkerEdgeColor', [1 0.5 0], 'DisplayName', 'Spray 034 Location', 'MarkerSize', 10);
% hold(ax_inset, 'off');
% 
% % Define the latitude and longitude offsets in degrees (approximately 50 km)
% offset_km = 1 / 111; % Assuming 1 degree of latitude is approximately 111 km
% 
% % Calculate bounding box coordinates
% lat_min = SprayLat - offset_km;
% lat_max = SprayLat + offset_km;
% lon_min = SprayLon - offset_km / cosd(SprayLat); % Correcting for longitude distance change with latitude
% lon_max = SprayLon + offset_km / cosd(SprayLat);
% 
% % Set geographic limits
% geolimits(ax_inset, [lat_min lat_max], [lon_min lon_max]);
% 
% grid on
% 
% ax_inset.LatitudeAxis.TickLabels = {};
% ax_inset.LongitudeAxis.TickLabels = {};
% ax_inset.LatitudeLabel.String = '';
% ax_inset.LongitudeLabel.String = '';
% ax_inset.Title.String = 'Glider Track';
% ax_inset.Title.Visible = 'on';
% ax_inset.Title.Color = [1 1 1];
% saveas(GliderMap,'GliderMap','png')