function zoneString = utmzoneui(initialZoneString)
%UTMZONEUI Choose or identify UTM zone by clicking on map
%
%   ZONE = UTMZONEUI will create an interface for choosing a UTM zone on
%   a world map. It allows for clicking on an area for its appropriate
%   zone, or entering a valid zone to identify the zone on the map.
%
%   ZONE = UTMZONEUI(INITZONE) initializes the displayed zone to the zone
%   character vector or scalar string given in INITZONE.
%
%   See also UTMZONE

% Copyright 1996-2023 The MathWorks, Inc.

if nargin == 0
    app = map.graphics.internal.utmgui;
    zoneString = '';
else
    initialZoneString = validateInitialZoneString(initialZoneString);
    app = map.graphics.internal.utmgui(initialZoneString);
    zoneString = initialZoneString;
end

% Check validity in case the window was closed
if isvalid(app)
    zoneString = app.SelectedUTMZone;
    delete(app);
end


function initialZoneString = validateInitialZoneString(initialZoneString)

try
    validateattributes(initialZoneString,{'char','string'},{'scalartext'},'','INITZONE')
    utmzone(initialZoneString);
    initialZoneString = upper(initialZoneString);
catch exception
    throwAsCaller(exception)
end