angular-google-maps icon indicating copy to clipboard operation
angular-google-maps copied to clipboard

Toggle markers visibility dynamically

Open Jamby93 opened this issue 10 years ago • 5 comments

I'm trying to toggle the visibility of markers dynamically but it seems it doesn't work as expected. See this http://plnkr.co/edit/7sW0Go2wzWHpK32iuv2w?p=preview Changing the marker options visibility property seems to influence just newly created markers, not the already created ones. Setting the doRebuildAll option on every change allows to see the change take place, but I don't think it's the right way, since it forces me to put a ng-change on every switch (In real application I have multiple markers directive with multiple options).

Jamby93 avatar Oct 25 '15 16:10 Jamby93

I'm also hitting this issue. Putting a simple 'ng-if' on the ui-gmap-markers is an alternative (costly) workaround. It would be great if a 'visible' parameter was added to the markers directive.

ahaverty avatar Mar 19 '16 16:03 ahaverty

I also tried a 'ng-hide' on the ui-gmap-directive but it didn't work as I expected, I don't know enough about angular google maps. However, I did discover a possibly silly workaround that doesn't rebuild the labels. Note: I'm using my markers as labels only, using the options.labelContent to define the labels template and text. I'm not sure how easy it is to apply a class to the icons?.. From there, I have a custom css class, and simply do a ng-if to toggle that class' visibility

<style ng-if="hideLabels">
.custom-class {visibility: hidden;}
</style>

Someone please put me out of my misery if there is a smart way of toggling marker visibility that we have possible missed?

ahaverty avatar Mar 19 '16 16:03 ahaverty

Have you tried with ng-show directive? You can also play with the opacity option. It will hide the marker but not the marker's label. It can be passed in the options directive.

e.g. options="{opacity: 0}" // will hide the marker, set it to 1 to display it.

markmssd avatar Mar 20 '16 20:03 markmssd

I solved it this way: http://plnkr.co/edit/mF0ryqornVveRhhrxZt6?p=preview

dariospadoni avatar Jan 19 '17 14:01 dariospadoni

While @dariospadoni's solution technically works for me, it's speed depends on how many markers you want to toggle. Would adding a global 'visible' parameter to the directive to toggle all markers at once be faster or also boil down to the same problem?

irmingard avatar Sep 08 '17 14:09 irmingard