Exemple #1
0
        /// <summary>
        /// gets image from tile server
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="pos"></param>
        /// <param name="zoom"></param>
        /// <returns></returns>
        public PureImage GetImageFrom(GMapProvider provider, GPoint pos, int zoom, GPoint corepos, out Exception result)
        {
            PureImage ret = null;

            result = null;
            //GPoint corepos1 = new GPoint(corepos.X / 256, corepos.Y / 256);
            GPoint corepos2 = new GPoint(corepos.X, corepos.Y - 1);
            GPoint corepos3 = new GPoint(corepos.X + 1, corepos.Y - 1);
            GPoint corepos4 = new GPoint(corepos.X + 1, corepos.Y);

            try
            {
                var rtile = new RawTile(provider.DbId, pos, zoom);

                //let't check memmory first
//                if (UseMemoryCache)
//                {
//                    var m = MemoryCache.GetTileFromMemoryCache(rtile);
//                    if (m != null)
//                    {
//                        if (GMapProvider.TileImageProxy != null)
//                        {
//                            ret = GMapProvider.TileImageProxy.FromArray(m);
//                            if (ret == null)
//                            {
//#if DEBUG
//                                Debug.WriteLine("Image disposed in MemoryCache o.O, should never happen ;} " + new RawTile(provider.DbId, pos, zoom));
//                                if (Debugger.IsAttached)
//                                {
//                                    Debugger.Break();
//                                }
//#endif
//                                m = null;
//                            }
//                        }
//                    }
//                }

                if (ret == null)
                {
                    if (Mode != AccessMode.ServerOnly && !provider.BypassCache)
                    {
                        if (PrimaryCache != null)
                        {
                            // hold writer for 5s
                            //if (cacheOnIdleRead)
                            //{
                            //    Interlocked.Exchange(ref readingCache, 5);
                            //}

                            if (pos == corepos || pos == corepos2 || pos == corepos3 || pos == corepos4)//
                            {
                                CacheLocator.Location = @"D:\LOG\ProgramFiles\MapDownloader\MapCache";
                                //CacheLocator.Location = @"D:\LOG\CODE\MapDB";
                                provider = GMapProviders.AMapSateliteMap;
                                ret      = PrimaryCache.GetImageFromCache(1542757547, pos, zoom);//provider1.DbId
                            }
                            else
                            {
                                CacheLocator.Location = @"D:\LOG\CODE\MapDB";
                                //CacheLocator.Location = @"D:\LOG\ProgramFiles\MapDownloader\MapCache";
                                provider = GMapProviders.GoogleChinaSatelliteMap;
                                ret      = PrimaryCache.GetImageFromCache(provider.DbId, pos, zoom);
                            }
                            //ret = PrimaryCache.GetImageFromCache(provider.DbId, pos, zoom);//

                            //if (ret != null)
                            //{
                            //    if (UseMemoryCache)
                            //    {
                            //        MemoryCache.AddTileToMemoryCache(rtile, ret.Data.GetBuffer());
                            //    }
                            //    return ret;
                            //}
                        }

                        //if (SecondaryCache != null)
                        //{
                        //    // hold writer for 5s
                        //    if (cacheOnIdleRead)
                        //    {
                        //        Interlocked.Exchange(ref readingCache, 5);
                        //    }

                        //    ret = SecondaryCache.GetImageFromCache(provider.DbId, pos, zoom);
                        //    if (ret != null)
                        //    {
                        //        if (UseMemoryCache)
                        //        {
                        //            MemoryCache.AddTileToMemoryCache(rtile, ret.Data.GetBuffer());
                        //        }
                        //        EnqueueCacheTask(new CacheQueueItem(rtile, ret.Data.GetBuffer(), CacheUsage.First));
                        //        return ret;
                        //    }
                        //}
                    }

                    //if (Mode != AccessMode.CacheOnly)
                    //{
                    //    ret = provider.GetTileImage(pos, zoom);
                    //    {
                    //        // Enqueue Cache
                    //        if (ret != null)
                    //        {
                    //            if (UseMemoryCache)
                    //            {
                    //                MemoryCache.AddTileToMemoryCache(rtile, ret.Data.GetBuffer());
                    //            }

                    //            if (Mode != AccessMode.ServerOnly && !provider.BypassCache)
                    //            {
                    //                EnqueueCacheTask(new CacheQueueItem(rtile, ret.Data.GetBuffer(), CacheUsage.Both));
                    //            }
                    //        }
                    //    }
                    //}
                    //else
                    //{
                    //    result = noDataException;
                    //}
                }
            }
            catch (Exception ex)
            {
                result = ex;
                ret    = null;
                Debug.WriteLine("GetImageFrom: " + ex.ToString());
            }

            return(ret);
        }
Exemple #2
0
        // ...

        internal byte[] GetTileFromMemoryCache(RawTile tile)
        {
            kiberCacheLock.AcquireReaderLock();
            try
            {
                if (TilesInMemory.TryGetValue(tile, out byte[] ret))
Exemple #3
0
 public CacheQueueItem(RawTile tile, byte[] Img, CacheUsage cacheType)
 {
     this.Tile      = tile;
     this.Img       = Img;
     this.CacheType = cacheType;
 }