폴리라인 생성/삭제
지도위에 폴리라인 도형을 생성 삭제 할 수 있습니다.
var map = new routo.maps.Map("map", {
center: { lat: 37.507009, lng: 127.0586339 }, // 지도 초기 위치
zoom: 18, // 지도 로딩 시 최초 표시 레벨
});
var polyline = null;
var createPolyline = document.querySelector('#create-polyline');
createPolyline.addEventListener('click', function() {
polyline = new routo.maps.Polyline({
path: [
{ "lng": 127.04125318558347, "lat": 37.517093804970045 },
{ "lng": 127.04279813797606, "lat": 37.51328131316447 },
{ "lng": 127.04391393692624, "lat": 37.510353731907486 },
{ "lng": 127.0488921168579, "lat": 37.5118515785247 },
{ "lng": 127.05326948197018, "lat": 37.51307706703564 },
{ "lng": 127.05610189468993, "lat": 37.513485558734374 },
{ "lng": 127.06020031006467, "lat": 37.51424721957666 },
{ "lng": 127.063140011145, "lat": 37.50892394118759 },
{ "lng": 127.0664015773071, "lat": 37.50987713804392 },
{ "lng": 127.06631574661863, "lat": 37.510557985488916 }
],
strokeColor: '#FF0000',
strokeWeight: '5'
});
polyline.setMap(map);
map.fitBounds(polyline.getBounds(), {
top: 50,
right: 100,
bottom: 50,
left: 100,
});
});
var deletePolyline = document.querySelector('#delete-polyline');
deletePolyline.addEventListener('click', function() {
polyline.setMap(null);
polyline = null;
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>폴리라인 생성 삭제하기</title>
<style>
html,
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.map {
width: 100%;
height: 400px;
position: relative;
}
</style>
</head>
<body>
<h2>폴리라인 생성 삭제하기</h2>
<hr />
<p>
지도위에 폴리라인 도형을 생성 삭제 할 수 있습니다.
</p>
<div class="map-container">
<div class="map-tool-bar">
<button id="create-polyline" class="cs-btn3">폴리라인 생성하기</button>
<button id="delete-polyline" class="cs-btn3">폴리라인 삭제하기</button>
</div>
<div id="map" class="map"></div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://api.routo.com/v2/maps/map?key={APIKEY}"></script>
<script>
var map = new routo.maps.Map("map", {
center: { lat: 37.507009, lng: 127.0586339 }, // 지도 초기 위치
zoom: 18, // 지도 로딩 시 최초 표시 레벨
});
var polyline = null;
var createPolyline = document.querySelector('#create-polyline');
createPolyline.addEventListener('click', function() {
polyline = new routo.maps.Polyline({
path: [
{ "lng": 127.04125318558347, "lat": 37.517093804970045 },
{ "lng": 127.04279813797606, "lat": 37.51328131316447 },
{ "lng": 127.04391393692624, "lat": 37.510353731907486 },
{ "lng": 127.0488921168579, "lat": 37.5118515785247 },
{ "lng": 127.05326948197018, "lat": 37.51307706703564 },
{ "lng": 127.05610189468993, "lat": 37.513485558734374 },
{ "lng": 127.06020031006467, "lat": 37.51424721957666 },
{ "lng": 127.063140011145, "lat": 37.50892394118759 },
{ "lng": 127.0664015773071, "lat": 37.50987713804392 },
{ "lng": 127.06631574661863, "lat": 37.510557985488916 }
],
strokeColor: '#FF0000',
strokeWeight: '5'
});
polyline.setMap(map);
map.fitBounds(polyline.getBounds(), {
top: 50,
right: 100,
bottom: 50,
left: 100,
});
});
var deletePolyline = document.querySelector('#delete-polyline');
deletePolyline.addEventListener('click', function() {
polyline.setMap(null);
polyline = null;
});
</script>
</body>
</html>