2016-06-14 62 views

回答

5

Mapbox Android SDK使用PNG文件作爲標記圖標。您可以將任何PNG文件用作圖標,換句話說,標記可以是任何您想要的顏色。 Heres an example帶有使用自定義圖標的標記。繼承人的代碼做的大部分工作:

  // Create an Icon object for the marker to use 
      IconFactory iconFactory = IconFactory.getInstance(MainActivity.this); 
      Drawable iconDrawable = ContextCompat.getDrawable(MainActivity.this, R.drawable.purple_marker); 
      Icon icon = iconFactory.fromDrawable(iconDrawable); 

      // Add the custom icon marker to the map 
      mapboxMap.addMarker(new MarkerOptions() 
        .position(new LatLng(-33.8500000, 18.4158234)) 
        .title("Cape Town Harbour") 
        .snippet("One of the busiest ports in South Africa") 
        .icon(icon)); 

這裏有一些標記我使用相同的風格爲默認圖標製作:

將這些在你的項目drawable-xxhdpi文件夾。這些是從Mapbox Android Demo app拉你可以從play store

+0

謝謝!不過,我認爲這不會讓我以編程方式更改顏色。我認爲這將有助於:http://stackoverflow.com/questions/11376516/change-drawable-color-programmatically –

+0

在我的情況下,我正在處理位圖作爲引腳gfx的來源不是內部應用程序內部來,但來從服務器。我必須從服務器上下載這個標記圖標。每次我在某些場合多次設置圖標時,標記會從地圖中移除。我想知道爲什麼?我猜它會去OOM。 –

2

讓你可以改變圖標的​​顏色編程

Drawable iconDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.your_marker, null); 
iconDrawable = DrawableCompat.wrap(iconDrawable); 
//Changing color to white 
DrawableCompat.setTint(iconDrawable, Color.WHITE); 
//Use this icon in addMarker(new MarkerOptions()... 
Icon icon = iconFactory.fromDrawable(iconDrawable);