Example #1
0
        public static IPropagatorBlock<TileRange, int[]> CreateTileRangePropagatorBlock(int z, TileRange bounds=null)
        {
            // var coordTransform = grid.CreateTileCoordTransform();

            var source = new BufferBlock<int[]>();

            var target = new ActionBlock<TileRange>((tilerange) => {

                for(int x =tilerange.MinX;x<=tilerange.MaxX;++x)
                    for(int y = tilerange.MinY;y<=tilerange.MaxY;++y)
                {
                    if (bounds != null && !bounds.ContainsXY(x, y))
                        continue;

                    var tilecoord=new int[] { z, x, y };
                    source.Post(tilecoord);
                }

            });

            // When the target is set to the completed state, propagate out any
            // remaining data and set the source to the completed state.
            target.Completion.ContinueWith(delegate
            {

                source.Complete();
            });

            return DataflowBlock.Encapsulate(target, source);
        }
Example #2
0
 public static TileRange CreateOrUpdate(int minX, int maxX, int minY, int maxY, TileRange tileRange = null)
 {
     if (tileRange != null)
     {
         tileRange.MinX = minX;
         tileRange.MaxX = maxX;
         tileRange.MinY = minY;
         tileRange.MaxY = maxY;
         return tileRange;
     }
     else
     {
         return new TileRange(minX, maxX, minY, maxY);
     }
 }
Example #3
0
        public IPropagatorBlock <TileRange, TileRange> CreateCoordinateTreeWalker(double[] originalExtent,
                                                                                  Func <int[], int[], double[], Task> callback, int?startz = null, int?endz = null)
        {
            var minzoom = startz ?? MinZoom;
            var maxzoom = (endz ?? MaxZoom);

            var coords = new IPropagatorBlock <int[], TileRange> [maxzoom - minzoom + 1];
            var tiles  = new IPropagatorBlock <TileRange, int[]> [maxzoom - minzoom + 1];

            var coordTransform = CreateTileCoordTransform();
            var to             = ProjectionInfo.FromEpsgCode(3857);
            Func <int[], Task <TileRange> > creator = async(coord) =>
            {
                var parentCoord = new int[] { coord[0] - 1, coord[1] >> 1, coord[2] >> 1 };
                var xyz         = coordTransform(coord, null, null);
                var parentXYZ   = coordTransform(parentCoord, null, null);
                //  Console.WriteLine(String.Join(", ", xyz));
                var tileExtent = GetTileCoordExtent(coord);


                await callback(xyz, parentXYZ, tileExtent);

                var range = GetTileCoordChildTileRange(coord);
                return(range);
            };

            var source = new BufferBlock <TileRange>();

            for (int z = minzoom; z <= maxzoom; ++z)
            {
                //int zoom = z;
                int zoomIdx = z - minzoom;
                tiles[zoomIdx]  = TileRange.CreateTileRangePropagatorBlock(z + 1, GetTileRangeForExtentAndZ(originalExtent, z + 1));
                coords[zoomIdx] = new TransformBlock <int[], TileRange>(creator);
                tiles[zoomIdx].LinkTo(coords[zoomIdx]);
                tiles[zoomIdx].Completion.ContinueWith(delegate
                {
                    Console.WriteLine("Completing coords[{0}]", zoomIdx + minzoom);
                    coords[zoomIdx].Complete();
                });

                if (z != minzoom)
                {
                    coords[zoomIdx - 1].LinkTo(tiles[zoomIdx]);
                    coords[zoomIdx - 1].Completion.ContinueWith(delegate
                    {
                        Console.WriteLine("Completing tiles[{0}]", zoomIdx + minzoom);
                        tiles[zoomIdx].Complete();
                    });
                }

                if (z == maxzoom)
                {
                    coords[zoomIdx].LinkTo(source);
                    coords[zoomIdx].Completion.ContinueWith(delegate
                    {
                        Console.WriteLine("Completing source[{0}]", zoomIdx + minzoom);
                        source.Complete();
                    });
                }
            }

            return(new CoordinateTreeWalker
            {
                coords = coords,
                tiles = tiles,
                block = DataflowBlock.Encapsulate(tiles[0], source)
            });
        }
Example #4
0
        public virtual bool ForEachTileCoordParentTileRange(int[] tileCoord, Func <int, TileRange, bool> callback, TileRange opt_tileRange = null, double[] opt_extent = null)
        {
            var tileCoordExtent = this.GetTileCoordExtent(tileCoord, opt_extent);
            var z = tileCoord[0] - 1;

            while (z >= this.MinZoom)
            {
                if (callback(z,
                             this.GetTileRangeForExtentAndZ(tileCoordExtent, z, opt_tileRange)))
                {
                    return(true);
                }
                --z;
            }
            return(false);
        }
Example #5
0
        /**
         * @param {ol.Extent} extent Extent.
         * @param {number} resolution Resolution.
         * @param {ol.TileRange=} opt_tileRange Temporary tile range object.
         * @return {ol.TileRange} Tile range.
         */
        public TileRange GetTileRangeForExtentAndResolution(double[] extent, double resolution, TileRange opt_tileRange = null)
        {
            var tileCoord = new int[3] {
                0, 0, 0
            };

            this.GetTileCoordForXYAndResolution_(
                extent[0], extent[1], resolution, false, tileCoord);
            var minX = tileCoord[1];
            var minY = tileCoord[2];

            this.GetTileCoordForXYAndResolution_(
                extent[2], extent[3], resolution, true, tileCoord);
            return(TileRange.CreateOrUpdate(
                       minX, tileCoord[1], minY, tileCoord[2], opt_tileRange));
        }
Example #6
0
 public static TileRange CreateOrUpdate(int minX, int maxX, int minY, int maxY, TileRange tileRange = null)
 {
     if (tileRange != null)
     {
         tileRange.MinX = minX;
         tileRange.MaxX = maxX;
         tileRange.MinY = minY;
         tileRange.MaxY = maxY;
         return(tileRange);
     }
     else
     {
         return(new TileRange(minX, maxX, minY, maxY));
     }
 }
Example #7
0
        public static IPropagatorBlock <TileRange, int[]> CreateTileRangePropagatorBlock(int z, TileRange bounds = null)
        {
            // var coordTransform = grid.CreateTileCoordTransform();



            var source = new BufferBlock <int[]>();

            var target = new ActionBlock <TileRange>((tilerange) => {
                for (int x = tilerange.MinX; x <= tilerange.MaxX; ++x)
                {
                    for (int y = tilerange.MinY; y <= tilerange.MaxY; ++y)
                    {
                        if (bounds != null && !bounds.ContainsXY(x, y))
                        {
                            continue;
                        }

                        var tilecoord = new int[] { z, x, y };
                        source.Post(tilecoord);
                    }
                }
            });

            // When the target is set to the completed state, propagate out any
            // remaining data and set the source to the completed state.
            target.Completion.ContinueWith(delegate
            {
                source.Complete();
            });

            return(DataflowBlock.Encapsulate(target, source));
        }