I am trying to get positions at the following map with ginput command. But the problem is I want to see the position of the point before clicking it.
Is it possible to that? After I clicked N points I can see positions, but I can not click them anymore. I should see the position first and after that I need to click it.
Thanks in advance!
Here is the code:
clc
clear
close all
geoaxes('Units','normalized');
N=5;
set (gcf, 'WindowButtonMotionFcn', @mouseMove);
for i=1:N
[lat,lon]=ginput(1)
hold on
geolimits('manual')
geoscatter(lat,lon,'filled','b')
end
set (gcf, 'WindowButtonMotionFcn', @mouseMove);
function mouseMove (object, eventdata)
C = get (gcf, 'CurrentPoint');
title(gca, ['(X,Y) = (', num2str(C(1,1)), ', ',num2str(C(1,2)), ')']);
end
If you have the mapping toolbox you can use gcpmap
to simplify this I think.
The main issue just requires a drawnow
in the callback function. Then I used waitforbuttonpress
and CurrentPoint
to get the location of the click instead of ginput
.
h = geoaxes('Units','normalized');
geolimits('manual')
set (gcf, 'WindowButtonMotionFcn', @(x,y) mouseMove(x,y,h));
hold on
N=5;
for i=1:N
waitforbuttonpress;
pt = h.CurrentPoint;
lat = pt(1,1);
lon = pt(1,2);
geoscatter(lat,lon,'filled','b')
end
hold off
function mouseMove (~, ~, handle)
C = handle.CurrentPoint;
title(gca, ['(X,Y) = (', num2str(C(1,1)), ', ',num2str(C(1,2)), ')']);
drawnow
end