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 ๐Ÿ”—

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 ๐Ÿ”—

 

 

Map | Mapbox GL JS

The Map object represents the map on your page. It exposes methods and properties that enable you to programmatically change the map, and fires events as users interact with it.

docs.mapbox.com

 

 

 


Thanks for ๐Ÿ™ˆ