我有一个Mapbox GL地图,其中包含一个图层和该图层上的多个标记,我正在尝试使用Directions GL插件在我的应用中绘制路线+显示路线信息(距离/时间/从起点到目的地的路线)。不幸的是,除了设置起点/目的地(如下所示)之外,我无法找到任何其他信息来在我的地图上显示路线和路线数据。我能找到的唯一可用信息是MapBox GL行车路线示例中提到的信息,但这不是我真正想要的,因为我不想将起点/目的地显示为A和B点,也不显示A / B点搜索框,如上面的mapbox.com示例中所示。
有人可以通过告诉我我在这里缺少什么以及如何绘制始发地/目的地之间的路线,使用Mapbox GL插件显示路线信息来帮助我吗?谢谢
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v8',
center: [userCoordinates.coords.longitude, userCoordinates.coords.latitude],
zoom: 15
});
var directions = new mapboxgl.Directions({
unit: 'metric',
profile: 'driving'
});
directions.setOrigin([userCoordinates.coords.longitude, userCoordinates.coords.latitude]);
map.on('click', function(e) {
var features = map.queryRenderedFeatures(e.point, { layers: ['gsLayer'] });
if (!features.length) {
return;
}
var feature = features[0];
directions.setDestination([feature.geometry.coordinates[0], feature.geometry.coordinates[1]]);
});
听起来您根本不想使用插件,而是直接向Directions API发出请求。
我建议您看一下mapbox-sdk-js-一个有用的js库,用于发出客户端请求。有关指导的API文档可在此处找到。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句