2016-08-23 9 views
0

glマップボックスに2つ以上の公園を描画する方向があります。 私はこのコードを試しましたが、完全には動作しません。GLマップボックス内の複数点の方向描画

mapboxgl.accessToken = 'pk.eyJ1IjoiYWNoYWxwcmFqYXBhdGkiLCJhIjoiY2lyNGkwZGsxMDFpenUybHd5bjRtMjVjeiJ9.2teTa5MmVqOW-MDpryv56w'; 
      var map = new mapboxgl.Map({ 
       container: 'map', 
       style: 'mapbox://styles/achalprajapati/cis1byfch0008hgnitiwbym9c', 
       center: [-122.222461, 37.172263], 
       zoom: 8 
      }); 

      var directions = new mapboxgl.Directions({ 
       unit: 'metric', // Use the metric system to display distances. 
       profile: 'walking', // Set the initial profile to walking. 
       container: 'directions', // Specify an element thats not the map container. 
       // proximity: [-122.222453, 37.172271] // Give search results closer to these coordinates higher priority. 
      }); 
      debugger; 
      //map.addControl(new mapboxgl.Directions()); 
      //map.addControl(directions); 



      map.on('load', function() { 

       directions.setOrigin([-122.222461, 37.172263]); 
       directions.addWaypoint(0, [-122.222461, 37.172263]); 
       directions.addWaypoint(1, [-122.483318, 37.724502]); 
       directions.setDestination([-122.483318, 37.724502]); 

      }); 

      directions.on('route', function (e) { 
       console.log(e.route); // Logs the current route shown in the interface. 
      }); 

答えて

0

mapbox-gl-jsの最近の更新で、mapbox-gl-directionsプラグインにエラーが発生しました。ここで

は方向、setOrigin、setDestinationを削除する方法新しいバージョン(v2.2.0 of mapbox-gl-directionsプラグインとv0.22.1 of mapbox-gl-js

mapboxgl.accessToken = 'pk.eyJ1IjoiYWNoYWxwcmFqYXBhdGkiLCJhIjoiY2lyNGkwZGsxMDFpenUybHd5bjRtMjVjeiJ9.2teTa5MmVqOW-MDpryv56w'; 
var map = new mapboxgl.Map({ 
    container: 'map', 
    style: 'mapbox://styles/achalprajapati/cis1byfch0008hgnitiwbym9c', 
    center: [-122.222461, 37.172263], 
    zoom: 8 
}); 

var directions = new mapboxgl.Directions({ 
    unit: 'metric', // Use the metric system to display distances. 
    profile: 'walking', // Set the initial profile to walking. 
    container: 'directions', // Specify an element thats not the map container. 
}); 

map.addControl(directions) 

map.on('load', function() { 
    directions.setOrigin([-122.222461, 37.172263]); 
    directions.addWaypoint(0, [-122.222461, 37.172263]); 
    directions.addWaypoint(1, [-122.483318, 37.724502]); 
    directions.setDestination([-122.483318, 37.724502]); 
}); 

directions.on('route', function (e) { 
    console.log(e.route); // Logs the current route shown in the interface. 
}); 
+0

であなたのコードのworking jsfiddle ..です? –

関連する問題