/// <summary> /// enqueueens tile to cache /// </summary> /// <param name="task"></param> void EnqueueCacheTask(CacheQueueItem task) { lock (tileCacheQueue) { if (!tileCacheQueue.Contains(task)) { Debug.WriteLine("EnqueueCacheTask: " + task); tileCacheQueue.Enqueue(task); if (CacheEngine != null && CacheEngine.IsAlive) { WaitForCache.Set(); } #if PocketPC else if (CacheEngine == null || CacheEngine.State == ThreadState.Stopped || CacheEngine.State == ThreadState.Unstarted) #else else if (CacheEngine == null || CacheEngine.ThreadState == System.Threading.ThreadState.Stopped || CacheEngine.ThreadState == System.Threading.ThreadState.Unstarted) #endif { CacheEngine = null; CacheEngine = new Thread(new ThreadStart(CacheEngineLoop)) { Name = "CacheEngine", IsBackground = false, Priority = ThreadPriority.Lowest }; abortCacheLoop = false; CacheEngine.Start(); } } } }
/// <summary> /// Creates our event thread that will receive native events /// </summary> private void CreateGpsEventThread() { // we only want to create the thread if we don't have one created already // and we have opened the gps device if (gpsEventThread == null && gpsHandle != IntPtr.Zero) { // Create and start thread to listen for GPS events gpsEventThread = new Thread(new System.Threading.ThreadStart(WaitForGpsEvents)); gpsEventThread.IsBackground = false; gpsEventThread.Name = "GMap.NET GpsEvents"; gpsEventThread.Start(); } }
/// <summary> /// starts loader threads if needed /// </summary> void EnsureLoaderThreads() { #if !PocketPC while (GThreadPool.Count < 5) #else while (GThreadPool.Count < 2) #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(); } }
/// <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++) { 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> /// Creates our event thread that will receive native events /// </summary> private void CreateGpsEventThread() { // we only want to create the thread if we don't have one created already // and we have opened the gps device if(gpsEventThread == null && gpsHandle != IntPtr.Zero) { // Create and start thread to listen for GPS events gpsEventThread = new Thread(new System.Threading.ThreadStart(WaitForGpsEvents)); gpsEventThread.IsBackground = false; gpsEventThread.Name = "GMap.NET GpsEvents"; gpsEventThread.Start(); } }
/// <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(); } }
/// <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(); } }
/// <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 NET40 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 NET40 AddLoadTask(task); #else { if (!TileLoadQueue.Contains(task)) { TileLoadQueue.Push(task); } } #endif } } finally { TileDrawingListLock.ReleaseReaderLock(); } #if !NET40 #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 !NET40 _loadWaitCount = 0; Monitor.PulseAll(TileLoadQueue); } finally { Monitor.Exit(TileLoadQueue); } #endif UpdatingBounds = false; if (OnTileLoadStart != null) { OnTileLoadStart(); } }