-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathangular-naver-maps.js
69 lines (69 loc) · 3.38 KB
/
angular-naver-maps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(function() {
angular.module('NaverMaps').directive('ngNaverMapInfowindow', [
'NgNaverMap',
function(NgNaverMap) {
return {
scope: {
index: '=',
model: '=?',
position: '@?',
onClick: '&?'
},
requires: '^?ngNaverMap',
restrict: 'E',
transclude: true,
link: function(scope, element, attrs, ngNaverMap, transclude) {
NgNaverMap.getMap().then(function(oMap) {
// Getting Naver Instance
var Naver = NgNaverMap.Naver;
// Creating Info Window instance
var oInfoWnd = new Naver.InfoWindow();
// Configuring Info Window instance
oInfoWnd.setPoint(NgNaverMap.getLatLng(eval(scope.position)));
oInfoWnd.setPosition({top: 40});
// oInfoWnd.autoPosition();
oInfoWnd.setVisible(false);
// Adding Info Window instance to the map
oMap.addOverlay(oInfoWnd);
// Tracking Info Window instance visibility
scope.visible = false;
// Registered Event to toggle the Info Window instance's visibility
scope.$on('toggleInfoWindow', function(event, index) {
if (index === scope.index) {
scope.visible = !scope.visible;
oInfoWnd.setVisible(scope.visible);
}
});
// Registered Event to close the Info Window instance's
scope.$on('closeInfoWindow', function(event, index) {
if (index === scope.index) {
scope.visible = false;
oInfoWnd.setVisible(false);
}
});
// Registered Event to close all Info Window instances
// scope.$on('hideAllInfoWindows', function(event) {
// oInfoWnd.setVisible(false);
// });
// Registered Event click calls the scope's on-click()
oInfoWnd.attach('click', function() {
scope.onClick({model: scope.model});
});
// Setting the inner content of the Info window instance using transcluded HTML
transclude(scope.$parent, function(clone, scope) {
var htmlWrapper = document.createElement('div');
for (var i = 0; i < clone.length; i++) {
if (clone[i].nodeType === 1) {
htmlWrapper.appendChild(clone[i]);
}
}
htmlWrapper.style.overflow = 'auto';
htmlWrapper.className = "ng-map-infowindow";
oInfoWnd.setContent(htmlWrapper);
});
});
}
};
}
]);
})();