Esempio n. 1
0
        private async Task ShowVehicleLocations()
        {
            var vehicleLocations = await searchVm.GetBusLocations();

            while (vehicleCounter > 0)
            {
                SearchMap.MapElements.RemoveAt(SearchMap.MapElements.Count - 1);
                vehicleCounter--;
            }

            var inboundBM = new WriteableBitmap(40, 40);
            await inboundBM.SetSourceAsync(await RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Inbound.png")).OpenReadAsync());

            var outboundBM = new WriteableBitmap(40, 40);
            await outboundBM.SetSourceAsync(await RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Outbound.png")).OpenReadAsync());

            foreach (Bus bus in vehicleLocations)
            {
                if (bus.direction.Equals("inbound"))
                {
                    var rotatedImage = inboundBM.RotateFree(bus.busHeading, false);
                    var stream = new InMemoryRandomAccessStream();
                    await rotatedImage.ToStream(stream, BitmapEncoder.PngEncoderId);

                    var busMarker = new MapIcon
                    {
                        Image = RandomAccessStreamReference.CreateFromStream(stream),
                        CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible,
                        Location = new Geopoint(new BasicGeoposition { Latitude = bus.latitude, Longitude = bus.longitude }),
                        NormalizedAnchorPoint = new Point(0.5, 0.5),
                        ZIndex = 99
                    };

                    SearchMap.MapElements.Add(busMarker);

                    await stream.FlushAsync();
                    stream.Dispose();
                    rotatedImage = null;
                }
                else if (bus.direction.Equals("outbound"))
                {
                    var rotatedImage = outboundBM.RotateFree(bus.busHeading, false);
                    var stream = new InMemoryRandomAccessStream();
                    await rotatedImage.ToStream(stream, BitmapEncoder.PngEncoderId);

                    var busMarker = new MapIcon
                    {
                        Image = RandomAccessStreamReference.CreateFromStream(stream),
                        CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible,
                        Location = new Geopoint(new BasicGeoposition { Latitude = bus.latitude, Longitude = bus.longitude }),
                        NormalizedAnchorPoint = new Point(0.5, 0.5),
                        ZIndex = 99
                    };

                    SearchMap.MapElements.Add(busMarker);

                    await stream.FlushAsync();
                    stream.Dispose();
                    rotatedImage = null;
                }
                vehicleCounter++;
            }

            inboundBM = null;
            outboundBM = null;
        }