我的地圖框方向應用程序接口工作正常。顯示A點到b點。方向/指示當前覆蓋在地圖上。我想顯示他們,但在地圖下的另一個div。有辦法做到這一點嗎?
<div class="flex-child-grow bg-white h-viewport-2/3 h-viewport-full-mm" id="map"></div>
<script>
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/outdoors-v12',
center: [-3.13256, 54.59947], // starting position [lng, lat]
zoom: 9 // starting zoom
});
const directions = new MapboxDirections({
accessToken: mapboxgl.accessToken,
//unit: 'metric',
profile: 'mapbox/walking',
interactive: false,
controls: {
inputs: false,
instructions: true,
profileSwitcher: true,
attributionControl: false
}
});
map.addControl(directions);
map.on('load', () => {
directions.setOrigin([startLat, startLng]);
let bounds = new mapboxgl.LngLatBounds();
bounds.extend([startLat, startLng]);
bounds.extend([destLat, destLng]);
directions.setDestination([destLat, destLng]);
map.fitBounds(bounds, {padding: 900, duration: 3000});
});
</script>
這是你正在尋找的嗎?
<body>
<div id="map"></div>
<div id = 'directions'></div>
<script>
const plugin = new MapboxDirections({
accessToken: mapboxgl.accessToken,
profile: "mapbox/walking"
});
//add direction plug in to an existing div
document.getElementById('directions').appendChild(plugin.onAdd(map))
</script>
</body>