how to draw map in app designer?

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

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.
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

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

YC
YC on 9 Aug 2019
Edited: YC on 9 Aug 2019
good idea, I will try and keep you updated.it works!
Great! Thanks for the feedback!
I am trying to do the copyobj function in my own project, but the world map drawn to the uiaxes window comes upside down. North section below, south section above. What could be the reason for this?
Set the YDir property of the uiaxes to 'reverse'.
ax.YDir = 'reverse'; % where ax is your uiaxes handle.
copyobj() only copies the object, not the axis properties.
This is my code:
NN = file.Ionex.TECU./10;
NN2 = file2.Ionex.TECU./10;
NN3 = file3.Ionex.TECU./10;
R1 = makerefmat('RasterSize',size(NN), ...
'Latlim', [min(lat(:)) max(lat(:))], ...
'Lonlim', [min(long(:)) max(long(:))], 'ColumnsStartFrom','North' );
R2 = makerefmat('RasterSize',size(NN2), ...
'Latlim', [min(lat(:)) max(lat(:))], ...
'Lonlim', [min(long(:)) max(long(:))], 'ColumnsStartFrom','North' );
R3 = makerefmat('RasterSize',size(NN3), ...
'Latlim', [min(lat(:)) max(lat(:))], ...
'Lonlim', [min(long(:)) max(long(:))], 'ColumnsStartFrom','North' );
app.is_sending = true;
UTCHR = 0;
while (app.is_sending)
iUTCHR = mod(UTCHR,map)+1;
tecUHR = NN(:,:,iUTCHR);
h = worldmap([min(lat) max(lat)], [min(long) max(long)]);
geoshow(app.UIAxes_3,h,tecUHR,R1,'DisplayType','texturemap');
load coastlines
plotm(coastlat,coastlon,'Color','black')
geoshow(app.UIAxes_3,coastlat,coastlon,'Color','black')
colormap(app.UIAxes_3 ,'jet')
a = colorbar(app.UIAxes_3);
a.Label.String = 'TECU';
axis equal
axis tight
title(app.UIAxes_3,[datestr(datenum(date(iUTCHR)) ,'yyyy-mm-dd HH:MM:SS')]);
hCopy = copyobj(h.Children, app.UIAxes_3);
delete(h.Parent)
end
Can you help with that? I added the output of the code. Thank you.
I don't see where you implemented my answer. Was there something not clear in my answer?
I wrote my code because I didn't know where to apply. I have tried a few places but the result I got has not changed.
In the line
ax.YDir = 'reverse'; % where ax is your uiaxes handle.
Ax is your axis handle. You need to replace that variable with your access handle variable. this needs to be done after the map is generated.
I tried it after the geoshow, but the result part in the figure still comes upside down. Is there another method for me to show this?
try
app.UIAxes_3.YDir = 'normal';
If that doesn't work, turn on the axes so I can see the ticks
axes(app.UIAxes_3, 'on')
and then show me the figure and the segment of code that includes the YDir.
app.UIAxes_3.YDir = 'normal';
This worked !! Thank you so much.
Glad I could help. I should have suggested that in the first place instead of setting YDir to 'reverse' which is what caused the problem.
I want the map plotted with xaxis being [-90,90] and y axis being [0,360] or [-180,180]. Right now, this plots the x and y axis from [-3,3]. This is a problem for me because I am using drawrectangle to return coordinates. is there a way to plot it on coordinate axis?
Hi, I've found that copyobj works well for the whole world map. But when I copy a map of specific latitude and longitude range, the children shown in app.UIAxes is very little, like this.
I wonder whether you have any idea why this happens. Thanks a lot!
I don't know what it means to copy a map of specific lat/lon range. You probably just need to set the axis limits.
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.
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

Asked:

YC
on 9 Aug 2019

Commented:

on 4 Jun 2021

Community Treasure Hunt

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

Start Hunting!