0
我正試圖計算mapbox-gl-directions中兩個標記之間的簡單路線。我想使用.on('route')
事件,但它永遠不會觸發。我嘗試重建docs中顯示的示例,但沒有成功。我做了以下事情:Mapbox-gl-directions事件不會觸發
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v8'
});
var directions = new mapboxgl.Directions({
unit: 'metric', // Use the metric system to display distances.
profile: 'driving', // Set the initial profile to walking.
container: 'directions' // Specify an element thats not the map container.
});
map.on('load', function() {
directions.setOrigin([77.5045504332, 13.0386169339]); // On load, set the origin to "Toronto, Ontario".
directions.setDestination([77.5075504332, 13.0386169339]); // On load, set the destination to "Montreal, Quebec".
});
directions.on('route', function(e) {
alert("FIRE!")
});
爲什麼不激發這個事件? 這裏也是JS FIDDLE。