implement InfoWindow
- add display infowindow function for each marker
Showing
2 changed files
with
90 additions
and
2 deletions
| ... | @@ -15,13 +15,14 @@ | ... | @@ -15,13 +15,14 @@ |
| 15 | 15 | ||
| 16 | .App-header { | 16 | .App-header { |
| 17 | background-color: #282c34; | 17 | background-color: #282c34; |
| 18 | - min-height: 100vh; | 18 | + min-height: 13vh; |
| 19 | display: flex; | 19 | display: flex; |
| 20 | flex-direction: column; | 20 | flex-direction: column; |
| 21 | align-items: center; | 21 | align-items: center; |
| 22 | justify-content: center; | 22 | justify-content: center; |
| 23 | font-size: calc(10px + 2vmin); | 23 | font-size: calc(10px + 2vmin); |
| 24 | color: white; | 24 | color: white; |
| 25 | + font-weight: bold; | ||
| 25 | } | 26 | } |
| 26 | 27 | ||
| 27 | .App-link { | 28 | .App-link { | ... | ... |
| ... | @@ -26,6 +26,7 @@ export default class Home extends Component { | ... | @@ -26,6 +26,7 @@ export default class Home extends Component { |
| 26 | // routeInformation: null, | 26 | // routeInformation: null, |
| 27 | }; | 27 | }; |
| 28 | this.removeAllChildNods = this.removeAllChildNods.bind(this); | 28 | this.removeAllChildNods = this.removeAllChildNods.bind(this); |
| 29 | + this.displayInfowindow = this.displayInfowindow.bind(this); | ||
| 29 | } | 30 | } |
| 30 | 31 | ||
| 31 | searchPlaces() { | 32 | searchPlaces() { |
| ... | @@ -87,7 +88,18 @@ export default class Home extends Component { | ... | @@ -87,7 +88,18 @@ export default class Home extends Component { |
| 87 | // 마커와 검색결과 항목에 mouseover 했을때 | 88 | // 마커와 검색결과 항목에 mouseover 했을때 |
| 88 | // 해당 장소에 인포윈도우에 장소명을 표시합니다 | 89 | // 해당 장소에 인포윈도우에 장소명을 표시합니다 |
| 89 | // mouseout 했을 때는 인포윈도우를 닫습니다 | 90 | // mouseout 했을 때는 인포윈도우를 닫습니다 |
| 90 | - | 91 | + ((marker, title) => { |
| 92 | + kakao.maps.event.addListener(marker, "click", () => { | ||
| 93 | + this.displayInfowindow(marker, title); | ||
| 94 | + }); | ||
| 95 | + kakao.maps.event.addListener(marker, "mouseover", () => { | ||
| 96 | + this.displayInfowindow(marker, title); | ||
| 97 | + }); | ||
| 98 | + | ||
| 99 | + itemEl.onmouseover = () => { | ||
| 100 | + this.displayInfowindow(marker, title); | ||
| 101 | + }; | ||
| 102 | + })(marker, places[i].place_name); | ||
| 91 | // 함수를 조건문처럼 사용하여 해당 함수가 true일때 marker,places[i].place_name함수가 불리워짐. | 103 | // 함수를 조건문처럼 사용하여 해당 함수가 true일때 marker,places[i].place_name함수가 불리워짐. |
| 92 | 104 | ||
| 93 | fragment.appendChild(itemEl); | 105 | fragment.appendChild(itemEl); |
| ... | @@ -205,6 +217,81 @@ export default class Home extends Component { | ... | @@ -205,6 +217,81 @@ export default class Home extends Component { |
| 205 | } | 217 | } |
| 206 | } | 218 | } |
| 207 | 219 | ||
| 220 | + // 검색결과 목록 또는 마커를 클릭했을 때 호출되는 함수입니다 | ||
| 221 | + // 인포윈도우에 장소명을 표시합니다 | ||
| 222 | + displayInfowindow(marker, title) { | ||
| 223 | + console.log(marker); | ||
| 224 | + | ||
| 225 | + let content = document.createElement("div"); | ||
| 226 | + content.className = "wraps"; | ||
| 227 | + | ||
| 228 | + let info = document.createElement("div"); | ||
| 229 | + info.className = "infos"; | ||
| 230 | + | ||
| 231 | + let titles = document.createElement("div"); | ||
| 232 | + titles.className = "title"; | ||
| 233 | + titles.innerHTML = title; | ||
| 234 | + | ||
| 235 | + let close = document.createElement("div"); | ||
| 236 | + close.className = "close"; | ||
| 237 | + close.onclick = () => { | ||
| 238 | + this.state.infoWindow.setMap(null); | ||
| 239 | + }; | ||
| 240 | + | ||
| 241 | + let body = document.createElement("div"); | ||
| 242 | + body.className = "body"; | ||
| 243 | + let desc = document.createElement("div"); | ||
| 244 | + let list = document.createElement("list"); | ||
| 245 | + let second = document.createElement("LI"); | ||
| 246 | + let br = document.createElement("div"); | ||
| 247 | + br.innerHTML += "<br>"; | ||
| 248 | + let second_ = document.createElement("LI"); | ||
| 249 | + | ||
| 250 | + let getMise = document.createElement("Button"); | ||
| 251 | + getMise.innerHTML = "미세먼지 정보"; | ||
| 252 | + getMise.className = "info-button"; | ||
| 253 | + getMise.onclick = () => { | ||
| 254 | + let position = marker.getPosition(); | ||
| 255 | + console.log(marker.getPosition()); | ||
| 256 | + console.log(position["Ga"]); | ||
| 257 | + }; | ||
| 258 | + let setDepart = document.createElement("Button"); | ||
| 259 | + setDepart.innerHTML = "출발지로 설정하기"; | ||
| 260 | + setDepart.onclick = () => { | ||
| 261 | + this.setState({ | ||
| 262 | + departure: marker.getPosition(), | ||
| 263 | + departureTitle: title, | ||
| 264 | + }); | ||
| 265 | + }; | ||
| 266 | + setDepart.className = "info-button"; | ||
| 267 | + let setArrive = document.createElement("Button"); | ||
| 268 | + setArrive.innerHTML = "도착지로 설정하기"; | ||
| 269 | + setArrive.onclick = () => { | ||
| 270 | + this.setState({ | ||
| 271 | + arrival: marker.getPosition(), | ||
| 272 | + arrivalTitle: title, | ||
| 273 | + }); | ||
| 274 | + }; | ||
| 275 | + setArrive.className = "info-button"; | ||
| 276 | + second.appendChild(getMise); | ||
| 277 | + second.appendChild(br); | ||
| 278 | + second_.appendChild(setDepart); | ||
| 279 | + second_.appendChild(setArrive); | ||
| 280 | + | ||
| 281 | + list.appendChild(second); | ||
| 282 | + list.appendChild(second_); | ||
| 283 | + desc.appendChild(list); | ||
| 284 | + body.appendChild(desc); | ||
| 285 | + titles.appendChild(close); | ||
| 286 | + info.appendChild(titles); | ||
| 287 | + info.appendChild(body); | ||
| 288 | + content.appendChild(info); | ||
| 289 | + | ||
| 290 | + this.state.infoWindow.setContent(content); | ||
| 291 | + this.state.infoWindow.setPosition(marker.getPosition()); | ||
| 292 | + this.state.infoWindow.setMap(this.state.map); | ||
| 293 | + } | ||
| 294 | + | ||
| 208 | componentDidMount() { | 295 | componentDidMount() { |
| 209 | // 컴포넌트가 만들어지고, render 함수가 호출된 이후에 호출되는 메소 | 296 | // 컴포넌트가 만들어지고, render 함수가 호출된 이후에 호출되는 메소 |
| 210 | // AJAX나 타이머를 생성하는 코드를 작성하는 파트이다. | 297 | // AJAX나 타이머를 생성하는 코드를 작성하는 파트이다. | ... | ... |
-
Please register or login to post a comment