how to draw map in app designer?

33 views (last 30 days)
YC
YC on 9 Aug 2019
Commented: Adam Danz on 4 Jun 2021
hi, I was trying to draw a map in app desinger
worldmap(app.UIAxes,'World'); but it reports error message.
so I searched and found there is one post saying that map axes cannot be used in uifigures.
If i really want to plot a map and some other points with lat/lon on the axes of the add designer (which makes the app look more professional), is there any work around?
Thanks!
  2 Comments
Adam Danz
Adam Danz on 9 Aug 2019
It always helpful to share the entire error message. In 2019a that error is
Error using worldmap
Expected input number 1, LATLIM, to be one of these types:
double
Instead its type was matlab.ui.control.UIAxes.
Error in checkgeoquad (line 25)
validateattributes(latlim, {'double'}, {'real','vector','finite'}, ...
Error in regionmap>checkMapLimits (line 281)
checkgeoquad(latlim, lonlim, mapFunctionName, 'LATLIM', 'LONLIM', 1, 2)
Error in regionmap (line 121)
[latlim, lonlim] = checkMapLimits(args{:}, mapFunctionName);
Error in worldmap (line 122)
ax = regionmap(mfilename, varargin);
Error in myFakeApp/ButtonPushed (line 39)
worldmap(app.UIAxes,'World')
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 335)
Error while evaluating Button PrivateButtonPushedFcn.
YC
YC on 9 Aug 2019
sorry, the code is just one single line:
function PlotButtonPushed3(app, event)
worldmap(app.UIAxes,'World');
end
the error message is the same as you just posted, thank you!

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 9 Aug 2019
There is no axes input to the worldmap function (unfortunately). The function will create a new figure to display the map. After the figure is created, you can copy it to your app axes and then delete the figure created by worldmap().
h = worldmap('World'); % Store the output handle!
hCopy = copyobj(h.Children, app.UIAxes); % Copy all of the axis' children to your app axis
delete(h.Parent) % get rid of the figure created by worldmap()
  18 Comments
Susan 耿
Susan 耿 on 4 Jun 2021
For example, I draw a local map
latlim = [10 30];
longlim = [50 100];
ax = worldmap(latlim,longlim);
axcopy = copyobj(ax.Children,app.UIAxes);
delete(ax.Parent);
The size of ax.Parent is normal, but the copied one shown in app.UIAxes is very small. Do you know how to adjust the size? Thanks QAQ.
Adam Danz
Adam Danz on 4 Jun 2021
I could not reproduce the same problem you described with the code you provided.
latlim = [10 30];
longlim = [50 100];
ax = worldmap(latlim,longlim);
app.UIFigure = uifigure();
app.UIAxes = uiaxes(app.UIFigure,'Position',[60 60 400 300]);
axcopy = copyobj(ax.Children,app.UIAxes);
delete(ax.Parent);
Notice how the map axes are rendered. You can remove the background axes using,
app.UIAxes.Visible = 'off';
Please post a new question if you need any further help.

Sign in to comment.

More Answers (0)

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!