Geoaxes Interactive Drawing Issue
Show older comments
I created fucntion that plots something (in this example, it is sinusoid, but it doesnt matter) and by holding left button on mouse i can draw over it. Now, I want the same thing, but when I use geoplot in geoaxes, but I don't know how to do it. Can someone help me?
Example of code with regular axes:
function draw_on_figure()
x = linspace(0, 2*pi, 100);
y = sin(2*x);
figure('WindowButtonDownFcn', @startDrawing, ...
'WindowButtonMotionFcn', @draw, ...
'WindowButtonUpFcn', @stopDrawing);
plot(x, y, 'b', 'LineWidth', 2);
hold on;
axis([0 2*pi -1.5 1.5]);
grid on;
isDrawing = false;
lineHandle = [];
function startDrawing(~, ~)
if strcmp(get(gcf, 'SelectionType'), 'normal') % normal - left click
isDrawing = true;
currentPoint = get(gca, 'CurrentPoint');
lineHandle = line(currentPoint(1, 1), currentPoint(1, 2), ...
'Color', 'r', 'LineWidth', 2);
end
end
function draw(~, ~)
if isDrawing
% current position of the mouse
position = get(gca, 'CurrentPoint');
x = get(lineHandle, 'XData');
y = get(lineHandle, 'YData');
set(lineHandle, 'XData', [x, position(1, 1)], ...
'YData', [y, position(1, 2)]);
end
end
function stopDrawing(~, ~)
isDrawing = false;
lineHandle = [];
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Mapping Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!