Xamarin custom map renderer for WinPhone

Emixam23Emixam23 USMember ✭✭✭

Hi,

I searched on the web but I can't find the way to make my custom renderer for windows phone 8.1.
My Android code is the following:

using Android.Gms.Maps;
using Android.Gms.Maps.Model;
using PROJECT.Droid;
using PROJECT;
using System.Collections.Generic;
using Xamarin.Forms;
using Xamarin.Forms.Maps;
using Xamarin.Forms.Maps.Android;
using System;

[assembly: ExportRenderer(typeof(CustomMap), typeof(CustomMapRenderer))]
namespace PROJECT.Droid
{
public class CustomMapRenderer : MapRenderer, IOnMapReadyCallback
{
    GoogleMap map;
    Polyline polyline;

    protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs<Xamarin.Forms.View> e)
    {
        base.OnElementChanged(e);

        if (e.OldElement != null)
        {
            // Unsubscribe
        }

        if (e.NewElement != null)
        {
            ((MapView)Control).GetMapAsync(this);
        }

        UpdatePolyLine();
    }

    protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    {
        base.OnElementPropertyChanged(sender, e);
        if (this.Element == null || this.Control == null)
            return;

        if (e.PropertyName == CustomMap.RouteCoordinatesProperty.PropertyName)
        {
            UpdatePolyLine();
        }
    }

    private void UpdatePolyLine()
    {
        if (map != null)
        {
            if (polyline != null)
            {
                polyline.Remove();
                polyline.Dispose();
            }
            var polylineOptions = new PolylineOptions();
            polylineOptions.InvokeColor(0x66FF0000);

            int a = 0;

            foreach (var position in ((CustomMap)this.Element).RouteCoordinates)
            {
                polylineOptions.Add(new LatLng(position.Latitude, position.Longitude));
                System.Diagnostics.Debug.Write(a++);
            }

            polyline = map.AddPolyline(polylineOptions);
        }
    }

    public void OnMapReady(GoogleMap googleMap)
    {
        map = googleMap;
        UpdatePolyLine();
    }
}
}

Does anyone can help me? :/ My iOS part is good as well

Best Answer

Answers

  • Emixam23Emixam23 USMember ✭✭✭

    Thank for your answer :)
    I didn't really do what I want to do.. I want to make my own CustomRenderer :/

Sign In or Register to comment.