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

Markers mess when there is more than one map on back - forward.

Open Vatsov opened this issue 10 years ago • 5 comments

Minimal demo

Current behavior

  • When there is more than one map and load the first map then go back and load the second one in the second map has markers from the first one.

Expected/desired behavior

  • Should load only the markers of the open map

Vatsov avatar Aug 27 '16 11:08 Vatsov

This is happening because the map instance is shared between two maps to prevent memory leak. Please make it sure that two map ids are different to have different map instances

allenhwkim avatar Aug 27 '16 12:08 allenhwkim

Thanks, I double check and ids are different. First map is with id map_0 and the second with map_1

Is it way to force map destroy?

I try to remove the data on scope destroy but without success.

function onDestoy() {
    vm.map = null;
    vm.markers= null;
    vm.markerClusterer = null;
}

$scope.$on("$destroy", onDestoy);

Vatsov avatar Aug 27 '16 14:08 Vatsov

If they are normal marker by html, the markers on map will be destroyed automatically, but yours are marker cluster which is not by HTML

Setting variable does not delete markers on map, thus, you need to remove marker instance directly by setting map to null and deleting it

I know It's not convenient :)

I wish Google map does not have a memory leak, so that we don't have to do this

Besides when it comes to marker clustered, which is not supported by Google officially, it's hard to control those on SPA

The easiest way I can think of is to refresh the page when you need to show a different marker clusterer

On Aug 27, 2016, at 10:07 AM, Deyan Vatsov [email protected] wrote:

Thanks, I double check and ids are different. First map is with id map_0 and the second with map_1

Is it way to force map destroy?

I try to remove the data on scope destroy but without success.

function onDestoy() { vm.map = null; vm.markers= null; vm.markerClusterer = null; }

$scope.$on("$destroy", onDestoy);

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

allenhwkim avatar Aug 27 '16 15:08 allenhwkim

Thanks a lot. I've added in scope destroy document.getElementById(vm.mapId).remove();

And it's work. Now still the issue #670

Do you know workaround in order to remove $timeout between set custom marker data and set clusterer?

Vatsov avatar Aug 27 '16 16:08 Vatsov

I was struggling with a similar issue with MarkerClusterer. Thank you very much @Vatsov you saved my Saturday night!

Jmaiers avatar Jan 29 '17 04:01 Jmaiers