Пример #1
0
        /// <summary>
        /// updates map bounds
        /// </summary>
        void UpdateBounds()
        {
            if (!IsStarted || Provider.Equals(EmptyProvider.Instance))
            {
                return;
            }

            updatingBounds = true;

            tileDrawingListLock.AcquireWriterLock();
            try
            {
                #region -- find tiles around --
                tileDrawingList.Clear();

                for (long i = (int)Math.Floor(-sizeOfMapArea.Width * scaleX), countI = (int)Math.Ceiling(sizeOfMapArea.Width * scaleX); i <= countI; i++)
                {
                    for (long j = (int)Math.Floor(-sizeOfMapArea.Height * scaleY), countJ = (int)Math.Ceiling(sizeOfMapArea.Height * scaleY); j <= countJ; j++)
                    {
                        GPoint p = centerTileXYLocation;
                        p.X += i;
                        p.Y += j;

#if ContinuesMap
                        // ----------------------------
                        if (p.X < minOfTiles.Width)
                        {
                            p.X += (maxOfTiles.Width + 1);
                        }

                        if (p.X > maxOfTiles.Width)
                        {
                            p.X -= (maxOfTiles.Width + 1);
                        }
                        // ----------------------------
#endif

                        if (p.X >= minOfTiles.Width && p.Y >= minOfTiles.Height && p.X <= maxOfTiles.Width && p.Y <= maxOfTiles.Height)
                        {
                            DrawTile dt = new DrawTile()
                            {
                                PosXY       = p,
                                PosPixel    = new GPoint(p.X * tileRect.Width, p.Y * tileRect.Height),
                                DistanceSqr = (centerTileXYLocation.X - p.X) * (centerTileXYLocation.X - p.X) + (centerTileXYLocation.Y - p.Y) * (centerTileXYLocation.Y - p.Y)
                            };

                            if (!tileDrawingList.Contains(dt))
                            {
                                tileDrawingList.Add(dt);
                            }
                        }
                    }
                }

                if (GMaps.Instance.ShuffleTilesOnLoad)
                {
                    Stuff.Shuffle <DrawTile>(tileDrawingList);
                }
                else
                {
                    tileDrawingList.Sort();
                }
                #endregion
            }
            finally
            {
                tileDrawingListLock.ReleaseWriterLock();
            }

            Monitor.Enter(tileLoadQueue);
            try
            {
                tileDrawingListLock.AcquireReaderLock();
                try
                {
                    foreach (DrawTile p in tileDrawingList)
                    {
                        LoadTask task = new LoadTask(p.PosXY, Zoom);
                        {
                            if (!tileLoadQueue.Contains(task))
                            {
                                tileLoadQueue.Push(task);
                            }
                        }
                    }
                }
                finally
                {
                    tileDrawingListLock.ReleaseReaderLock();
                }

                #region -- starts loader threads if needed --

                lock (GThreadPool)
                {
                    while (GThreadPool.Count < GThreadPoolSize)
                    {
                        Thread t = new Thread(new ThreadStart(ProcessLoadTask));
                        {
                            t.Name         = "TileLoader: " + GThreadPool.Count;
                            t.IsBackground = true;
                            t.Priority     = ThreadPriority.BelowNormal;
                        }
                        GThreadPool.Add(t);

                        Debug.WriteLine("add " + t.Name + " to GThreadPool");

                        t.Start();
                    }
                }
                #endregion

                {
                    LastTileLoadStart = DateTime.Now;
                    Debug.WriteLine("OnTileLoadStart - at zoom " + Zoom + ", time: " + LastTileLoadStart.TimeOfDay);
                }

                loadWaitCount = 0;
                Monitor.PulseAll(tileLoadQueue);
            }
            finally
            {
                Monitor.Exit(tileLoadQueue);
            }

            updatingBounds = false;

            if (OnTileLoadStart != null)
            {
                OnTileLoadStart();
            }
        }
        /// <summary>
        ///     updates map bounds
        /// </summary>
        void UpdateBounds()
        {
            if (!IsStarted || Provider.Equals(EmptyProvider.Instance))
            {
                return;
            }

            UpdatingBounds = true;

            TileDrawingListLock.AcquireWriterLock();
            try
            {
                #region -- find tiles around --

                TileDrawingList.Clear();

                for (long i = (int)Math.Floor(-_sizeOfMapArea.Width * ScaleX),
                     countI = (int)Math.Ceiling(_sizeOfMapArea.Width * ScaleX);
                     i <= countI;
                     i++)
                {
                    for (long j = (int)Math.Floor(-_sizeOfMapArea.Height * ScaleY),
                         countJ = (int)Math.Ceiling(_sizeOfMapArea.Height * ScaleY);
                         j <= countJ;
                         j++)
                    {
                        var p = CenterTileXYLocation;
                        p.X += i;
                        p.Y += j;

#if ContinuesMap
                        // ----------------------------
                        if (p.X < minOfTiles.Width)
                        {
                            p.X += (maxOfTiles.Width + 1);
                        }

                        if (p.X > maxOfTiles.Width)
                        {
                            p.X -= (maxOfTiles.Width + 1);
                        }
                        // ----------------------------
#endif

                        if (p.X >= _minOfTiles.Width && p.Y >= _minOfTiles.Height && p.X <= _maxOfTiles.Width &&
                            p.Y <= _maxOfTiles.Height)
                        {
                            var dt = new DrawTile()
                            {
                                PosXY       = p,
                                PosPixel    = new GPoint(p.X * TileRect.Width, p.Y * TileRect.Height),
                                DistanceSqr = (CenterTileXYLocation.X - p.X) * (CenterTileXYLocation.X - p.X) +
                                              (CenterTileXYLocation.Y - p.Y) * (CenterTileXYLocation.Y - p.Y)
                            };

                            if (!TileDrawingList.Contains(dt))
                            {
                                TileDrawingList.Add(dt);
                            }
                        }
                    }
                }

                if (GMaps.Instance.ShuffleTilesOnLoad)
                {
                    Stuff.Shuffle(TileDrawingList);
                }
                else
                {
                    TileDrawingList.Sort();
                }

                #endregion
            }
            finally
            {
                TileDrawingListLock.ReleaseWriterLock();
            }

#if NET46
            Interlocked.Exchange(ref _loadWaitCount, 0);
#else
            Monitor.Enter(TileLoadQueue);
            try
            {
#endif
            TileDrawingListLock.AcquireReaderLock();
            try
            {
                foreach (var p in TileDrawingList)
                {
                    var task = new LoadTask(p.PosXY, Zoom, this);
#if NET46
                    AddLoadTask(task);
#else
                    {
                        if (!TileLoadQueue.Contains(task))
                        {
                            TileLoadQueue.Push(task);
                        }
                    }
#endif
                }
            }
            finally
            {
                TileDrawingListLock.ReleaseReaderLock();
            }

#if !NET46
            #region -- starts loader threads if needed --

            lock (_gThreadPool)
            {
                while (_gThreadPool.Count < GThreadPoolSize)
                {
                    var t = new Thread(TileLoadThread);
                    {
                        t.Name         = "TileLoader: " + _gThreadPool.Count;
                        t.IsBackground = true;
                        t.Priority     = ThreadPriority.BelowNormal;
                    }

                    _gThreadPool.Add(t);

                    Debug.WriteLine("add " + t.Name + " to GThreadPool");

                    t.Start();
                }
            }
            #endregion
#endif
            {
                _lastTileLoadStart = DateTime.Now;
                Debug.WriteLine("OnTileLoadStart - at zoom " + Zoom + ", time: " + _lastTileLoadStart.TimeOfDay);
            }
#if !NET46
            _loadWaitCount = 0;
            Monitor.PulseAll(TileLoadQueue);
        }

        finally
        {
            Monitor.Exit(TileLoadQueue);
        }
#endif
            UpdatingBounds = false;

            if (OnTileLoadStart != null)
            {
                OnTileLoadStart();
            }
        }
Пример #3
0
        /// <summary>
        /// updates map bounds
        /// </summary>
        void UpdateBounds()
        {
            if (MapType == NET.MapType.None)
            {
                return;
            }

            lock (tileLoadQueue)
            {
                tileDrawingListLock.AcquireWriterLock();
                try
                {
                    #region -- find tiles around --
                    tileDrawingList.Clear();

                    for (int i = -sizeOfMapArea.Width; i <= sizeOfMapArea.Width; i++)
                    {
                        for (int j = -sizeOfMapArea.Height; j <= sizeOfMapArea.Height; j++)
                        {
                            Point p = centerTileXYLocation;
                            p.X += i;
                            p.Y += j;

#if ContinuesMap
                            // ----------------------------
                            if (p.X < minOfTiles.Width)
                            {
                                p.X += (maxOfTiles.Width + 1);
                            }

                            if (p.X > maxOfTiles.Width)
                            {
                                p.X -= (maxOfTiles.Width + 1);
                            }
                            // ----------------------------
#endif

                            if (p.X >= minOfTiles.Width && p.Y >= minOfTiles.Height && p.X <= maxOfTiles.Width && p.Y <= maxOfTiles.Height)
                            {
                                if (!tileDrawingList.Contains(p))
                                {
                                    tileDrawingList.Add(p);
                                }
                            }
                        }
                    }

                    if (GMaps.Instance.ShuffleTilesOnLoad)
                    {
                        Stuff.Shuffle <Point>(tileDrawingList);
                    }
                    #endregion

                    foreach (Point p in tileDrawingList)
                    {
                        LoadTask task = new LoadTask(p, Zoom);
                        {
                            if (!tileLoadQueue.Contains(task))
                            {
                                tileLoadQueue.Enqueue(task);
                            }
                        }
                    }
                }
                finally
                {
                    tileDrawingListLock.ReleaseWriterLock();
                }

                #region -- starts loader threads if needed --
#if !PocketPC
                while (GThreadPool.Count < GThreadPoolSize)
#else
                while (GThreadPool.Count < GThreadPoolSize)
#endif
                {
                    Thread t = new Thread(new ThreadStart(ProcessLoadTask));
                    {
                        t.Name         = "GMap.NET TileLoader: " + GThreadPool.Count;
                        t.IsBackground = true;
                        t.Priority     = ThreadPriority.BelowNormal;
                    }
                    GThreadPool.Add(t);

                    Debug.WriteLine("add " + t.Name + " to GThreadPool");

                    t.Start();
                }
                #endregion

                lock (LastTileLoadStartEndLock)
                {
                    LastTileLoadStart = DateTime.Now;
                    Debug.WriteLine("OnTileLoadStart - at zoom " + Zoom + ", time: " + LastTileLoadStart.TimeOfDay);
                }

                loadWaitCount = 0;

#if !PocketPC
                Monitor.PulseAll(tileLoadQueue);
#else
                wait.PulseAll();
#endif
            }

            if (OnTileLoadStart != null)
            {
                OnTileLoadStart();
            }
        }
Пример #4
0
        /// <summary>
        /// updates map bounds
        /// </summary>
        void UpdateBounds()
        {
            if (!IsStarted || Provider.Equals(EmptyProvider.Instance))
            {
                return;
            }

            updatingBounds = true;

            tileDrawingListLock.AcquireWriterLock();
            try
            {
                #region -- find tiles around --
                tileDrawingList.Clear();

                for (long i = (int)Math.Floor(-sizeOfMapArea.Width * scaleX), countI = (int)Math.Ceiling(sizeOfMapArea.Width * scaleX); i <= countI; i++)
                {
                    for (long j = (int)Math.Floor(-sizeOfMapArea.Height * scaleY), countJ = (int)Math.Ceiling(sizeOfMapArea.Height * scaleY); j <= countJ; j++)
                    {
                        GPoint p = centerTileXYLocation;
                        p.X += i;
                        p.Y += j;

#if ContinuesMap
                        // ----------------------------
                        if (p.X < minOfTiles.Width)
                        {
                            p.X += (maxOfTiles.Width + 1);
                        }

                        if (p.X > maxOfTiles.Width)
                        {
                            p.X -= (maxOfTiles.Width + 1);
                        }
                        // ----------------------------
#endif

                        if (p.X >= minOfTiles.Width && p.Y >= minOfTiles.Height && p.X <= maxOfTiles.Width && p.Y <= maxOfTiles.Height)
                        {
                            DrawTile dt = new DrawTile()
                            {
                                PosXY       = p,
                                PosPixel    = new GPoint(p.X * tileRect.Width, p.Y * tileRect.Height),
                                DistanceSqr = (centerTileXYLocation.X - p.X) * (centerTileXYLocation.X - p.X) + (centerTileXYLocation.Y - p.Y) * (centerTileXYLocation.Y - p.Y)
                            };

                            if (!tileDrawingList.Contains(dt))
                            {
                                tileDrawingList.Add(dt);
                            }
                        }
                    }
                }

                if (GMaps.Instance.ShuffleTilesOnLoad)
                {
                    Stuff.Shuffle <DrawTile>(tileDrawingList);
                }
                else
                {
                    tileDrawingList.Sort();
                }
                #endregion
            }
            finally
            {
                tileDrawingListLock.ReleaseWriterLock();
            }

            Interlocked.Exchange(ref loadWaitCount, 0);

            tileDrawingListLock.AcquireReaderLock();
            try
            {
                foreach (DrawTile p in tileDrawingList)
                {
                    LoadTask task = new LoadTask(p.PosXY, Zoom, this);

                    AddLoadTask(task);
                }
            }
            finally
            {
                tileDrawingListLock.ReleaseReaderLock();
            }

            {
                LastTileLoadStart = DateTime.Now;
                Debug.WriteLine("OnTileLoadStart - at zoom " + Zoom + ", time: " + LastTileLoadStart.TimeOfDay);
            }

            updatingBounds = false;

            OnTileLoadStart?.Invoke();
        }