Created
October 20, 2020 10:08
Leaf 튜토리얼 예제
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Custom Icons Tutorial - Leaflet</title> | |
<meta charset="utf-8"/> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" | |
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A==" | |
crossorigin=""/> | |
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js" | |
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA==" | |
crossorigin=""></script> | |
<style> | |
html, body { height: 100%; margin: 0; } | |
#map { width: 600px; height: 400px; } | |
</style> | |
</head> | |
<body> | |
<div id='map'></div> | |
<script> | |
/** | |
* [설명] | |
* 사용자 지정 아이콘을 만드려면 일반적으로 '이미지 / 그림자이미지' 2종류의 | |
* (배경이 투명한 PNG)이미지가 필요하다. | |
*/ | |
// 맵 객체 생성 | |
var map = L.map('map').setView([51.5, -0.09], 13); | |
// 타일레이어 연동 | |
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { | |
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' | |
}).addTo(map); | |
/** | |
* L.Icon 개체 생성 (녹색잎) | |
*/ | |
var greenIcon = L.icon({ | |
iconUrl: 'https://leafletjs.com/examples/custom-icons/leaf-green.png', | |
shadowUrl: 'https://leafletjs.com/examples/custom-icons/leaf-shadow.png', | |
iconSize: [38, 95], // size of the icon | |
shadowSize: [50, 64], // size of the shadow | |
iconAnchor: [22, 94], // point of the icon which will correspond to marker's location | |
shadowAnchor: [4, 62], // the same for the shadow | |
popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor | |
}); | |
/** | |
* 마커 아이콘은 마커를 생성할 때 옵션으로 전달되는 L.Icon 개체에 의해 정의된다. | |
*/ | |
L.marker([51.5, -0.09], {icon: greenIcon}).addTo(map); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment