2016-07-15 2 views
0

오늘지도 타일에 대해 말하겠습니다!Xamarin Forms Maps - 타일 사용자 정의

개인 프로젝트와 내 회사 프로젝트의 경우 Xamarin.Forms.Maps를 많이 사용자 정의해야합니다. 나는이 튜토리얼을 찾았습니다. Custom Map Tiles in Xamarin.Forms Android 및 iOS (한 번 더 ..)에 대해서만 이야기합니다. 그러나 WinPhone 8.1 및/또는 UWP에서 어떻게 작동하는지 알고 싶습니다.

또한 Mapbox을 사용하므로이 프로젝트가 실제로 오랫동안 사용할 수 있는지 확인하고 싶습니다. (나는이 프로젝트에 대해 알고있는 사람들에게만 묻는다. 왜냐하면 나는 독서를 통해 정당한 사람을 알지 못하기 때문이다.)

내가 아는 한, 그것에 대해 몇 가지 nuget 패키지가 존재하지만 내가 정말 원하는 것을하지 않고

당신이 그것에 대해하거나 이미 그것을 한 경우 웹 사이트가있는 경우 (I 각 플랫폼 종속적 인 이상 사용자 정의 타일 원하는) 어떤 방향이나 어떤 도움을 주시겠습니까? 고마워!

EDIT 1

나는 UWP 렌더러이 코드를 찾았지만지도 타일을 변경하지 않습니다 ..

[assembly: ExportRenderer(typeof(CustomMap), typeof(CustomMapRenderer))] 
namespace MapTileProject.UWP.Renderer 
{ 
    public class CustomMapRenderer : MapRenderer 
    { 
     CustomMap customMap; 
     MapControl mapControl; 

     protected override void OnElementChanged(ElementChangedEventArgs<Map> e) 
     { 
      base.OnElementChanged(e); 

      if (e.NewElement != null) 
      { 
       customMap = e.NewElement as CustomMap; 
       mapControl = Control as MapControl; 

       UpdateTiles(); 
      } 
     } 

     private void UpdateTiles() 
     { 
      Debug.WriteLine("BEGINING !"); 
      HttpMapTileDataSource dataSource = new HttpMapTileDataSource(customMap.MapTileTemplate); 
      MapTileSource tileSource = new MapTileSource(dataSource); 
      mapControl.TileSources.Add(tileSource); 
      Debug.WriteLine("END !"); 
     } 
    } 
} 

답변

1

는 UWP 렌더러이 코드를 찾았지만, 지도 타일을 변경하지 않습니다

피들러를 사용하여 웹 요청을 확인하면 요청한 API URL이 inco임을 알 수 있습니다. rrect : enter image description here

참조 UWP의 표준 HttpMapTileDataSource이 같아야 Overlay tiles from a tile source

:

http://www.web 서비스 name.com/z={zoomlevel & X} = {X} = Y & {y}

X, Y 좌표 및 줌 레브 엘 : {개의 zoomLevel}, {X}, {Y}

그래서 우리가 먼저 MapTileTemplate 문자열을 변환해야합니다

[assembly: ExportRenderer(typeof(CustomMap), typeof(CustomMapRenderer))] 
namespace MapTileProject.UWP.Renderers 
{ 
    public class CustomMapRenderer : MapRenderer 
    { 
     CustomMap customMap; 
     MapControl mapControl; 

     protected override void OnElementChanged(ElementChangedEventArgs<Map> e) 
     { 
      base.OnElementChanged(e); 

      if (e.NewElement != null) 
      { 
       customMap = e.NewElement as CustomMap; 
       mapControl = Control as MapControl; 

       UpdateTiles(); 
      } 
     } 
     /// <summary> 
     /// Convert MapTileTemplate string to fit UWP HttpMapTileDataSource 
     /// </summary> 
     /// <param name="mapTileTemplate"></param> 
     /// <returns></returns> 
     private string GetTileTemplateForUWP(string mapTileTemplate) 
     { 
      return mapTileTemplate.Replace("{z}", "{zoomlevel}"); 
     } 

     private void UpdateTiles() 
     { 
      Debug.WriteLine("BEGINING !"); 
      HttpMapTileDataSource dataSource = new HttpMapTileDataSource(GetTileTemplateForUWP(customMap.MapTileTemplate)); 
      MapTileSource tileSource = new MapTileSource(dataSource); 
      mapControl.TileSources.Add(tileSource); 
      Debug.WriteLine("END !"); 
     } 
    } 

} 

스크린 샷 : enter image description here

+0

오 좋아! :) 지금 논리가 보인다><당신의 대답에 감사드립니다! – Emixam23