2016-04-13 14 views
0

地図上の任意の場所をクリックすると、地図上に原点を設定して運転目的地を設定するアプリ内にMapbox GL方向プラグインが使用されています。私は今、大規模な研究がそうする方法を理解できない場合でも、左上の検索元/宛先ボックスを削除しようとしています。どうすればいいか教えてください。ありがとう。私は以下の私のアプリで使用しています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]]); 

}); 

答えて

0

私はあなたがmap.addControl(new mapboxgl.Directions());は、コントローラを追加されたもので表示されますMapbox GL Javascriptを使用して、そしてthis exampleを見ていると仮定します。あなたのコード内には、これもmap.addControl(directions);があります。それを取り除き、何が起こるかを見てください。

希望すると便利です。

+0

を。単にソースと宛先の間に描かれたルートを削除します – MKM

1

ドキュメンテーションがないのでこれを理解することはできませんでしたが、最終的にmapbox-gl-directions.jsファイルを読んでいました。

あなたの例では、発信元/宛先ボックス除去するために、このようなコントロールを埋め込む必要があります:はMap.addControl(方向)を削除

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); 
+0

これはmapbox-gl-jsの方向apiを使用している間、入力を隠すための正しい使い方です。必要に応じてこのレポをチェックしてください。 https://github.com/mapbox/mapbox-gl-directions/blob/master/API.md –

関連する問題