-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm_smoke.htm
201 lines (157 loc) · 6.76 KB
/
m_smoke.htm
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/style.css">
<script src="js/jquery.min.js"></script>
<script type="text/javascript" src="//dapi.kakao.com/v2/maps/sdk.js?appkey=980cb5bdc84e332d75c476760f95cb73"></script>
</head>
<body>
<div id="content" class="content">
<div class="wrap">
<div id="map" ></div>
</div>
</div>
<script>
var mapContainer = document.getElementById('map'), // 지도를 표시할 div
mapOption = {
center: new kakao.maps.LatLng(33.450701, 126.570667), // 지도의 중심좌표
level: 4 // 지도의 확대 레벨
};
var map = new kakao.maps.Map(mapContainer, mapOption); // 지도를 생성합니다
var option = {enableHighAccuracy: true}
// HTML5의 geolocation으로 사용할 수 있는지 확인합니다
if (navigator.geolocation) {
// GeoLocation을 이용해서 접속 위치를 얻어옵니다
navigator.geolocation.getCurrentPosition(function(position,option) {
var lat = position.coords.latitude, // 위도
lon = position.coords.longitude, // 경도
error_range = position.coords.accuracy;
var locPosition = new kakao.maps.LatLng(lat, lon), // 마커가 표시될 위치를 geolocation으로 얻어온 좌표로 생성합니다
message = '<div style="padding:5px;">현재위치: 마커에서 '+error_range+' m 떨어진 곳에 있음</div>'; // 인포윈도우에 표시될 내용입니다
// 마커와 인포윈도우를 표시합니다
displayMarker(locPosition, message);
});
} else { // HTML5의 GeoLocation을 사용할 수 없을때 마커 표시 위치와 인포윈도우 내용을 설정합니다
var locPosition = new kakao.maps.LatLng(33.450701, 126.570667),
message = 'geolocation을 사용할수 없어요..'
displayMarker(locPosition, message);
}
// 지도에 마커와 인포윈도우를 표시하는 함수입니다
function displayMarker(locPosition, message) {
// 마커를 생성합니다
var marker = new kakao.maps.Marker({
map: map,
position: locPosition
});
var iwContent = message, // 인포윈도우에 표시할 내용
iwRemoveable = true;
// 인포윈도우를 생성합니다
var infowindow = new kakao.maps.InfoWindow({
content : iwContent,
removable : iwRemoveable
});
// 인포윈도우를 마커위에 표시합니다
infowindow.open(map, marker);
// 지도 중심좌표를 접속위치로 변경합니다
map.setCenter(locPosition);
console.log(locPosition);
}
</script>
<script src="js/app.common.js"></script>
<!-- 주차장 위치를 표시합니다. -->
<script src="db/smokeList.js"></script>
<script>
var imageSrc = './lib/img/smoke_icon.png', // 마커이미지의 주소입니다
imageSize = new kakao.maps.Size(30, 30), // 마커이미지의 크기입니다
imageOption = {offset: new kakao.maps.Point(15, 15)}; // 마커이미지의 옵션입니다. 마커의 좌표와 일치시킬 이미지 안에서의 좌표를 설정합니다.
var markerImage = new kakao.maps.MarkerImage(imageSrc, imageSize, imageOption);
var infowindow = new kakao.maps.InfoWindow({
content: '<div class="info-title">흡연부스</div>' // 인포윈도우에 표시할 내용
});
Object.keys(pos_smoke).forEach( key =>{
var smoke_marker = new kakao.maps.Marker({
map: map, // 마커를 표시할 지도
position: pos_smoke[key].latlng, // 마커의 위치
image: markerImage
});
var overlay = new kakao.maps.CustomOverlay({
position: smoke_marker.getPosition()
});
var Customcontent = document.createElement('div');
Customcontent.style.width = '170px';
Customcontent.style.height = '150px';
Customcontent.className = "over_wrap";
var info = document.createElement('div');
info.className = "over_info";
Customcontent.appendChild(info);
var title = document.createElement('div');
title.className = "over_title";
title.appendChild(document.createTextNode("흡연부스"))
info.appendChild(title);
var closeBtn = document.createElement("div");
closeBtn.className = "over_close";
closeBtn.setAttribute("title","닫기");
closeBtn.onclick = function(){overlay.setMap(null);};
title.appendChild(closeBtn);
var bodyContent = document.createElement("div");
bodyContent.className = "over_body";
info.appendChild(bodyContent);
var imgDiv = document.createElement("div");
imgDiv.className = "over_img";
bodyContent.appendChild(imgDiv);
var imgContent = document.createElement("img");
imgContent.setAttribute("src", "/lib/img/smoke_icon.png");
imgContent.setAttribute("width", "73");
imgContent.setAttribute("heigth", "70");
imgDiv.appendChild(imgContent);
var descContent = document.createElement("div");
descContent.className = "over_desc"
bodyContent.appendChild(descContent);
var LinkDiv = document.createElement("div");
descContent.appendChild(LinkDiv);
var url = ""
var LinkContent = document.createElement("a");
if (url == "")
{
url = "javascript:"
}
LinkContent.setAttribute("href", "#");
if (url != "javascript:")
{
LinkContent.setAttribute("target", "_blank");
}
LinkContent.className = "link";
LinkContent.appendChild(document.createTextNode("리뷰"));
LinkDiv.appendChild(LinkContent);
overlay.setContent(Customcontent);
kakao.maps.event.addListener(smoke_marker, 'mouseover', mouseOverListener(map,smoke_marker,infowindow ));
kakao.maps.event.addListener(smoke_marker, 'mouseout', mouseOutListener(infowindow));
kakao.maps.event.addListener(smoke_marker, 'click', clickListener(map,smoke_marker,overlay));
});
function mouseOverListener(map, smoke_marker,infowindow){
return function(){
infowindow.open(map, smoke_marker);
}
}
function mouseOutListener(infowindow) {
return function() {
infowindow.close();
};
}
var clickedOverlay = null;
function clickListener( map,smoke_marker,overlay ){
return function() {
if (clickedOverlay) {
clickedOverlay.setMap(null);
}
overlay.setMap(map);
clickedOverlay = overlay;
};
}
</script>
</body>
</html>