Plotting data labels with the mapping toolbox

I am making a GUI that allows users to search for cities, select the ones they would like to plot, and have it show the cities as a red circle on the map. I also need to give the user the option to deselect and/or copy and paste cities in the plot browser. Right now I am using the following code to plot the cities:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for e= 1:length(plotcity.name)
texthandles{e} = textm(plotcity.loc(e,1),plotcity.loc(e,2),plotcity.name{e},'DisplayName',[plotcity.name{e} '(label)']);
cityhandles{e} = plotm(plotcity.loc(e,:),'or','DisplayName',plotcity.name{e});
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
where:
plotcity.name is a 1xn cell array,
plotcity.loc is a nx2 matrix where each row contains the latitude and longitude of the city,
and texthandles and cityhandles are empty cell arrays.
This plots exactly what I want it to, however if I hide a city in the plot browser, it only hides the point at the city's location, the text remains printed on the map with no easy way to remove it.
I have tried making cityhandles and texthandles hggroup objects, making one the parent of the other, playing with the annotation, visibility, tag, and displayname properties, without success.
If someone could recommend a way to plot the cities on the map in such a fashion that they could be copied or removed (with their label) to another plot, I would greatly appreciate it.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 3 de Jul. de 2012

0 votos

Perhaps linkprop() of the Visible property for the point and its corresponding label.

5 comentarios

That makes sense but when I tried this code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for e= 1:length(plotcity.name)
texthandles(e) = textm(plotcity.loc(e,1),plotcity.loc(e,2),plotcity.name{e});
cityhandles(e) = plotm(plotcity.loc(e,:),'or','DisplayName',plotcity.name{e});
hlink(e) = linkprop([texthandles(e) cityhandles(e)],'Visibility');
end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
it did the same thing, hiding the point while leaving the label. Am I using linkprop incorrectly? or is there a way to plot my object hlink?
Liam Cusack
Liam Cusack el 3 de Jul. de 2012
*The actual property name is 'Visible' but I tried that, again with no luck
To check: the help information says,
It is necessary that the link object remain referenced
within the context of where you want property linking
to occur. You can keep the link object as a variable
in the base workspace, make the link object GLOBAL,
or store the link object in USERDATA property or
in application data (SETAPPDATA).
Are you ensuring your hlink vector is not going out of scope?
Liam Cusack
Liam Cusack el 3 de Jul. de 2012
Editada: Walter Roberson el 3 de Jul. de 2012
Ah thats it, I used:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for e= 1:length(plotcity.name)
texthandles(e) = textm(plotcity.loc(e,1),plotcity.loc(e,2),plotcity.name{e});
cityhandles(e) = plotm(plotcity.loc(e,:),'or','DisplayName',plotcity.name{e});
hlink(e) = linkprop([texthandles(e) cityhandles(e)],'Visible');
set(cityhandles,'UserData',hlink(e))
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
and it worked like a charm, Thanks Walt!!!
You should move the set() past the end of the loop, and remove the (e)
set(cityhandles,'UserData',hlink)
otherwise the UserData would be overwritten in each iteration.

Iniciar sesión para comentar.

Más respuestas (1)

Stephen
Stephen el 3 de Jul. de 2012

0 votos

could you just refresh the original background image and only plot the updated city info? Completely erase the pre-existing map, in other words.

1 comentario

Liam Cusack
Liam Cusack el 3 de Jul. de 2012
The shapefile I'm using for the map takes a while to load and I want it to be a faster interface where the user can select and deselect cities as they please.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by