简体   繁体   中英

How to programmatically invoke zoom event in MatLab?

I am using "plot_google_map.m" that uses the Google Maps API to plot a map in the background of the current figure. A figure generated with this auto-refreshes the map upon zooming event, and I added some codes to make it refresh data upon panning event, too.

Now I would like to programmatically change the range of axes without using zoom or pan buttons, but the problem is map is not refreshed automatically. So, I am thinking of generating zooming or panning event programatically, but I haven't found a way to do that. Any idea on this?

Let me elaborate my question. In the 'plot_google_map.m', there is subfunction which is a callback of zooming event.

function plot_google_map  
% Listen to Zoom events    
h  = figure(1); plot(1:10);
hz = zoom(h);
set(hz,'ActionPostCallback',@mypostcallback);

function mypostcallback(obj,evd)
disp('Refreshes map data');

What I want to do is, to call this subfunction outside the 'plot_google_map'.
Any idea is welcomed, and thank you for your answers in advance!

You heard about the zoom command?

>> help zoom
 zoom   Zoom in and out on a 2-D plot.

Actually it seems that's how the program recognizes you zooming.

Assuming that your axes handle is hAxes , then you can do the zooming by changing the xLim and yLim properties of your axes rather than a zooming ratio, like the following:

If your plot is using the x axis from 0-100 then you can zoom in on a particular sub range og 0-100 for example:

set(hAxes,'xLim',[20 40])

and also for y axis you can zoom on a specific y range:

set(hAxes,'xLim',[30 70])

and if you want to zoom on a specific area on the plot, for example x[20-50],y[10-50], you can do it by doing the two previous action like:

set(hAxes,'xLim',[20 50])
set(hAxes,'yLim',[10 50])


So , change the xLim and yLim values of the axe depending on the size of your plot or your image, and that's how actually zooming work with axes.

You can even try this demo script:

 clear;clc;
 figure;
 h = axes;
 y = sin( 0:2*pi / 100:pi );
 plot(y);
 %// =============================
 pause(1);
 set(h , 'xlim' , [20 80]);
 %// =============================
 pause(1);
 set(h , 'xlim' , [30 40]);
 %// =============================
 pause(1);
 set(h , 'xlim' , [10 100]);
 %// =============================
 pause(1);
 set(h , 'ylim' , [.1 .4]);
 %// =============================
 pause(1);
 set(h , 'ylim' , [.2 .7]);
 %// =============================
 pause(1);
 set(h , 'ylim' , [.3 .9]);
 %// =============================
 pause(1);
 set(h , 'ylim' , [.1 .2]);
 set(h , 'xlim' , [10 80]);
 %// =============================
 pause(1);
 set(h , 'ylim' , [.3 .7]);
 set(h , 'xlim' , [40 90]);
 %// =============================

Why not simply call plot_google_map again after every time you change the axes range? This will cause the map to be updated with the new extent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM