Я пытаюсь вычислить простой маршрут между двумя маркерами в mapbox-gl-directions. Я хочу использовать событие .on('route')
, но он никогда не срабатывает. Я попытался перестроить пример, показанный в docs, но без успеха. Я сделал следующее:События в Mapbox-gl-направлениях не срабатывают
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 тоже.