Exemplo n.º 1
0
        private async void UWPSyncTileLayer_BitmapRequested(CustomMapTileDataSource sender, MapTileBitmapRequestedEventArgs args)
        {
            var deferral = args.Request.GetDeferral();

            try
            {
                var data = await _makeTileUri(args.X, args.Y, args.ZoomLevel);

                if (data != null)
                {
                    MemoryStream stream = new MemoryStream();
                    stream.Write(data, 0, data.Length);
                    stream.Position = 0;
                    var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream.AsRandomAccessStream());

                    var pixelProvider = await decoder.GetPixelDataAsync(Windows.Graphics.Imaging.BitmapPixelFormat.Rgba8, Windows.Graphics.Imaging.BitmapAlphaMode.Straight, new Windows.Graphics.Imaging.BitmapTransform(), Windows.Graphics.Imaging.ExifOrientationMode.RespectExifOrientation, Windows.Graphics.Imaging.ColorManagementMode.ColorManageToSRgb);

                    var pixelData = pixelProvider.DetachPixelData();
                    InMemoryRandomAccessStream randomAccessStream = new InMemoryRandomAccessStream();
                    IOutputStream outputStream = randomAccessStream.GetOutputStreamAt(0);
                    DataWriter    writer       = new DataWriter(outputStream);
                    writer.WriteBytes(pixelData);
                    await writer.StoreAsync();

                    await writer.FlushAsync();

                    args.Request.PixelData = RandomAccessStreamReference.CreateFromStream(randomAccessStream);
                }
                deferral.Complete();
            }
            catch (Exception ex)
            {
                deferral.Complete();
            }
        }
Exemplo n.º 2
0
        private async void CustomDataSource_BitmapRequested(
            CustomMapTileDataSource sender,
            MapTileBitmapRequestedEventArgs args)
        {
            var deferral = args.Request.GetDeferral();

            args.Request.PixelData = await CreateBitmapAsStreamAsync();

            deferral.Complete();
        }
Exemplo n.º 3
0
        private void LoadMap()
        {
            CustomMapTileDataSource customDataSource = new CustomMapTileDataSource();

            // Attach a handler for the BitmapRequested event.
            customDataSource.BitmapRequested += customDataSource_BitmapRequestedAsync;
            MapTileSource customTileSource = new MapTileSource(customDataSource);

            MyMapControl.TileSources.Add(customTileSource);
        }
Exemplo n.º 4
0
        public InvertMaskMapTileSource(Geopath path, Color colorIn, Color colorOut) : base()
        {
            Path     = path;
            ColorIn  = colorIn;
            ColorOut = colorOut;
            var dataSource = new CustomMapTileDataSource();

            dataSource.BitmapRequested += BitmapRequested;
            DataSource = dataSource;
        }
Exemplo n.º 5
0
        public MainPage()
        {
            this.InitializeComponent();

            CustomMapTileDataSource customDataSource = new CustomMapTileDataSource();

            // Attach a handler for the BitmapRequested event.
            customDataSource.BitmapRequested += customDataSource_BitmapRequestedAsync;
            MapTileSource customTileSource = new MapTileSource(customDataSource);

            myMap.TileSources.Add(customTileSource);

            // Customize component
            customTileSource.Layer           = MapTileLayer.BackgroundReplacement;
            customTileSource.IsFadingEnabled = false;
            myMap.Style         = MapStyle.None;
            myMap.MapProjection = MapProjection.WebMercator;
        }
Exemplo n.º 6
0
        void BitmapRequested(CustomMapTileDataSource sender, MapTileBitmapRequestedEventArgs args)
        {
            var deferral = args.Request.GetDeferral();
            IRandomAccessStreamReference referenceStream;
            double lat, lon = 0;
            int    pixelX, pixelY = 0;

            Microsoft.MapPoint.TileSystem.TileXYToPixelXY(args.X, args.Y, out pixelX, out pixelY);
            Microsoft.MapPoint.TileSystem.PixelXYToLatLong(pixelX, pixelY, args.ZoomLevel, out lat, out lon);
            BasicGeoposition northWest = new BasicGeoposition {
                Latitude = lat, Longitude = lon
            };

            Microsoft.MapPoint.TileSystem.PixelXYToLatLong(pixelX + (int)sizeOfMapTile, pixelY + (int)sizeOfMapTile, args.ZoomLevel, out lat, out lon);
            BasicGeoposition southEast = new BasicGeoposition {
                Latitude = lat, Longitude = lon
            };
            GeoboundingBox tileBox = new GeoboundingBox(northWest, southEast);

            if (tileBox.CollidesWith(PathBox))
            {
                if (PathCache.pointInPolygon(northWest.Longitude, northWest.Latitude) &&
                    PathCache.pointInPolygon(southEast.Longitude, southEast.Latitude) &&
                    PathCache.pointInPolygon(northWest.Longitude, southEast.Latitude) &&
                    PathCache.pointInPolygon(southEast.Longitude, northWest.Latitude))
                {
                    referenceStream = RandomAccessStreamReference.CreateFromStream(InTile);
                }
                else
                {
                    var cutter = new Windows.Storage.Streams.InMemoryRandomAccessStream();
                    cutTile(cutter, pixelX, pixelY, args.ZoomLevel);
                    referenceStream = RandomAccessStreamReference.CreateFromStream(cutter);
                }
            }
            else
            {
                referenceStream = RandomAccessStreamReference.CreateFromStream(OutTile);
            }

            args.Request.PixelData = referenceStream;
            deferral.Complete();
        }
Exemplo n.º 7
0
        private void CustTileSource_Checked(object sender, RoutedEventArgs e)
        {
            var customSource = new CustomMapTileDataSource();

            customSource.BitmapRequested += async(o, args) =>
            {
                var deferral = args.Request.GetDeferral();
                args.Request.PixelData = await CreateBitmapAsStreamAsync();

                deferral.Complete();
            };
            var ts = new MapTileSource(customSource)
            {
                Layer = MapTileLayer.BackgroundOverlay,
                IsTransparencyEnabled = true,
            };

            map1.TileSources.Add(ts);
        }
Exemplo n.º 8
0
    private async void BitmapRequestedHandler(CustomMapTileDataSource sender, MapTileBitmapRequestedEventArgs args)
    {
        var deferral = args.Request.GetDeferral();

        try
        {
            using (var imgStream = await GetTileAsStreamAsync(args.X, args.Y, args.ZoomLevel))
            {
                var memStream = imgStream.AsRandomAccessStream();
                var decoder   = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(memStream);

                var pixelProvider = await decoder.GetPixelDataAsync(Windows.Graphics.Imaging.BitmapPixelFormat.Rgba8, Windows.Graphics.Imaging.BitmapAlphaMode.Straight, new Windows.Graphics.Imaging.BitmapTransform(), Windows.Graphics.Imaging.ExifOrientationMode.RespectExifOrientation, Windows.Graphics.Imaging.ColorManagementMode.ColorManageToSRgb);

                var pixels = pixelProvider.DetachPixelData();
                var width  = decoder.OrientedPixelWidth;
                var height = decoder.OrientedPixelHeight;
                Parallel.For(0, height, i =>
                {
                    for (int j = 0; j <= width - 1; j++)
                    {
                        // Alpha channel Index (RGBA)
                        var idx = (i * height + j) * 4 + 3;
                    }
                });
                var randomAccessStream = new InMemoryRandomAccessStream();
                var outputStream       = randomAccessStream.GetOutputStreamAt(0);
                var writer             = new DataWriter(outputStream);
                writer.WriteBytes(pixels);
                await writer.StoreAsync();

                await writer.FlushAsync();

                args.Request.PixelData = RandomAccessStreamReference.CreateFromStream(randomAccessStream);
            }
        }
        catch
        {
        }
        deferral.Complete();
    }
Exemplo n.º 9
0
 private void CustTileSource_Checked(object sender, RoutedEventArgs e)
 {
     var customSource = new CustomMapTileDataSource();
     customSource.BitmapRequested += async (o, args) => 
     {
         var deferral = args.Request.GetDeferral();
         args.Request.PixelData = await CreateBitmapAsStreamAsync();
         deferral.Complete();
     };
     var ts = new MapTileSource(customSource)
     {
         Layer = MapTileLayer.BackgroundOverlay,
         IsTransparencyEnabled = true,
     }; 
     map1.TileSources.Add(ts);
 }
 public CustomMapTileDataSourceEvents(CustomMapTileDataSource This)
 {
     this.This = This;
 }