WEB GL JS

웹 개발, 어플리케이션에서 활용될 수 있도록 Javascript로 제공되는 지도 플랫폼 입니다.

폴리라인 생성/삭제


routogl 지도에 폴리라인을 생성/삭제하는 예제입니다.

const map = new routogl.Map({
  container: 'map', // container ID
  style: routogl.RoutoStyle.LIGHT,
  center: [127.0586339, 37.507009], // starting position [lng, lat]
  zoom: 17, // starting zoom
});

map.on('load', () => {
  // 폴리라인 소스 생성
  map.addSource('polyline', {
    'type': 'geojson',
    'data': {
      'type': 'Feature',
      'geometry': {
        'type': 'LineString',
        'coordinates': [
          [127.0584339, 37.506709],
          [127.0585739, 37.506109],
          [127.0589739, 37.506109],
          [127.0589739, 37.506809],
          [127.0587239, 37.507809],
          [127.0587239, 37.507809],
          [127.0585639, 37.507509]
        ]
      }
    }
  });

  // 폴리라인 스타일이 정의된 레이어 생성
  map.addLayer({
    'id': 'polylineLayer',
    'type': 'line',
    'source': 'polyline',
    'layout': {},
    'paint': {
      'line-color': '#0022af',
      'line-width': 3
    }
  });
});

// 폴리라인 삭제
const removePolyline = document.getElementById('removePolyline');
removePolyline.addEventListener('click', () => {
  if (map.getLayer('polylineLayer')) map.removeLayer('polylineLayer');
  map.removeSource('polyline');
});