Geoaxes zoom not working after adding ButtonDownFcn.

11 ビュー (過去 30 日間)
Peter Valent
Peter Valent 2021 年 5 月 19 日
コメント済み: Adam Danz 2022 年 5 月 16 日
I have an app built in AppDesigner with a map plotted in geoaxes. I need to zoom in and out but I also need to do some action when I click on the map. The problem is that:
  • zoom works perfectly when no buttondownfcn is added
f = uifigure;
gx = geoaxes();
geoscatter(gx,10,10)
  • zoom does not work at all when buttondownfcn is added.
f = uifigure;
gx = geoaxes(f);
geoscatter(gx,10,10)
gx.ButtonDownFcn = 'disp(''hello'')';
I need to use both functionalities. What should I do?

採用された回答

Adam Danz
Adam Danz 2021 年 5 月 20 日
編集済み: Adam Danz 2021 年 6 月 14 日
I'm not sure why assigning the button down function affects the zooming but it can be fixed by resetting the default interactivity of the axes.
gx = geoaxes;
geoscatter(gx,10,10)
enableDefaultInteractivity(gx) % * <-- must be before assigning ButtonDownFcn
gx.ButtonDownFcn = 'disp(''hello'')';
* See Jan Studnicka's comment below.
  7 件のコメント
Malte Nagel
Malte Nagel 2022 年 5 月 16 日
Has someone already reported this bug? It appears to still be there and it is causing a lot of trouble for me.
Adam Danz
Adam Danz 2022 年 5 月 16 日
> Has someone already reported this bug?
Yes.
Does the workaround in my answer now work for you?

サインインしてコメントする。

その他の回答 (1 件)

Jan Studnicka
Jan Studnicka 2021 年 5 月 21 日
"Sometimes MATLAB® automatically disables the built-in interactions. For example, they might be disabled for charts that have special features, or when you implement certain callbacks such as a WindowScrollWheelFcn."
However, with geoaxes you can easily implement zooming in / out by using WindowScrollWheelFcn callback of the uifigure. This is an example created from the documentation's example on "how to use WindowScrollWheelFcn":
function scroll_wheel
% Shows how to use WindowScrollWheelFcn in combination with geoaxes and
% ButtonDownFcn callback.
f = uifigure('WindowScrollWheelFcn',@figScroll,'Name','Scroll Wheel Demo');
gx = geoaxes(f);
geoscatter(gx,10,10)
gx.ButtonDownFcn = 'disp(''hello'')';
title(gx,'Rotate the scroll wheel')
function figScroll(~,event)
if event.VerticalScrollCount > 0
gx.ZoomLevel = gx.ZoomLevel-0.1;
elseif event.VerticalScrollCount < 0
gx.ZoomLevel = gx.ZoomLevel+0.1;
end
end
end
  1 件のコメント
Adam Danz
Adam Danz 2021 年 5 月 21 日
編集済み: Adam Danz 2021 年 5 月 21 日
+1 Good idea, Jan. Note that this zooms into the center of the axes rather than zooming into the location of the cursor within the axes.
It's still not clear to me why a ButtonDownFcn would prevent zoom interaction since that callback function does not respond to the scroll wheel. I also find it odd that adding the ButtonDownFcn disables zoom interaction but calling enableDefaultInteractivity can turn it back on in regular figures - that sounds buggy to me. Lastly, I wonder why applying enableDefaultInteractivity doesn't fix the problem with uifigures.
BTW, I also get the same interative warning when zooming in/out using this method (r2021a)
Warning: A value of class "double" was indexed with no subscripts specified. Currently the result of this operation is the indexed value itself, but in a
future release, it will be an error.
> In matlab.internal.asynchttpsave/AsyncHTTPContentFileWriter/handleThreadIsFinishedEvent
In matlab.internal.asynchttpsave.AsyncHTTPContentFileWriter
In asyncio/Channel/onPropertyChanged (line 471)
In asyncio.Channel>@(source,data)obj.onPropertyChanged(data.Name,data.Value) (line 401)
There's clearly some cleaning up to do by MW.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeVisual Exploration についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by