-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
107 lines (76 loc) · 2.13 KB
/
main.js
File metadata and controls
107 lines (76 loc) · 2.13 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
var mapOptions = {
center: new naver.maps.LatLng(37.3595704, 127.105399),
zoom: 10
};
var map = new naver.maps.Map('map', mapOptions);
var markerList = [];
var infowindowList = [];
for (var i in data) {
var target = data[i];
var latlng = new naver.maps.LatLng(target.lat, target.lng);
marker = new naver.maps.Marker({
map: map,
position: latlng,
icon: {
content: "<div class='marker'></div>",
anchor: new naver.maps.Point(12, 12)
},
});
var content = `<div class='infowindow_wrap'>
<div class='infowindow_title'>${target.title}</div>
<div class='infowindow_content'>${target.content}</div>
<div class='infowindow_date'>${target.date}</div>
</div>`
var infowindow = new naver.maps.InfoWindow({
content: content,
backgroundColor: "#00ff000000",
borderColor: "#00ff000000",
anchorSize: new naver.maps.Size(0, 0)
})
markerList.push(marker);
infowindowList.push(infowindow);
}
for (var i = 0, ii = markerList.length; i < ii; i++) {
naver.maps.Event.addListener(map, "click", ClicMap(i));
naver.maps.Event.addListener(markerList[i], "click", getClickHandler(i));
}
function ClicMap(i) {
return function() {
var infowindow = infowindowList[i];
infowindow.close()
}
}
function getClickHandler(i) {
return function() {
var marker = markerList[i];
var infowindow = infowindowList[i];
if (infowindow.getMap()) {
infowindow.close();
} else {
infowindow.open(map, marker);
}
}
}
function onErrorGeolocation() {
var center = map.getCenter();
infowindow.setContent('<div style="padding:20px;">' +
'<h5 style="margin-bottom:5px;color:#f00;">Geolocation failed!</h5>'+
"latitude: "+ center.lat() +"<br />longitude: "+ center.lng() +'</div>');
infowindow.open(map, center);
}
$('#current').click(() => {
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position) => {
const lat = position.coords.latitude;
const lng = position.coords.longitude;
var location = new naver.maps.LatLng(lat, lng);
map.setCenter(location);
map.setZoom(14);
marker = new naver.maps.Marker({
map: map,
position: location,
});
});
} else {
}
})