0

我在我的应用程序中使用 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'        
 });

 map.addControl(directions);



 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]]);

 });
4

2 回答 2

1

由于没有文档,我也无法弄清楚这一点,但最后我通读了 mapbox-gl-directions.js 文件,我想我知道了如何去做。

在您的示例中,您应该嵌入这样的控件以删除源/目标框:

var directions = new mapboxgl.Directions({ 
  unit: 'metric',
  profile:'driving', 
  container:'directions', // Specify an element thats not the map container.
  // UI controls
  controls: {
    inputs: false,
    instructions: true
  }
});

map.addControl(directions);
于 2016-10-26T11:15:41.097 回答
0

我假设您使用的是 Mapbox GL Javascript,并且查看这个示例,它似乎map.addControl(new mapboxgl.Directions());是添加控制器的内容。在你给你的代码中,你也有这个map.addControl(directions);。尝试删除它,看看会发生什么。

希望这可以帮助!

于 2016-04-13T21:00:40.757 回答