Mapbox-gl-directions事件不会触发

时间:2016-10-22 21:53:49

标签: javascript routing mapbox mapbox-gl-js

我正在尝试计算mapbox-gl-directions中两个标记之间的简单路线。我想使用.on('route')事件,但它永远不会触发。我试图重建docs中显示的示例,但没有成功。我做了以下事情:

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

1 个答案:

答案 0 :(得分:1)

通过更新外部资源链接以使用最新版本的Mapbox GL和Mapbox GL Directions库,我能够让您的代码在您提供的JS Fiddle中运行。这意味着Mapbox GL JS的static public void restore(string ip, string user, string password, string[] tblList, string sourcedb, string targetdb) { try { string basecmd; basecmd = "/c mysql -h {0} -u {1} -p{2} {3} < {4}.sql"; foreach (string s in tblList) { string db_tbl = sourcedb + "_" + s; string cmd = String.Format(basecmd, ip, user, pass, targetdb, db_tbl); //cmd = cmd + " >error1234.txt"; System.Threading.Thread.Sleep(1000); Console.WriteLine(cmd); //System.Diagnostics.Process.Start("cmd.exe", cmd); System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", cmd); procStartInfo.UseShellExecute = false; procStartInfo.CreateNoWindow = true; System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo = procStartInfo; proc.Start(); //sendSuccesEmail(); } } catch (Exception ex) { Console.WriteLine(ex); Console.WriteLine("pause"); } } 已更改为v0.12.0,并且Directions插件的v0.26.0已更改为v1.0.0

v2.2.0

您在docs中找到的示例似乎自2015年12月发布以来未更新; here's a link指向更近期的路线示例并使用两个库的正确版本。最后,我可能会删除Mapbox.js的外部链接,因为在使用Mapbox GL JS时它们不是必需的。祝你好运!