function [] = MakeMapFig(s,plotpath)
% Map of Glider location relative to other important landmarks. s: struct
% of glider data, ZoomRadius draws a box around Spray for plotting.
% Add C1
% Ben Werb 5/28/24 | Bwerb@mbari.org

fig = figure('Visible','off');
%% 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 
% M1 moves around about .5 km from its center point. Could grab live
% location or just center point
M1Lat = 36.75901;
M1Lon = -122.02019;
% need to add C1

%% Spray 034
SprayLatHist = s.lat(end-9:end-1);
SprayLonHist = s.lon(end-9:end-1);
SprayLat = s.lat(end);
SprayLon = s.lon(end);
%% Get Rachel Carson Location
[CrsnLat,CrsnLon] = GetCarsonLocation();
%% 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

% Not plotting these right now, 5/30/24
% SprayHistDescription = cellstr(date(end-9:end-1))'; % datetimes of last 10 points
% SprayDescription = cellstr(date(end))'; %
% 
% Maptitle = ['Last Update: ', datestr(date(end)),' PST'];

% [SurfaceDrift,TimeatSurface] = SurfaceStats(s); % Fix this calculation

% Create the annotation string with new lines
Maptext = {
    ['Mission: ' s.depID]
    ['Start Date: ' datestr(min(date(:))) ' PST']
    ['Last Profile: ' datestr(date(end)) ' PST']
    ['Total Profiles: ' num2str(length(s.lat))]
    ['Current location: ' num2str(s.lat(end)) ', ' num2str(s.lon(end))]
    % ['Surface Drift: ' num2str(SurfaceDrift) ' km']
    % ['Time at surface: ' num2str(TimeatSurface) ' s']
};
%% Create a geographic axes
ax = geoaxes('Basemap','satellite',MapCenter=[SprayLat SprayLon],...
    Position=[0, 0, 1, 1],Grid='on',MinorGridAlpha=0,GridAlpha=0); % Map centers on Spray location and adjusts map size to fit a title for the date

% 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 station labels 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', 'northeast',FontSize=8);
%% Add extra info:
annotation('textbox','Position',[0.015, 0.88, 0.25, 0.17] ,'String',...
    Maptext, 'FitBoxToText', 'on', 'FontSize', 8, 'EdgeColor', 'none',...
    'BackgroundColor', 'white','HorizontalAlignment','left',...
    'VerticalAlignment','bottom'); % Release the hold on the plot

% grid off
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]);

plotname = 'map';
% SaveFigFolderServer(fig,plotpath,plotname)
saveas(fig,[plotpath,'\',plotname,'.png'],'png')

end