Looking to get mouse position feedback interactively over a plot and send to text boxes in GUI

I have a figure in a GUI that is a map (lat/lon). I want to send that lat/long to 2 text boxes in the GUI as the mouse goes over the map interactively and then capture the final coordinate with a mouse click (using ginput). Here is part of my code...
function load_map_Callback(hObject, eventdata, handles)
% hObject handle to load_map (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
plotMapDTED_copper_gui(map,'deg',handles.axes1);
if(get(handles.option_mouse_click_linear,'Value'))
datacursormode on
%Enter target location
message = sprintf('Select the location on the map as the Target:\n\nClick OK to continue.\nClick Exit to exit this function');
button = questdlg(message, 'Enter Target', 'OK', 'Exit','OK');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Exit')
reset2default(handles);
return;
end
if LocalMouseOverMap (hObject, handles)
set(hObject,'Pointer','crosshair');
cp = get(hObject,'CurrentPoint');
xxxx=cp(1,1);
yyyy=cp(1,2);
set(handles.text19,'string',num2str(xxxx,'%.3f'));
set(handles.text21,'string',num2str(yyyy,'%.3f'));
[xt yt] = ginput(1);
end
scatter(xt, yt,'MarkerFaceColor',[0 0 1],'Marker','*');
then at the end I had this call
function status = LocalMouseOverMap (hObject, handles)
% get the current mouse position
cp = get(hObject,'CurrentPoint');
% Get the position of the map axes in pixels
set(handles.axes1,'units','pixels');
pos = get(handles.axes1,'position');
set(handles.axes1,'units','normalized');
% Determine if the mouse position is with the axes boundaries
if (cp(1) > pos(1) && cp(1) < pos(1) + pos(3) ...
&& cp(2) > pos(2) && cp(2) < pos(2) + pos(4))
status = true;
else
status = false;
end

1 comentario

your code does not look unreasonable at first glance. Are you encountering a specific problem?

Iniciar sesión para comentar.

Respuestas (2)

Yes - I a getting an error that states that I cannot access "CurrentPoint" with this uicontrol. Now I know the figure has a propoerty - "CurrentPoint" but I don't know why I can't get to it.
Check what hObject actually is - I suspect its not the figure handle - and hence doesn't have the property "CurrentPoint".
If hObject is a child of figure (I would have thought so), you can get to the figure by going up through its parent.
e.g.
h = figure;
child = uicontrol ( 'parent', h, 'style', 'edit' )
get ( get ( child, 'parent' ), 'CurrentPoint' )

2 comentarios

Or better than assuming you know the nesting level, use
get(ancestor(hObject,'figure'),'CurrentPoint')
Very good.
you learn something new everyday....

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Performance en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 1 de Nov. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by