How to use Mapping Toolbox functions such as "plotm" in App Designer?

I am building an app in App Designer that needs to use Mapping Toolbox functions such as "plotm" to display geographic data on the app's axes. However, whenever I call "axesm" to set up my map axes, it opens up a new figure outside of my app.
Is it possible to use Mapping Toolbox functions on an App Designer axes? If not, is there some workaround to replicate this behavior?

 Accepted Answer

Unfortunately, there is currently no way to directly call Mapping Toolbox functions such as "plotm" on an App Designer UIAxes object. To work around this, use one of the following techniques based on your specific use case.
1) Create a "geoaxes" object as a child of the app's UIFigure.
load coastlines
% Create "geoaxes" object
fig = uifigure;
ax = geoaxes(fig);
geoplot(ax, coastlat, coastlon);
2) Copy the original axes as a child of the app's UIFigure.
load coastlines
% Construct map in regular axes
ax1 = worldmap('world');
plotm(coastlat,coastlon)
% Reparent to axes in "uifigure"
fig2 = uifigure;
copyobj(ax1, fig2);
% Remove original axes
fig1 = ax1.Parent;
delete(fig1);
If you do not want to remove the original figure but also do not want to display it, then you can change its visibility as follows:
% Hide original axes
fig1 = ax1.Parent;
fig1.Visible = 'off';
3) Replot the projected (x, y) map data on the app's UIAxes.
load coastlines
% Construct map in regular axes
ax1 = worldmap('world');
hPlot = plotm(coastlat, coastlon);
% Copy data into "uiaxes"
ax2 = uiaxes;
plot(ax2, hPlot.XData, hPlot.YData);
% Remove original axes
fig1 = ax1.Parent;
delete(fig1);

More Answers (0)

Products

Release

R2019b

Community Treasure Hunt

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

Start Hunting!