function plot_map(hTsgGUI, hPlotAxes)
% Function to plot the earth map and ship trackline
%
% Input
% -----
% hTsgGUI ............ Handel to the main user interface
% hPlotAxes .......... Handels to the graphic axes
%
% Output
% ------
%
% Library : 'M_MAP'
%
% TO DO
% note that a decimal degree notation is used, so that a longitude of 120°
% 30'W is specified as -120.5
%
% PROBLEM NOT YET RESOLVED
%    Does M_MAP use 0-360° or -180°-180° covention ?
%
% $Id$

% Retrieve named application data
% -------------------------------
tsg = getappdata( hTsgGUI, 'tsg_data');

% Convert lat/lon in degre decimal
% --------------------------------


% Get the Geographic limit of the TSG time series
% -----------------------------------------------
dateLim = get(hPlotAxes(1), 'Xlim');
ind = find( tsg.DAYD >= dateLim(1) & tsg.DAYD <= dateLim(2));

if ~isempty( ind )

  latMin = min( tsg.LATX(ind) ) - 2;
  if latMin < -90
    latMin = -90;
  end
  latMax = max( tsg.LATX(ind) ) + 2;
  if latMax > 90
    latMax = 90;
  end
  lonMin = min( tsg.LONX(ind) ) - 2;
  if lonMin < -180
    lonMin = -180;
  end
  lonMax = max( tsg.LONX(ind) ) + 2;
  if lonMax > 180
    lonMax = 180;
  end

  % Positionning the right axes
  % ----------------------------
  axes(hPlotAxes(4));

  % Use of Mercator projection
  % --------------------------
  %m_proj('Mercator','lat',[-70 70],'long',[-180 180]);
  m_proj('Mercator','lat',[latMin latMax],'long',[lonMin lonMax]);

  % detailed coast lines
  % m_gshhs_i('patch',[.7 .7 .7]);

  % Less detailed coast lines
  %m_gshhs_l('patch',[.7 .7 .7]);

  % Lesser  detailed coast lines
  % ----------------------------
  m_coast('patch',[.7 .7 .7], 'TAG', 'TAG_PLOT4_LINE_COAST');

  %m_grid('box','fancy','tickdir','in', ...
  %       'ytick', [-70:20:70],...
  %       'xtick', [-180:40:180],...
  %       'Fontsize', [10]);
  m_grid('box','fancy','tickdir','in', 'TAG', 'TAG_PLOT4_LINE_GRID', 'Fontsize', 10);

  % Plot the ship track - Check if LAT-LON in deg-decimal
  % -----------------------------------------------------
  %m_line(tsg.LONX,tsg.LATX, 'TAG', 'TAG_PLOT4_LINE_SHIPTRACK', 'marker','.','markersize',3,'color','b');
  m_line(tsg.LONX,tsg.LATX, 'LineStyle', 'none', 'marker','*','markersize',2,'color','b');

  hLines = get(hPlotAxes(4), 'Children');
  for i=1:length(hLines)
    set(hLines(i), 'Tag', ['TAG_PLOT4_LINE_MAP' int2str(i)]);
  end

end
end
