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 commentaires

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 le 9 Août 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!

Connectez-vous pour commenter.

 Réponse acceptée

Adam Danz
Adam Danz le 9 Août 2019

2 votes

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 commentaires

YC
YC le 9 Août 2019
Modifié(e) : YC le 9 Août 2019
good idea, I will try and keep you updated.it works!
Adam Danz
Adam Danz le 9 Août 2019
Great! Thanks for the feedback!
Özge
Özge le 10 Juin 2020
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?
Adam Danz
Adam Danz le 10 Juin 2020
Modifié(e) : Adam Danz le 10 Juin 2020
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.
Adam Danz
Adam Danz le 11 Juin 2020
I don't see where you implemented my answer. Was there something not clear in my answer?
Özge
Özge le 11 Juin 2020
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.
Adam Danz
Adam Danz le 11 Juin 2020
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.
Özge
Özge le 11 Juin 2020
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.
Adam Danz
Adam Danz le 12 Juin 2020
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.
meghannmarie
meghannmarie le 28 Juil 2020
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?
Adam Danz
Adam Danz le 28 Juil 2020
Susan 耿
Susan 耿 le 3 Juin 2021
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!
Adam Danz
Adam Danz le 3 Juin 2021
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.
Susan 耿
Susan 耿 le 4 Juin 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.
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by