首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Mapbox方向事件不会触发

Mapbox方向事件不会触发
EN

Stack Overflow用户
提问于 2016-10-22 21:53:49
回答 1查看 580关注 0票数 0

我试图在mapbox-gl-方向中的两个标记之间计算一个简单的路径。我想使用.on('route')事件,但它从不触发。我试着重建文档中显示的示例,但没有成功。我做了以下工作:

代码语言:javascript
运行
复制
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小提琴

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-10 21:00:47

通过更新外部资源链接以使用Mapbox和Mapbox方向库的最新版本,我能够让您的代码在您提供的JS Fiddle中运行。这意味着Mapbox的v0.12.0改为v0.26.0,方向插件的v1.0.0改为v2.2.0

代码语言:javascript
运行
复制
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.26.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.26.0/mapbox-gl.css' rel='stylesheet' />

<script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-directions/v2.2.0/mapbox-gl-directions.js'></script>
<link rel='stylesheet' href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-directions/v2.2.0/mapbox-gl-directions.css' type='text/css' />

看起来,您在文档中找到的示例自2015年12月发布以来一直没有更新;这里有一个链接给出了一个新的说明示例,该示例使用了两个库的正确版本。最后,我可能会删除到Mapbox.js的外部链接,因为它们在使用Mapbox.js时是不必要的。祝好运!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40197437

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档