public MainPage()
        {
            InitializeComponent();

            _mapView = new MapsUIView
            {
                NativeMap       = InfoLayersSample.CreateMap(),
                BackgroundColor = Color.Black
            };
            _mapView.NativeMap.Info += MapOnInfo;

            ContentGrid.Children.Add(_mapView);
        }
Example #2
0
        public MainPage()
        {
            InitializeComponent();

            var mapControl = new MapsUIView();

            mapControl.NativeMap.Layers.Add(OpenStreetMap.CreateTileLayer());

            var centerOfWarsaw = new Point(21.107886, 52.2127475);
            // OSM uses spherical mercator coordinates. So transform the lon lat coordinates to spherical mercator
            var sphericalMercatorCoordinate = SphericalMercator.FromLonLat(centerOfWarsaw.X, centerOfWarsaw.Y);

            // Set the center of the viewport to the coordinate. The UI will refresh automatically
            mapControl.NativeMap.NavigateTo(sphericalMercatorCoordinate);
            // Additionally you might want to set the resolution, this could depend on your specific purpose
            mapControl.NativeMap.NavigateTo(mapControl.NativeMap.Resolutions[9]);

            var layer = GenerateIconLayer();

            mapControl.NativeMap.Layers.Add(layer);
            mapControl.NativeMap.InfoLayers.Add(layer);

            mapControl.NativeMap.Info += (sender, args) =>
            {
                var layername    = args.Layer?.Name;
                var featureLabel = args.Feature?["Label"]?.ToString();
                var featureType  = args.Feature?["Type"]?.ToString();

                if (!string.IsNullOrWhiteSpace(featureLabel))
                {
                    ShowPopup(featureLabel, featureType);
                }

                Debug.WriteLine("Info Event was invoked.");
                Debug.WriteLine("Layername: " + layername);
                Debug.WriteLine("Feature Label: " + featureLabel);
                Debug.WriteLine("Feature Type: " + featureType);

                Debug.WriteLine("World Postion: {0:F4} , {1:F4}", args.WorldPosition?.X, args.WorldPosition?.Y);
                Debug.WriteLine("Screen Postion: {0:F4} , {1:F4}", args.ScreenPosition?.X, args.ScreenPosition?.Y);
            };

            ContentGrid.Children.Add(mapControl);
        }