MapControl.WPF Unable to load openstreetmap

驚鏵 1 Reputation point MVP
2021-05-15T10:44:47.387+00:00

TileSource Unable to load openstreetmap

XAML

<map:Map x:Name="map" ZoomLevel="5" Center="39.9132801985722,116.392009995601,0">  
            <map:Map.Mode>  
                <map:MercatorMode/>  
            </map:Map.Mode>  
            <local:OpenstreetmapTileLayer UriFormat="https://tile.openstreetmap.org/{z}/{x}/{y}.png"/>  
        </map:Map>  

XAML.CS

public class OpenstreetmapTileLayer : MapTileLayer   
    {  
        public OpenstreetmapTileLayer()  
        {  
            TileSource = new OpenstreetmapTileSource();  
        }  

        public string UriFormat  
        {  
            get { return TileSource.UriFormat; }  
            set { TileSource.UriFormat = value; }  
        }  
    }  


public class OpenstreetmapTileSource: TileSource  
    {  
        public override Uri GetUri(int x, int y, int zoomLevel)  
        {  
            var uri= new Uri(UriFormat.  
                       Replace("{x}", x.ToString()).  
                       Replace("{y}", y.ToString()).  
                       Replace("{z}", zoomLevel.ToString()));  
            Console.WriteLine(uri);  
            return uri;  
        }  
    }  

![96893-image.png]1

XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
808 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.