2017-09-26 26 views
0

我寫一個Xamarin Xamarin的iOS變色窗體應用程序,它實現了Android和iOS的自定義地圖渲染器。我想實現自定義引腳,其中不同的顏色在我的地圖上表示不同的東西。的一些地圖銷

我添加銷到我的自定義地圖的代碼是在這裏:

List<BasicMapAnnotation> annotationList = new List<BasicMapAnnotation>(); 

for (int i = 0; i < userLocations.Count; i++) 
{ 
     LatLong latLongs = JsonConvert.DeserializeObject<LatLong>(userLocations[i].coords); 
     var annotation = new BasicMapAnnotation(new CLLocationCoordinate2D(Convert.ToDouble(latLongs.latitude), Convert.ToDouble(latLongs.longitude)), userLocations[i].user_id, "Latitude: " + latLongs.latitude.ToString() + " Longitude: " + latLongs.longitude.ToString()); 

     annotationList.Add(annotation); 
} 
nativeMap.AddAnnotations(annotationList.ToArray()); 

如何繪製我的腳時,我現在添加一些自定義登錄,使得它們是不同的顏色?

if(something()) 
{ 
    annotation.colour = Color.Green; 
} 

回答

1

我相信在iOS上你可以設置PinTintColor,但是在Android上你必須爲這個pin設置一個位圖。

看一看,特別是自定義渲染的source code for TK.Custom map on GitHub。他們展示瞭如何改變引腳的顏色。

這裏是從示出了改變的銷顏色iOS的自定義呈現代碼。

var pinAnnotationView = annotationView as MKPinAnnotationView; 
if (pinAnnotationView != null) 
{ 
    pinAnnotationView.AnimatesDrop = AnimateOnPinDrop; 

    var pinTintColorAvailable = pinAnnotationView.RespondsToSelector(new Selector("pinTintColor")); 

    if (!pinTintColorAvailable) 
    { 
     return; 
    } 

    if (pin.DefaultPinColor != Color.Default) 
    { 
     pinAnnotationView.PinTintColor = pin.DefaultPinColor.ToUIColor(); 
    } 
    else 
    { 
     pinAnnotationView.PinTintColor = UIColor.Red; 
    } 
} 
+0

你的意思是我應該可以使用類似annotation.PinTintColor的東西?因爲我不認爲註解有不幸 –

+0

我添加代碼,以我的回答改變顯示在iOS上的腳色這樣的功能 - 從TK.CustomMap的iOS渲染採取 –

+0

謝謝你,史蒂夫,如果是這樣的代碼中調用的自定義地圖渲染? –