WEB GL JS

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

커스텀 popup 생성


routogl 지도에 커스텀 팝업을 생성하는 예제입니다.
팝업 태그의 클래스명을 이용하여 직접 CSS를 수정하여 스타일 커스텀을 진행할 수 있습니다.

const map = new routogl.Map({
  container: 'map', // container ID
  style: routogl.RoutoStyle.LIGHT,
  center: [127.0586339, 37.507009], // 초기 위치 [lng, lat]
  zoom: 17, // 초기 줌 레벨
});

const markerHeight = 10;
const markerRadius = 10;
const linearOffset = 25;
const popupOffsets = {
    'top': [0, 0],
    'top-left': [0, 0],
    'top-right': [0, 0],
    'bottom': [0, -markerHeight],
    'bottom-left': [linearOffset, (markerHeight - markerRadius + linearOffset) * -1],
    'bottom-right': [-linearOffset, (markerHeight - markerRadius + linearOffset) * -1],
    'left': [markerRadius, (markerHeight - markerRadius) * -1],
    'right': [-markerRadius, (markerHeight - markerRadius) * -1]
};

// 팝업 생성
const popup = new routogl.Popup({
  offset: popupOffsets,
  className: 'my-class',
  closeButton: true
}).setLngLat([127.0586339, 37.507009])
  .setHTML("<span>커스텀 팝업</span>")
  .setMaxWidth("500px")
  .addTo(map);

// 팝업 컨텐츠 DIV
const contentDiv = document.querySelector('.mapboxgl-popup-content');
contentDiv.style.width = '150px';
contentDiv.style.backgroundColor = 'yellow';

// 말풍선 하단 삼각형 Tip DIV
const tipDiv = document.querySelector('.mapboxgl-popup-tip');
tipDiv.style.borderTopColor = 'yellow';

// 닫기 Button
const closeButton = document.querySelector('.mapboxgl-popup-close-button');
closeButton.style.width = '50px';
closeButton.style.border = '1px solid black';
closeButton.style.backgroundColor = 'white';
closeButton.style.padding = '5px';
closeButton.textContent = '닫기';