지도 이벤트 적용
routogl 지도에 다양한 이벤트를 적용하는 예제입니다.
const map = new routogl.Map({
container: 'map', // container ID
style: routogl.RoutoStyle.LIGHT,
center: [127.0586339, 37.507009], // 초기 위치 [lng, lat]
zoom: 13, // 초기 줌 레벨
});
const eventInfo = document.getElementById('eventInfo');
// mousedown, mouseup, mouseover, mousemove
// map.on('mousedown', () => {
// eventInfo.value += '마우스 다운\n';
// });
// map.on('mouseup', () => {
// eventInfo.value += '마우스 업\n';
// });
// map.on('mouseover', () => {
// eventInfo.value += '마우스 오버\n';
// });
// map.on('mousemove', () => {
// eventInfo.value += '마우스 이동\n';
// });
// click, dblclick
map.on('click', (e) => {
eventInfo.value += `지도 클릭 [${e.lngLat.lng}, ${e.lngLat.lat}]\n`;
});
map.on('dblclick', () => {
eventInfo.value += '지도 더블클릭\n';
});
// movestart, move, moveend
map.on('movestart', () => {
eventInfo.value += '지도 이동 시작\n';
});
map.on('move', () => {
eventInfo.value += '지도 이동중\n';
});
map.on('moveend', () => {
eventInfo.value += '지도 이동 완료\n';
});
// dragstart, drag, dragend
map.on('dragstart', () => {
eventInfo.value += '드래그 시작\n';
});
map.on('drag', () => {
eventInfo.value += '드래그중\n';
});
map.on('dragend', () => {
eventInfo.value += '드래그 완료\n';
});
// zoomstart, zoom, zoomend
map.on('zoomstart', () => {
eventInfo.value += '줌 레벨 변경 시작\n';
});
map.on('zoom', () => {
eventInfo.value += '줌 레벨 변경\n';
});
map.on('zoomend', () => {
eventInfo.value += '줌 레벨 변경 완료\n';
});
// rotatestart, rotate, rotateend
map.on('rotatestart', () => {
eventInfo.value += '회전 시작\n';
});
map.on('rotate', () => {
eventInfo.value += '회전중\n';
});
map.on('rotateend', () => {
eventInfo.value += '회전 완료\n';
});
// pitchstart, pitch, pitchend
map.on('pitchstart', () => {
eventInfo.value += '고도 변경 시작\n';
});
map.on('pitch', () => {
eventInfo.value += '고도 변경\n';
});
map.on('pitchend', () => {
eventInfo.value += '고도 변경 완료\n';
});
// load
map.on('load', () => {
eventInfo.value += '지도가 로드되었습니다.\n';
});
setInterval(() => {
eventInfo.scrollTop = eventInfo.scrollHeight;
}, 1000);
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>routo Developers - 지도 - 지도 이벤트 적용</title>
<link href="https://api.mapbox.com/mapbox-gl-js/v3.7.0/mapbox-gl.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" />
<style>html, body { margin: 0; padding: 0; } div#map { width: 100%; height: 50vh; }</style>
</head>
<body>
<main>
<div class="container">
<header class="d-flex flex-wrap justify-content-center py-3 mb-4 border-bottom">
<a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-dark text-decoration-none">
<span class="fs-4">routo Map Examples</span>
</a>
<nav aria-label="breadcrumb">
<ol class="breadcrumb p-3 bg-body-tertiary rounded-3"></ol>
</nav>
</header>
<examplecontent>
<h2 id="title" class="mb-5">지도 이벤트 적용</h2>
<hr />
<p id="desc" class="text-start text-break fs-5">
routogl 지도에 다양한 이벤트를 적용하는 예제입니다.
<br/>
</p>
<!-- 지도 -->
<div id="map" class="mb-3 map"></div>
<textarea rows="5" id="eventInfo" style="width:100%;margin-bottom: 5px;"></textarea>
</examplecontent>
</div>
</main>
</body>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://stg-api.routo.com/v3/maps/map?key=c914fb43-0d44-4fa7-838a-84619e3486c3"></script>
<script>
const map = new routogl.Map({
container: 'map', // container ID
style: routogl.RoutoStyle.LIGHT,
center: [127.0586339, 37.507009], // 초기 위치 [lng, lat]
zoom: 13, // 초기 줌 레벨
});
const eventInfo = document.getElementById('eventInfo');
// mousedown, mouseup, mouseover, mousemove
// map.on('mousedown', () => {
// eventInfo.value += '마우스 다운\n';
// });
// map.on('mouseup', () => {
// eventInfo.value += '마우스 업\n';
// });
// map.on('mouseover', () => {
// eventInfo.value += '마우스 오버\n';
// });
// map.on('mousemove', () => {
// eventInfo.value += '마우스 이동\n';
// });
// click, dblclick
map.on('click', (e) => {
eventInfo.value += `지도 클릭 [${e.lngLat.lng}, ${e.lngLat.lat}]\n`;
});
map.on('dblclick', () => {
eventInfo.value += '지도 더블클릭\n';
});
// movestart, move, moveend
map.on('movestart', () => {
eventInfo.value += '지도 이동 시작\n';
});
map.on('move', () => {
eventInfo.value += '지도 이동중\n';
});
map.on('moveend', () => {
eventInfo.value += '지도 이동 완료\n';
});
// dragstart, drag, dragend
map.on('dragstart', () => {
eventInfo.value += '드래그 시작\n';
});
map.on('drag', () => {
eventInfo.value += '드래그중\n';
});
map.on('dragend', () => {
eventInfo.value += '드래그 완료\n';
});
// zoomstart, zoom, zoomend
map.on('zoomstart', () => {
eventInfo.value += '줌 레벨 변경 시작\n';
});
map.on('zoom', () => {
eventInfo.value += '줌 레벨 변경\n';
});
map.on('zoomend', () => {
eventInfo.value += '줌 레벨 변경 완료\n';
});
// rotatestart, rotate, rotateend
map.on('rotatestart', () => {
eventInfo.value += '회전 시작\n';
});
map.on('rotate', () => {
eventInfo.value += '회전중\n';
});
map.on('rotateend', () => {
eventInfo.value += '회전 완료\n';
});
// pitchstart, pitch, pitchend
map.on('pitchstart', () => {
eventInfo.value += '고도 변경 시작\n';
});
map.on('pitch', () => {
eventInfo.value += '고도 변경\n';
});
map.on('pitchend', () => {
eventInfo.value += '고도 변경 완료\n';
});
// load
map.on('load', () => {
eventInfo.value += '지도가 로드되었습니다.\n';
});
setInterval(() => {
eventInfo.scrollTop = eventInfo.scrollHeight;
}, 1000);</script>
</html>