亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 Mapbox 繪制箭頭

如何使用 Mapbox 繪制箭頭

素胚勾勒不出你 2022-05-25 17:12:27
使用 Mapbox Android SDK 和 Annotation 插件,是否可以在線條上添加箭頭?如果沒有,有什么方法可以建議一條線的方向嗎?理想情況下,我希望有兩個標記,它們之間有一個箭頭,這樣用戶就知道要朝哪個方向行駛。
查看完整描述

2 回答

?
哆啦的時光機

TA貢獻1779條經驗 獲得超6個贊

不幸的是,Mapbox Lines 不支持此功能。但是,使用新的 Mapbox API v7 和 Annotations 插件,您可以執行以下操作來獲得您需要的內容。

1. 使用 LineManager 在 Mapview 上繪制一條線

2. 以度為單位計算 Line 的方位角 3. 按計算的度數

旋轉可繪制箭頭(可繪制可以是向上的箭頭)

4. 使用在 Mapview 上繪制符號符號管理器。該符號將放置在線的中間,并用作旋轉的可繪制對象的圖像


只需將此代碼放在 Mapview 活動中的任何位置


public void createLineAndArrow(){  


  //Declare the coordinates of the two points of the line

  float latitude1  = 34.1f;

  float longitude1 = 33.2f;

  float latitude2  = 35f;

  float longitude2 = 34.5f;


  //Calculate bearing of line

  double lat1Rad = Math.toRadians(latitude1);

  double lat2Rad = Math.toRadians(latitude2);

  double deltaLonRad = Math.toRadians(longitude2 - longitude1);

  double y = Math.sin(deltaLonRad) * Math.cos(lat2Rad);

  double x = Math.cos(lat1Rad) * Math.sin(lat2Rad) - Math.sin(lat1Rad) * 

             Math.cos(lat2Rad) * Math.cos(deltaLonRad);

  double bearing =  (Math.toDegrees(Math.atan2(y,x))+360)%360;


  //Draw the Line

  List<LatLng> lineVertices = new ArrayList<>();

  lineVertices.add(new LatLng(latitude1,longitude1));

  lineVertices.add(new LatLng(latitude2,longitude2));

  LineOptions lineOptions = new LineOptions().withLatLngs(lineVertices)

                        .withLineColor(ColorUtils.colorToRgbaString(Color.MAGENTA))

                        .withLineWidth(3f);

  LineManager lineManager = new LineManager(mapView, mapboxMap,mapboxMap.getStyle());

  lineManager.create(lineOptions);


  //Rotate the drawable

  Bitmap bmapOriginal = BitmapFactory.decodeResource(getResources(), 

                        R.drawable.arrowup);

  final Bitmap bmap = bmapOriginal.copy(Bitmap.Config.ARGB_8888, true);

  Matrix matrix = new Matrix();

  matrix.postRotate((float)bearing);

  Bitmap rotatedBitmap = Bitmap.createBitmap(bmap , 0, 0, bmap.getWidth(), 

                         bmap.getHeight(), matrix, true);

  Drawable d = new BitmapDrawable(getResources(), rotatedBitmap);


  //Add the drawable to the selected mapbox style

  mapboxMap.getStyle().addImage("rotatedImage",

                        BitmapUtils.getBitmapFromDrawable(d),

                        true);


 //Draw the Symbol in the middle of the Line

 SymbolOptions symbolOptions = new SymbolOptions().withIconImage("rotatedImage")

                          .withGeometry(Point.fromLngLat((longitude2+longitude1)/2, 

                          (latitude2+latitude1)/2));


 SymbolManager symbolManager = new SymbolManager(mapView, mapboxMap, 

                               mapboxMap.getStyle());

 symbolManager.create(symbolOptions);


}  

http://img1.sycdn.imooc.com//628df31700017bbe04420240.jpg

查看完整回答
反對 回復 2022-05-25
?
眼眸繁星

TA貢獻1873條經驗 獲得超9個贊

Mapbox 不支持開箱即用的箭頭,但您可以嘗試使用/Line#setPattern將添加到地圖的圖像名稱作為參數。您可以在此處閱讀有關該圖案圖像要求的更多信息。否則,您需要通過在地圖上正確定位和旋轉箭頭圖形 (a ) 來推出自定義解決方案。您可以使用樣式屬性和公開方法進行設置。Style#addImageMapboxMap#addImageSymbolsymbol-placementicon-rotation-alignmentSymbolManager


查看完整回答
反對 回復 2022-05-25
  • 2 回答
  • 0 關注
  • 651 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號