Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.

Commit 3997eea

Browse files
committed
Merge pull request #60 from trafficland/feature/icon_update_without_destroy
Feature/icon update without destroy
2 parents 74ad00e + e67c980 commit 3997eea

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

dist/angular-google-maps.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,16 @@ angular.module('google-maps')
435435
}
436436
}, true);
437437

438+
scope.$watch('icon', function (newValue, oldValue) {
439+
if (newValue !== oldValue) {
440+
marker.icon = newValue;
441+
marker.setMap(null);
442+
marker.setMap(mapCtrl.getMap());
443+
marker.setPosition(new google.maps.LatLng(scope.coords.latitude, scope.coords.longitude));
444+
marker.setVisible(scope.coords.latitude !== null && scope.coords.longitude !== null);
445+
}
446+
}, true);
447+
438448
// remove marker on scope $destroy
439449
scope.$on("$destroy", function () {
440450
marker.setMap(null);
@@ -545,14 +555,16 @@ angular.module("google-maps").
545555
show: '&show',
546556
templateUrl: '=templateurl',
547557
templateParameter: '=templateparameter',
548-
isIconVisibleOnClick: '=isiconvisibleonclick'
558+
isIconVisibleOnClick: '=isiconvisibleonclick',
559+
closeClick: '&closeclick' //scope glue to gmap InfoWindow closeclick
549560
},
550561
link: function (scope, element, attrs, ctrls) {
551562
$timeout(function () {
552563

553-
if (!angular.isDefined(attrs.isiconvisibleonclick)) {
554-
scope.isIconVisibleOnClick = true;
555-
}
564+
var isIconVisibleOnClick = true;
565+
566+
if (angular.isDefined(attrs.isiconvisibleonclick))
567+
isIconVisibleOnClick = scope.isIconVisibleOnClick;
556568

557569
var mapCtrl = ctrls[0],
558570
markerCtrl = ctrls.length > 1 ? ctrls[1] : null;
@@ -579,12 +591,13 @@ angular.module("google-maps").
579591

580592
initialMarkerVisibility = markerInstance.getVisible();
581593

582-
markerInstance.setVisible(scope.isIconVisibleOnClick);
594+
markerInstance.setVisible(isIconVisibleOnClick);
583595
});
584596

585597
// Set visibility of marker back to what it was before opening the window
586598
google.maps.event.addListener(win, 'closeclick', function () {
587599
markerInstance.setVisible(initialMarkerVisibility);
600+
scope.closeClick();
588601
});
589602
}
590603

@@ -621,7 +634,7 @@ angular.module("google-maps").
621634
// If we're initially showing the marker and it's not yet visible, show it.
622635
showWindow();
623636
}
624-
});
637+
},true);
625638
}, 50);
626639
}
627640
};

dist/angular-google-maps.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/directives/marker.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ angular.module('google-maps')
121121
}
122122
}, true);
123123

124+
scope.$watch('icon', function (newValue, oldValue) {
125+
if (newValue !== oldValue) {
126+
marker.icon = newValue;
127+
marker.setMap(null);
128+
marker.setMap(mapCtrl.getMap());
129+
marker.setPosition(new google.maps.LatLng(scope.coords.latitude, scope.coords.longitude));
130+
marker.setVisible(scope.coords.latitude !== null && scope.coords.longitude !== null);
131+
}
132+
}, true);
133+
124134
// remove marker on scope $destroy
125135
scope.$on("$destroy", function () {
126136
marker.setMap(null);

src/directives/window.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,16 @@ angular.module("google-maps").
5757
show: '&show',
5858
templateUrl: '=templateurl',
5959
templateParameter: '=templateparameter',
60-
isIconVisibleOnClick: '=isiconvisibleonclick'
60+
isIconVisibleOnClick: '=isiconvisibleonclick',
61+
closeClick: '&closeclick' //scope glue to gmap InfoWindow closeclick
6162
},
6263
link: function (scope, element, attrs, ctrls) {
6364
$timeout(function () {
6465

65-
if (!angular.isDefined(attrs.isiconvisibleonclick)) {
66-
scope.isIconVisibleOnClick = true;
67-
}
66+
var isIconVisibleOnClick = true;
67+
68+
if (angular.isDefined(attrs.isiconvisibleonclick))
69+
isIconVisibleOnClick = scope.isIconVisibleOnClick;
6870

6971
var mapCtrl = ctrls[0],
7072
markerCtrl = ctrls.length > 1 ? ctrls[1] : null;
@@ -91,12 +93,13 @@ angular.module("google-maps").
9193

9294
initialMarkerVisibility = markerInstance.getVisible();
9395

94-
markerInstance.setVisible(scope.isIconVisibleOnClick);
96+
markerInstance.setVisible(isIconVisibleOnClick);
9597
});
9698

9799
// Set visibility of marker back to what it was before opening the window
98100
google.maps.event.addListener(win, 'closeclick', function () {
99101
markerInstance.setVisible(initialMarkerVisibility);
102+
scope.closeClick();
100103
});
101104
}
102105

@@ -133,7 +136,7 @@ angular.module("google-maps").
133136
// If we're initially showing the marker and it's not yet visible, show it.
134137
showWindow();
135138
}
136-
});
139+
},true);
137140
}, 50);
138141
}
139142
};

0 commit comments

Comments
 (0)