Lang/Javascript
JS * Mapbox ์ฌ์ฉํ๊ธฐ ( ๊ธฐ์ด์ฌ์ฉ๋ฒ๋ง! )
___l_i_ *
2022. 1. 12. 15:05
์ค๊ตญ์์๋ google map ์ฌ์ฉ์ด ์ ์๋๋ค๊ณ ํ๋ค.
๋ ์ ์จ๋ด์ ๋ชจ๋ฅด๊ฒ ์ง๋ง.. ์๋ ๋จ๋ค... ๊ทธ๋ฆฌํ์ฌ ์ฌ์ฉํ๊ฒ ๋ Mapbox !
์ฌ์ค ์์ธํ ๋ด์ฉ์ ์๋ ๋ฌธ์๊ฐ ์ ์ ๋ฆฌ๋์ด ์์ด์ ํํ์ด์ง๋ฅผ ๋ฐฉ๋ฌธ ํ๋๊ฒ ๋น ๋ฅด๋ค.
๊ธฐ๋ณธ ๋ช๊ฐ์ง์ ๋ด์ฉ๋ง ์ ๋ฆฌํด ๋๋ค!
Map ๐
- Create map object and connect element by id.
- Clear default bottom-right info button if attributionControl option set false.
<div id='map' style='width: 400px; height: 300px;'></div>
<script>
// TO MAKE THE MAP APPEAR YOU MUST
// ADD YOUR ACCESS TOKEN FROM
// https://account.mapbox.com
mapboxgl.accessToken = 'YOUR_ACCESS_TOKEN';
const map = new mapboxgl.Map({
container: 'map', // container ID
style: 'mapbox://styles/mapbox/streets-v11', // style URL
center: [-74.5, 40], // starting position [lng, lat]
zoom: 9, // starting zoom
attributionControl: false // remove mapbox info(?) button
});
</script>
Marker ๐
- Draw marker on the map.
const marker = new mapboxgl.Marker({
color: "#FFFFFF"
}).setLngLat([-74.5, 40])
.addTo(map);
Custom Marker ๐
- Can create custom marker using HTML element.
- View full-screen demo page
Line Draw ๐
- Draw line between points
- If you want to change your map style, you add source and layer after style load
map.on('style.load', function(){
// addSource
// addLayer
});
Controller ๐
- Make map size to full screen
- Zoom map
- I think they don't support a style controller but you can make use setStyle option.
Thanks for ๐