-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap4.html
286 lines (235 loc) Β· 11.7 KB
/
map4.html
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.map_wrap, .map_wrap * {margin:0;padding:0;font-family:'Malgun Gothic',dotum,'λμ',sans-serif;font-size:12px;}
.map_wrap a, .map_wrap a:hover, .map_wrap a:active{color:#000;text-decoration: none;}
.map_wrap {position:relative;width:100%;height:500px;}
#menu_wrap {position:absolute;top:0;left:0;bottom:0;width:250px;margin:10px 0 30px 10px;padding:5px;overflow-y:auto;background:rgba(255, 255, 255, 0.7);z-index: 1;font-size:12px;border-radius: 10px;}
.bg_white {background:#fff;}
#menu_wrap hr {display: block; height: 1px;border: 0; border-top: 2px solid #5F5F5F;margin:3px 0;}
#menu_wrap .option{text-align: center;}
#menu_wrap .option p {margin:10px 0;}
#menu_wrap .option button {margin-left:5px;}
#placesList li {list-style: none;}
#placesList .item {position:relative;border-bottom:1px solid #888;overflow: hidden;cursor: pointer;min-height: 65px;}
#placesList .item span {display: block;margin-top:4px;}
#placesList .item h5, #placesList .item .info {text-overflow: ellipsis;overflow: hidden;white-space: nowrap;}
#placesList .item .info{padding:10px 0 10px 55px;}
#placesList .info .gray {color:#8a8a8a;}
#placesList .info .jibun {padding-left:26px;background:url(https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/places_jibun.png) no-repeat;}
#placesList .info .tel {color:#009900;}
#placesList .item .markerbg {float:left;position:absolute;width:36px; height:37px;margin:10px 0 0 10px;background:url(https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/marker_number_blue.png) no-repeat;}
#placesList .item .marker_1 {background-position: 0 -10px;}
#placesList .item .marker_2 {background-position: 0 -56px;}
#placesList .item .marker_3 {background-position: 0 -102px}
#placesList .item .marker_4 {background-position: 0 -148px;}
#placesList .item .marker_5 {background-position: 0 -194px;}
#placesList .item .marker_6 {background-position: 0 -240px;}
#placesList .item .marker_7 {background-position: 0 -286px;}
#placesList .item .marker_8 {background-position: 0 -332px;}
#placesList .item .marker_9 {background-position: 0 -378px;}
#placesList .item .marker_10 {background-position: 0 -423px;}
#placesList .item .marker_11 {background-position: 0 -470px;}
#placesList .item .marker_12 {background-position: 0 -516px;}
#placesList .item .marker_13 {background-position: 0 -562px;}
#placesList .item .marker_14 {background-position: 0 -608px;}
#placesList .item .marker_15 {background-position: 0 -654px;}
#pagination {margin:10px auto;text-align: center;}
#pagination a {display:inline-block;margin-right:10px;}
#pagination .on {font-weight: bold; cursor: default;color:#777;}
</style>
</head>
<body>
<div class="map_wrap">
<div id="map" style="width:100%;height:100%;position:relative;overflow:hidden; margin-top: -10px;"></div>
<div id="menu_wrap" class="bg_white">
<div class="option">
<div>
<form onsubmit="searchPlaces(); return false;">
ν€μλ : <input type="text" value="λΆμν΅λ¬Έκ³ " id="keyword" size="15">
<button type="submit">κ²μνκΈ°</button>
</form>
</div>
</div>
<hr>
<ul id="placesList"></ul>
<div id="pagination"></div>
</div>
</div>
<script src="//dapi.kakao.com/v2/maps/sdk.js?appkey=e7a49d21161d4d937044f81549130320"></script>
<script>
// λ§μ»€λ₯Ό λ΄μ λ°°μ΄μ
λλ€
var markers = [];
var mapContainer = document.getElementById('map'), // μ§λλ₯Ό νμν div
mapOption = {
center: new kakao.maps.LatLng(37.566826, 126.9786567), // μ§λμ μ€μ¬μ’ν
level: 3 // μ§λμ νλ λ 벨
};
// μ§λλ₯Ό μμ±ν©λλ€
var map = new kakao.maps.Map(mapContainer, mapOption);
// μ₯μ κ²μ κ°μ²΄λ₯Ό μμ±ν©λλ€
var ps = new kakao.maps.services.Places();
// κ²μ κ²°κ³Ό λͺ©λ‘μ΄λ λ§μ»€λ₯Ό ν΄λ¦νμ λ μ₯μλͺ
μ νμΆν μΈν¬μλμ°λ₯Ό μμ±ν©λλ€
var infowindow = new kakao.maps.InfoWindow({zIndex:1});
// ν€μλλ‘ μ₯μλ₯Ό κ²μν©λλ€
searchPlaces();
// ν€μλ κ²μμ μμ²νλ ν¨μμ
λλ€
function searchPlaces() {
var keyword = document.getElementById('keyword').value;
if (!keyword.replace(/^\s+|\s+$/g, '')) {
alert('ν€μλλ₯Ό μ
λ ₯ν΄μ£ΌμΈμ!');
return false;
}
// μ₯μκ²μ κ°μ²΄λ₯Ό ν΅ν΄ ν€μλλ‘ μ₯μκ²μμ μμ²ν©λλ€
ps.keywordSearch( keyword, placesSearchCB);
}
// μ₯μκ²μμ΄ μλ£λμ λ νΈμΆλλ μ½λ°±ν¨μ μ
λλ€
function placesSearchCB(data, status, pagination) {
if (status === kakao.maps.services.Status.OK) {
// μ μμ μΌλ‘ κ²μμ΄ μλ£λμΌλ©΄
// κ²μ λͺ©λ‘κ³Ό λ§μ»€λ₯Ό νμΆν©λλ€
displayPlaces(data);
// νμ΄μ§ λ²νΈλ₯Ό νμΆν©λλ€
displayPagination(pagination);
} else if (status === kakao.maps.services.Status.ZERO_RESULT) {
alert('κ²μ κ²°κ³Όκ° μ‘΄μ¬νμ§ μμ΅λλ€.');
return;
} else if (status === kakao.maps.services.Status.ERROR) {
alert('κ²μ κ²°κ³Ό μ€ μ€λ₯κ° λ°μνμ΅λλ€.');
return;
}
}
// κ²μ κ²°κ³Ό λͺ©λ‘κ³Ό λ§μ»€λ₯Ό νμΆνλ ν¨μμ
λλ€
function displayPlaces(places) {
var listEl = document.getElementById('placesList'),
menuEl = document.getElementById('menu_wrap'),
fragment = document.createDocumentFragment(),
bounds = new kakao.maps.LatLngBounds(),
listStr = '';
// κ²μ κ²°κ³Ό λͺ©λ‘μ μΆκ°λ νλͺ©λ€μ μ κ±°ν©λλ€
removeAllChildNods(listEl);
// μ§λμ νμλκ³ μλ λ§μ»€λ₯Ό μ κ±°ν©λλ€
removeMarker();
for ( var i=0; i<places.length; i++ ) {
// λ§μ»€λ₯Ό μμ±νκ³ μ§λμ νμν©λλ€
var placePosition = new kakao.maps.LatLng(places[i].y, places[i].x),
marker = addMarker(placePosition, i),
itemEl = getListItem(i, places[i]); // κ²μ κ²°κ³Ό νλͺ© Elementλ₯Ό μμ±ν©λλ€
// κ²μλ μ₯μ μμΉλ₯Ό κΈ°μ€μΌλ‘ μ§λ λ²μλ₯Ό μ¬μ€μ νκΈ°μν΄
// LatLngBounds κ°μ²΄μ μ’νλ₯Ό μΆκ°ν©λλ€
bounds.extend(placePosition);
// λ§μ»€μ κ²μκ²°κ³Ό νλͺ©μ mouseover νμλ
// ν΄λΉ μ₯μμ μΈν¬μλμ°μ μ₯μλͺ
μ νμν©λλ€
// mouseout νμ λλ μΈν¬μλμ°λ₯Ό λ«μ΅λλ€
(function(marker, title) {
kakao.maps.event.addListener(marker, 'mouseover', function() {
displayInfowindow(marker, title);
});
kakao.maps.event.addListener(marker, 'mouseout', function() {
infowindow.close();
});
itemEl.onmouseover = function () {
displayInfowindow(marker, title);
};
itemEl.onmouseout = function () {
infowindow.close();
};
})(marker, places[i].place_name);
fragment.appendChild(itemEl);
}
// κ²μκ²°κ³Ό νλͺ©λ€μ κ²μκ²°κ³Ό λͺ©λ‘ Elementμ μΆκ°ν©λλ€
listEl.appendChild(fragment);
menuEl.scrollTop = 0;
// κ²μλ μ₯μ μμΉλ₯Ό κΈ°μ€μΌλ‘ μ§λ λ²μλ₯Ό μ¬μ€μ ν©λλ€
map.setBounds(bounds);
}
// κ²μκ²°κ³Ό νλͺ©μ Elementλ‘ λ°ννλ ν¨μμ
λλ€
function getListItem(index, places) {
var el = document.createElement('li'),
itemStr = '<span class="markerbg marker_' + (index+1) + '"></span>' +
'<div class="info">' +
' <h5>' + places.place_name + '</h5>';
if (places.road_address_name) {
itemStr += ' <span>' + places.road_address_name + '</span>' +
' <span class="jibun gray">' + places.address_name + '</span>';
} else {
itemStr += ' <span>' + places.address_name + '</span>';
}
itemStr += ' <span class="tel">' + places.phone + '</span>' +
'</div>';
el.innerHTML = itemStr;
el.className = 'item';
return el;
}
// λ§μ»€λ₯Ό μμ±νκ³ μ§λ μμ λ§μ»€λ₯Ό νμνλ ν¨μμ
λλ€
function addMarker(position, idx, title) {
var imageSrc = 'https://t1.daumcdn.net/localimg/localimages/07/mapapidoc/marker_number_blue.png', // λ§μ»€ μ΄λ―Έμ§ url, μ€νλΌμ΄νΈ μ΄λ―Έμ§λ₯Ό μλλ€
imageSize = new kakao.maps.Size(36, 37), // λ§μ»€ μ΄λ―Έμ§μ ν¬κΈ°
imgOptions = {
spriteSize : new kakao.maps.Size(36, 691), // μ€νλΌμ΄νΈ μ΄λ―Έμ§μ ν¬κΈ°
spriteOrigin : new kakao.maps.Point(0, (idx*46)+10), // μ€νλΌμ΄νΈ μ΄λ―Έμ§ μ€ μ¬μ©ν μμμ μ’μλ¨ μ’ν
offset: new kakao.maps.Point(13, 37) // λ§μ»€ μ’νμ μΌμΉμν¬ μ΄λ―Έμ§ λ΄μμμ μ’ν
},
markerImage = new kakao.maps.MarkerImage(imageSrc, imageSize, imgOptions),
marker = new kakao.maps.Marker({
position: position, // λ§μ»€μ μμΉ
image: markerImage
});
marker.setMap(map); // μ§λ μμ λ§μ»€λ₯Ό νμΆν©λλ€
markers.push(marker); // λ°°μ΄μ μμ±λ λ§μ»€λ₯Ό μΆκ°ν©λλ€
return marker;
}
// μ§λ μμ νμλκ³ μλ λ§μ»€λ₯Ό λͺ¨λ μ κ±°ν©λλ€
function removeMarker() {
for ( var i = 0; i < markers.length; i++ ) {
markers[i].setMap(null);
}
markers = [];
}
// κ²μκ²°κ³Ό λͺ©λ‘ νλ¨μ νμ΄μ§λ²νΈλ₯Ό νμλ ν¨μμ
λλ€
function displayPagination(pagination) {
var paginationEl = document.getElementById('pagination'),
fragment = document.createDocumentFragment(),
i;
// κΈ°μ‘΄μ μΆκ°λ νμ΄μ§λ²νΈλ₯Ό μμ ν©λλ€
while (paginationEl.hasChildNodes()) {
paginationEl.removeChild (paginationEl.lastChild);
}
for (i=1; i<=pagination.last; i++) {
var el = document.createElement('a');
el.href = "#";
el.innerHTML = i;
if (i===pagination.current) {
el.className = 'on';
} else {
el.onclick = (function(i) {
return function() {
pagination.gotoPage(i);
}
})(i);
}
fragment.appendChild(el);
}
paginationEl.appendChild(fragment);
}
// κ²μκ²°κ³Ό λͺ©λ‘ λλ λ§μ»€λ₯Ό ν΄λ¦νμ λ νΈμΆλλ ν¨μμ
λλ€
// μΈν¬μλμ°μ μ₯μλͺ
μ νμν©λλ€
function displayInfowindow(marker, title) {
var content = '<div style="padding:5px;z-index:1;">' + title + '</div>';
infowindow.setContent(content);
infowindow.open(map, marker);
}
// κ²μκ²°κ³Ό λͺ©λ‘μ μμ Elementλ₯Ό μ κ±°νλ ν¨μμ
λλ€
function removeAllChildNods(el) {
while (el.hasChildNodes()) {
el.removeChild (el.lastChild);
}
}
</script>
</body>
</html>