/// <summary> /// Map moved to new position by dragging /// </summary> /// <param name="point"></param> public void UpdateRouteAndCarRefresh(GMapControl map) { if (RouteMain.Count == 0) { Visibility = Visibility.Hidden; return; } UpdateRouteUIPoints(_segmentMain, _figureMain, RouteMain, map); UpdateRouteUIPoints(_segmentPrev, _figurePrev, RoutePrev, map); //update car position if (_iCurrentPointIndex >= 0) { _car.Opacity = 0.8; GMap.NET.PointLatLng currentPosition = new GMap.NET.PointLatLng(RouteMain[_iCurrentPointIndex].Latitude, RouteMain[_iCurrentPointIndex].Longitude); GMap.NET.GPoint pt0 = map.FromLatLngToLocal(currentPosition); Point ptCar = new Point(pt0.X, pt0.Y); Canvas.SetLeft(_car, ptCar.X - _car.ActualWidth * _car.RenderTransformOrigin.X); //middle width Canvas.SetTop(_car, ptCar.Y - _car.ActualHeight * _car.RenderTransformOrigin.Y); //toward the front of car carDirection.Angle = RouteMain[_iCurrentPointIndex].Course; UpdateCarScale(map.Zoom); } else { _car.Opacity = 0.1; } Visibility = Visibility.Visible; }
public override GMap.NET.GPoint FromLatLngToPixel(double lat, double lng, int zoom) { if (m_buffer1.ContainsKey(lat) && m_buffer1[lat].ContainsKey(lng) && m_buffer1[lat][lng].ContainsKey(zoom)) { return(m_buffer1[lat][lng][zoom]); } GMap.NET.GPoint p = base.FromLatLngToPixel(lat, lng, zoom); GMap.NET.GPoint offset = GoogleMapChinaOffset.Instance.GetOffset(lat, lng, zoom); p = p + new GMap.NET.GSize(offset.X, offset.Y); if (!m_buffer1.ContainsKey(lat)) { m_buffer1[lat] = new Dictionary <double, Dictionary <int, GMap.NET.GPoint> >(); } if (!m_buffer1[lat].ContainsKey(lng)) { m_buffer1[lat][lng] = new Dictionary <int, GMap.NET.GPoint>(); } if (!m_buffer1[lat][lng].ContainsKey(zoom)) { m_buffer1[lat][lng][zoom] = p; } return(p); }
public System.Drawing.Size?GetOffsetFromCache(GMap.NET.GPoint pos, int zoom) { System.Drawing.Size?ret = null; { if (Initialize()) { try { lock (cmdFetch) { cmdFetch.Parameters["@x"].Value = pos.X; cmdFetch.Parameters["@y"].Value = pos.Y; cmdFetch.Parameters["@zoom"].Value = zoom; using (SqlDataReader odata = cmdFetch.ExecuteReader()) { if (odata.Read()) { ret = new System.Drawing.Size(odata.GetInt32(0), odata.GetInt32(1)); } } } } catch (Exception) { ret = null; Dispose(); } } } return(ret); }
public override GMap.NET.PointLatLng FromPixelToLatLng(int x, int y, int zoom) { if (m_buffer2.ContainsKey(x) && m_buffer2[x].ContainsKey(y) && m_buffer2[x][y].ContainsKey(zoom)) { return(m_buffer2[x][y][zoom]); } GMap.NET.PointLatLng p = base.FromPixelToLatLng(x, y, zoom); GMap.NET.GPoint offset = GoogleMapChinaOffset.Instance.GetOffset(p.Lat, p.Lng, zoom); p = base.FromPixelToLatLng(x - offset.X, y - offset.Y, zoom); if (!m_buffer2.ContainsKey(x)) { m_buffer2[x] = new Dictionary <int, Dictionary <int, GMap.NET.PointLatLng> >(); } if (!m_buffer2[x].ContainsKey(y)) { m_buffer2[x][y] = new Dictionary <int, GMap.NET.PointLatLng>(); } if (!m_buffer2[x][y].ContainsKey(zoom)) { m_buffer2[x][y][zoom] = p; } return(p); }
public GMap.NET.GPoint?GetOffsetFromCache(int key) { GMap.NET.GPoint?ret = null; try { using (SQLiteConnection connection = new SQLiteConnection()) { connection.ConnectionString = this.ConnectionString; connection.Open(); using (DbCommand command = connection.CreateCommand()) { command.CommandText = string.Format(sqlSelect, new object[] { key }); using (DbDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) { if (reader.Read()) { ret = new GMap.NET.GPoint(reader.GetInt32(1), reader.GetInt32(0)); } reader.Close(); } } connection.Close(); } } catch (System.Data.SQLite.SQLiteException) { } catch (Exception) { } return(ret); }
public bool PutOffsetToCache(GMap.NET.GPoint pos, int zoom, System.Drawing.Size offset) { bool ret = true; { if (Initialize()) { try { lock (cmdInsert) { cmdInsert.Parameters["@x"].Value = pos.X; cmdInsert.Parameters["@y"].Value = pos.Y; cmdInsert.Parameters["@zoom"].Value = zoom; cmdInsert.Parameters["@offsetx"].Value = offset.Width; cmdInsert.Parameters["@offsety"].Value = offset.Height; cmdInsert.ExecuteNonQuery(); } } catch (Exception) { ret = false; Dispose(); } } } return(ret); }
public GMap.NET.PointLatLng GetAntiOffseted(GMap.NET.PointLatLng latLon) { System.Drawing.Size offset = GetOffset(latLon.Lat, latLon.Lng, 18).Value; GMap.NET.GPoint point = m_projection.FromLatLngToPixel(latLon, 18); point = point - new GMap.NET.GSize(offset.Width, offset.Height); return(m_projection.FromPixelToLatLng(point, 18)); }
//public static bool ExportMapDataToDB(string sourceFile, string destFile) //{ // bool flag = true; // try // { // if (!File.Exists(destFile)) // { // flag = CreateEmptyDB(destFile); // } // if (!flag) // { // return flag; // } // using (SQLiteConnection connection = new SQLiteConnection()) // { // connection.ConnectionString = string.Format("Data Source=\"{0}\";Page Size=32768;Pooling=True", sourceFile); // connection.Open(); // if (connection.State == ConnectionState.Open) // { // using (SQLiteConnection connection2 = new SQLiteConnection()) // { // connection2.ConnectionString = string.Format("Data Source=\"{0}\";Page Size=32768;Pooling=True", destFile); // connection2.Open(); // if (connection2.State == ConnectionState.Open) // { // using (SQLiteCommand command = new SQLiteCommand(string.Format("ATTACH DATABASE \"{0}\" AS Source", sourceFile), connection2)) // { // command.ExecuteNonQuery(); // } // using (SQLiteTransaction transaction = connection2.BeginTransaction()) // { // try // { // List<long> list = new List<long>(); // using (SQLiteCommand command2 = new SQLiteCommand("SELECT id, X, Y, Zoom, Type FROM Tiles;", connection)) // { // using (SQLiteDataReader reader = command2.ExecuteReader()) // { // while (reader.Read()) // { // long item = reader.GetInt64(0); // using (SQLiteCommand command3 = new SQLiteCommand(string.Format("SELECT id FROM Tiles WHERE X={0} AND Y={1} AND Zoom={2} AND Type={3};", new object[] { reader.GetInt32(1), reader.GetInt32(2), reader.GetInt32(3), reader.GetInt32(4) }), connection2)) // { // using (SQLiteDataReader reader2 = command3.ExecuteReader()) // { // if (!reader2.Read()) // { // list.Add(item); // } // } // continue; // } // } // } // } // foreach (long num2 in list) // { // using (SQLiteCommand command4 = new SQLiteCommand(string.Format("INSERT INTO Tiles(X, Y, Zoom, Type) SELECT X, Y, Zoom, Type FROM Source.Tiles WHERE id={0}; INSERT INTO TilesData(id, Tile) Values((SELECT last_insert_rowid()), (SELECT Tile FROM Source.TilesData WHERE id={0}));", num2), connection2)) // { // command4.Transaction = transaction; // command4.ExecuteNonQuery(); // continue; // } // } // list.Clear(); // transaction.Commit(); // } // catch // { // transaction.Rollback(); // flag = false; // } // return flag; // } // } // return flag; // } // } // return flag; // } // } // catch (Exception) // { // flag = false; // } // return flag; //} public System.Drawing.Size?GetOffsetFromCache(GMap.NET.GPoint pos, int zoom) { System.Drawing.Size?ret = null; try { using (SQLiteConnection connection = new SQLiteConnection()) { connection.ConnectionString = this.ConnectionString; connection.Open(); using (DbCommand command = connection.CreateCommand()) { command.CommandText = string.Format(sqlSelect, new object[] { pos.X, pos.Y, zoom }); using (DbDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) { if (reader.Read()) { ret = new System.Drawing.Size(reader.GetInt32(0), reader.GetInt32(1)); } reader.Close(); } } connection.Close(); } } catch (Exception) { ret = null; } return(ret); }
private void BUT_geinjection_Click(object sender, EventArgs e) { GMapControl MainMap = new GMapControl(); MainMap.MapType = GMap.NET.MapType.GoogleSatellite; MainMap.CacheLocation = Path.GetDirectoryName(Application.ExecutablePath) + "/gmapcache/"; FolderBrowserDialog fbd = new FolderBrowserDialog(); try { fbd.SelectedPath = @"C:\Users\hog\Documents\albany 2011\New folder"; } catch { } fbd.ShowDialog(); if (fbd.SelectedPath != "") { string[] files = Directory.GetFiles(fbd.SelectedPath, "*.jpg", SearchOption.AllDirectories); string[] files1 = Directory.GetFiles(fbd.SelectedPath, "*.png", SearchOption.AllDirectories); int origlength = files.Length; Array.Resize(ref files, origlength + files1.Length); Array.Copy(files1, 0, files, origlength, files1.Length); foreach (string file in files) { log.Info(DateTime.Now.Millisecond + " Doing " + file); Regex reg = new Regex(@"Z([0-9]+)\\([0-9]+)\\([0-9]+)"); Match mat = reg.Match(file); int temp = 1 << int.Parse(mat.Groups[1].Value); GMap.NET.GPoint pnt = new GMap.NET.GPoint(int.Parse(mat.Groups[3].Value), int.Parse(mat.Groups[2].Value)); BUT_geinjection.Text = file; BUT_geinjection.Refresh(); //MainMap.Projection. MemoryStream tile = new MemoryStream(); Image Img = Image.FromFile(file); Img.Save(tile, System.Drawing.Imaging.ImageFormat.Jpeg); tile.Seek(0, SeekOrigin.Begin); log.Info(pnt.X + " " + pnt.Y); Application.DoEvents(); MainMap.Manager.ImageCacheLocal.PutImageToCache(tile, GMap.NET.MapType.Custom, pnt, int.Parse(mat.Groups[1].Value)); // Application.DoEvents(); } } }
public void ConvertCoordGroundToPixel(double GroundX, double GroundY, ref int PixelX, ref int PixelY) { GMap.NET.PointLatLng Position = new GMap.NET.PointLatLng(); Position.Lat = GroundY; Position.Lng = GroundX; GMap.NET.GPoint p = FromLatLngToLocal(Position); PixelX = (int)p.X; PixelY = (int)p.Y; }
public bool PutOffsetToCache(GMap.NET.GPoint pos, int zoom, System.Drawing.Size offset) { bool flag = true; if (this.Created) { try { using (SQLiteConnection connection = new SQLiteConnection()) { connection.ConnectionString = this.ConnectionString; connection.Open(); DbTransaction transaction = connection.BeginTransaction(); try { using (DbCommand command = connection.CreateCommand()) { command.Transaction = transaction; command.CommandText = "INSERT INTO GoogleMapOffsetCache([X], [Y], [Zoom], [OffsetX], [OffsetY] ) VALUES(@x, @y, @zoom, @offsetx, @offsety)"; command.Parameters.Add(new SQLiteParameter("@x", pos.X)); command.Parameters.Add(new SQLiteParameter("@y", pos.Y)); command.Parameters.Add(new SQLiteParameter("@zoom", zoom)); command.Parameters.Add(new SQLiteParameter("@offsetx", offset.Width)); command.Parameters.Add(new SQLiteParameter("@offsety", offset.Height)); command.ExecuteNonQuery(); } //using (DbCommand command2 = connection.CreateCommand()) //{ // command2.Transaction = transaction; // command2.CommandText = "INSERT INTO TilesData(id, Tile) VALUES((SELECT last_insert_rowid()), @p1)"; // command2.Parameters.Add(new SQLiteParameter("@p1", tile.GetBuffer())); // command2.ExecuteNonQuery(); //} transaction.Commit(); } catch (Exception) { transaction.Rollback(); flag = false; } finally { if (transaction != null) { transaction.Dispose(); } } connection.Close(); } } catch (Exception) { flag = false; } } return(flag); }
public GMap.NET.PointLatLng GetAntiOffseted(GMap.NET.PointLatLng latLon) { GMap.NET.GPoint offset = GetOffset(latLon.Lat, latLon.Lng, 18); if (offset == GMap.NET.GPoint.Empty) { return(latLon); } GMap.NET.GPoint point = m_projection.FromLatLngToPixel(latLon, 18); point = point - new GMap.NET.GSize(offset.X, offset.Y); return(m_projection.FromPixelToLatLng(point, 18)); }
public override GMap.NET.PureImage GetTileImage(GMap.NET.GPoint pos, int zoom) { var path = $"{Environment.CurrentDirectory}\\Images\\Map\\{zoom}\\{pos.X}\\{pos.Y}.png"; if (File.Exists(path)) { return(GMapImageProxy.Instance.FromArray(File.ReadAllBytes(path))); } var blankImagePath = $"{Environment.CurrentDirectory}\\Images\\blank.png"; return(GMapImageProxy.Instance.FromArray(File.ReadAllBytes(blankImagePath))); }
public bool PutOffsetToCache(int key, GMap.NET.GPoint offset) { bool flag = false; if (this.Created) { using (SQLiteConnection connection = new SQLiteConnection()) { connection.ConnectionString = this.ConnectionString; connection.Open(); DbTransaction transaction = connection.BeginTransaction(); try { using (DbCommand command = connection.CreateCommand()) { command.Transaction = transaction; command.CommandText = sqlInsert; command.Parameters.Add(new SQLiteParameter("@Id", key)); command.Parameters.Add(new SQLiteParameter("@dlat", offset.Y)); command.Parameters.Add(new SQLiteParameter("@dlon", offset.X)); command.ExecuteNonQuery(); } transaction.Commit(); flag = true; } catch (System.Data.SQLite.SQLiteException) { } catch (Exception) { transaction.Rollback(); } finally { if (transaction != null) { transaction.Dispose(); } } connection.Close(); } } return(flag); }
public GMap.NET.GPoint GetOffset(double lat, double lon, int zoom) { if (zoom < 11) { return(GMap.NET.GPoint.Empty); } if (lat > 53.55 || lat < 18.15 || lon > 134.79 || lon < 73.65) { return(GMap.NET.GPoint.Empty); //throw new ArgumentException("lat or lon is beyond the limit!"); } if (zoom == 19) { GMap.NET.GPoint ret1 = GetOffset(lat, lon, 18); return(new GMap.NET.GPoint(2 * ret1.X, 2 * ret1.Y)); } if (zoom > 18) { throw new ArgumentException("zoom is beyond the limit!"); } Int16 iLat = (Int16)((Int16)Math.Round(lat * 100) + 9000); //纬度, 最大18000 Int16 iLon = (Int16)Math.Round(lon * 100); Int32 key = ((Int32)iLat << 16) + iLon; GMap.NET.GPoint offset = GetOffset(key); if (offset == null || offset == GMap.NET.GPoint.Empty) { return(GMap.NET.GPoint.Empty); } else { int dz = (int)Math.Pow(2, 18 - zoom); return(new GMap.NET.GPoint(offset.X / dz, offset.Y / dz)); } }
// tile consumer thread void ProcessLoadTask() { LoadTask?task = null; long lastTileLoadTimeMs; bool stop = false; #if !PocketPC Thread ct = Thread.CurrentThread; string ctid = "Thread[" + ct.ManagedThreadId + "]"; #else int ctid = 0; #endif while (!stop && IsStarted) { task = null; Monitor.Enter(tileLoadQueue); try { while (tileLoadQueue.Count == 0) { Debug.WriteLine(ctid + " - Wait " + loadWaitCount + " - " + DateTime.Now.TimeOfDay); if (++loadWaitCount >= GThreadPoolSize) { loadWaitCount = 0; #region -- last thread takes action -- { LastTileLoadEnd = DateTime.Now; lastTileLoadTimeMs = (long)(LastTileLoadEnd - LastTileLoadStart).TotalMilliseconds; } #region -- clear stuff-- if (IsStarted) { GMaps.Instance.MemoryCache.RemoveOverload(); tileDrawingListLock.AcquireReaderLock(); try { Matrix.ClearLevelAndPointsNotIn(Zoom, tileDrawingList); } finally { tileDrawingListLock.ReleaseReaderLock(); } } #endregion UpdateGroundResolution(); #if UseGC GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); #endif Debug.WriteLine(ctid + " - OnTileLoadComplete: " + lastTileLoadTimeMs + "ms, MemoryCacheSize: " + GMaps.Instance.MemoryCache.Size + "MB"); if (OnTileLoadComplete != null) { OnTileLoadComplete(lastTileLoadTimeMs); } #endregion } if (!IsStarted || false == Monitor.Wait(tileLoadQueue, WaitForTileLoadThreadTimeout, false) || !IsStarted) { stop = true; break; } } if (IsStarted && !stop || tileLoadQueue.Count > 0) { task = tileLoadQueue.Pop(); } } finally { Monitor.Exit(tileLoadQueue); } if (task.HasValue && IsStarted) { try { #region -- execute -- var m = Matrix.GetTileWithReadLock(task.Value.Zoom, task.Value.Pos); if (!m.NotEmpty) { Debug.WriteLine(ctid + " - try load: " + task); Tile t = new Tile(task.Value.Zoom, task.Value.Pos); foreach (var tl in provider.Overlays) { int retry = 0; do { PureImage img = null; Exception ex = null; if (!provider.MaxZoom.HasValue || task.Value.Zoom <= provider.MaxZoom) { if (skipOverZoom == 0 || task.Value.Zoom <= skipOverZoom) { // tile number inversion(BottomLeft -> TopLeft) if (tl.InvertedAxisY) { img = GMaps.Instance.GetImageFrom(tl, new GPoint(task.Value.Pos.X, maxOfTiles.Height - task.Value.Pos.Y), task.Value.Zoom, out ex); } else // ok { img = GMaps.Instance.GetImageFrom(tl, task.Value.Pos, task.Value.Zoom, out ex); } } } if (img != null && ex == null) { if (okZoom < task.Value.Zoom) { okZoom = task.Value.Zoom; skipOverZoom = 0; Debug.WriteLine("skipOverZoom disabled, okZoom: " + okZoom); } } else if (ex != null) { if (skipOverZoom != okZoom) { if (ex.Message.Contains("(404) Not Found")) { skipOverZoom = okZoom; Debug.WriteLine("skipOverZoom enabled: " + skipOverZoom); } } } // check for parent tiles if not found if (img == null && okZoom > 0 && fillEmptyTiles && Provider.Projection is MercatorProjection) { int zoomOffset = task.Value.Zoom > okZoom ? task.Value.Zoom - okZoom : 1; long Ix = 0; GPoint parentTile = GPoint.Empty; while (img == null && zoomOffset < task.Value.Zoom) { Ix = (long)Math.Pow(2, zoomOffset); parentTile = new GMap.NET.GPoint((task.Value.Pos.X / Ix), (task.Value.Pos.Y / Ix)); img = GMaps.Instance.GetImageFrom(tl, parentTile, task.Value.Zoom - zoomOffset++, out ex); } if (img != null) { // offsets in quadrant long Xoff = Math.Abs(task.Value.Pos.X - (parentTile.X * Ix)); long Yoff = Math.Abs(task.Value.Pos.Y - (parentTile.Y * Ix)); img.IsParent = true; img.Ix = Ix; img.Xoff = Xoff; img.Yoff = Yoff; // wpf //var geometry = new RectangleGeometry(new Rect(Core.tileRect.X + 0.6, Core.tileRect.Y + 0.6, Core.tileRect.Width + 0.6, Core.tileRect.Height + 0.6)); //var parentImgRect = new Rect(Core.tileRect.X - Core.tileRect.Width * Xoff + 0.6, Core.tileRect.Y - Core.tileRect.Height * Yoff + 0.6, Core.tileRect.Width * Ix + 0.6, Core.tileRect.Height * Ix + 0.6); // gdi+ //System.Drawing.Rectangle dst = new System.Drawing.Rectangle((int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); //System.Drawing.RectangleF srcRect = new System.Drawing.RectangleF((float)(Xoff * (img.Img.Width / Ix)), (float)(Yoff * (img.Img.Height / Ix)), (img.Img.Width / Ix), (img.Img.Height / Ix)); } } if (img != null) { Debug.WriteLine(ctid + " - tile loaded: " + img.Data.Length / 1024 + "KB, " + task); { t.AddOverlay(img); } break; } else { if (ex != null) { lock (FailedLoads) { if (!FailedLoads.ContainsKey(task.Value)) { FailedLoads.Add(task.Value, ex); if (OnEmptyTileError != null) { if (!RaiseEmptyTileError) { RaiseEmptyTileError = true; OnEmptyTileError(task.Value.Zoom, task.Value.Pos); } } } } } if (RetryLoadTile > 0) { Debug.WriteLine(ctid + " - ProcessLoadTask: " + task + " -> empty tile, retry " + retry); { Thread.Sleep(1111); } } } }while(++retry < RetryLoadTile); } if (t.HasAnyOverlays && IsStarted) { Matrix.SetTile(t); } else { t.Dispose(); } } #endregion } catch (Exception ex) { Debug.WriteLine(ctid + " - ProcessLoadTask: " + ex.ToString()); } finally { if (Refresh != null) { Refresh.Set(); } } } } #if !PocketPC Monitor.Enter(tileLoadQueue); try { Debug.WriteLine("Quit - " + ct.Name); lock (GThreadPool) { GThreadPool.Remove(ct); } } finally { Monitor.Exit(tileLoadQueue); } #endif }
static void ProcessLoadTask(LoadTask task, string ctid) { try { #region -- execute -- var m = task.Core.Matrix.GetTileWithReadLock(task.Zoom, task.Pos); if (!m.NotEmpty) { Debug.WriteLine(ctid + " - try load: " + task); Tile t = new Tile(task.Zoom, task.Pos); foreach (var tl in task.Core.provider.Overlays) { int retry = 0; do { PureImage img = null; Exception ex = null; if (task.Zoom >= task.Core.provider.MinZoom && (!task.Core.provider.MaxZoom.HasValue || task.Zoom <= task.Core.provider.MaxZoom)) { if (task.Core.skipOverZoom == 0 || task.Zoom <= task.Core.skipOverZoom) { // tile number inversion(BottomLeft -> TopLeft) if (tl.InvertedAxisY) { img = GMaps.Instance.GetImageFrom(tl, new GPoint(task.Pos.X, task.Core.maxOfTiles.Height - task.Pos.Y), task.Zoom, out ex); } else // ok { img = GMaps.Instance.GetImageFrom(tl, task.Pos, task.Zoom, out ex); } } } if (img != null && ex == null) { if (task.Core.okZoom < task.Zoom) { task.Core.okZoom = task.Zoom; task.Core.skipOverZoom = 0; Debug.WriteLine("skipOverZoom disabled, okZoom: " + task.Core.okZoom); } } else if (ex != null) { if ((task.Core.skipOverZoom != task.Core.okZoom) && (task.Zoom > task.Core.okZoom)) { if (ex.Message.Contains("(404) Not Found")) { task.Core.skipOverZoom = task.Core.okZoom; Debug.WriteLine("skipOverZoom enabled: " + task.Core.skipOverZoom); } } } // check for parent tiles if not found if (img == null && task.Core.okZoom > 0 && task.Core.fillEmptyTiles && task.Core.Provider.Projection is MercatorProjection) { int zoomOffset = task.Zoom > task.Core.okZoom ? task.Zoom - task.Core.okZoom : 1; long Ix = 0; GPoint parentTile = GPoint.Empty; while (img == null && zoomOffset < task.Zoom) { Ix = (long)Math.Pow(2, zoomOffset); parentTile = new GMap.NET.GPoint((task.Pos.X / Ix), (task.Pos.Y / Ix)); img = GMaps.Instance.GetImageFrom(tl, parentTile, task.Zoom - zoomOffset++, out ex); } if (img != null) { // offsets in quadrant long Xoff = Math.Abs(task.Pos.X - (parentTile.X * Ix)); long Yoff = Math.Abs(task.Pos.Y - (parentTile.Y * Ix)); img.IsParent = true; img.Ix = Ix; img.Xoff = Xoff; img.Yoff = Yoff; // wpf //var geometry = new RectangleGeometry(new Rect(Core.tileRect.X + 0.6, Core.tileRect.Y + 0.6, Core.tileRect.Width + 0.6, Core.tileRect.Height + 0.6)); //var parentImgRect = new Rect(Core.tileRect.X - Core.tileRect.Width * Xoff + 0.6, Core.tileRect.Y - Core.tileRect.Height * Yoff + 0.6, Core.tileRect.Width * Ix + 0.6, Core.tileRect.Height * Ix + 0.6); // gdi+ //System.Drawing.Rectangle dst = new System.Drawing.Rectangle((int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); //System.Drawing.RectangleF srcRect = new System.Drawing.RectangleF((float)(Xoff * (img.Img.Width / Ix)), (float)(Yoff * (img.Img.Height / Ix)), (img.Img.Width / Ix), (img.Img.Height / Ix)); } } if (img != null) { Debug.WriteLine(ctid + " - tile loaded: " + img.Data.Length / 1024 + "KB, " + task); { t.AddOverlay(img); } break; } else { if (ex != null) { lock (task.Core.FailedLoads) { if (!task.Core.FailedLoads.ContainsKey(task)) { task.Core.FailedLoads.Add(task, ex); if (task.Core.OnEmptyTileError != null) { if (!task.Core.RaiseEmptyTileError) { task.Core.RaiseEmptyTileError = true; task.Core.OnEmptyTileError(task.Zoom, task.Pos); } } } } } if (task.Core.RetryLoadTile > 0) { Debug.WriteLine(ctid + " - ProcessLoadTask: " + task + " -> empty tile, retry " + retry); { Thread.Sleep(1111); } } } } while (++retry < task.Core.RetryLoadTile); } if (t.HasAnyOverlays && task.Core.IsStarted) { task.Core.Matrix.SetTile(t); } else { t.Dispose(); } } #endregion } catch (Exception ex) { Debug.WriteLine(ctid + " - ProcessLoadTask: " + ex.ToString()); } finally { if (task.Core.Refresh != null) { task.Core.Refresh.Set(); } } }
public GMap.NET.GPoint? GetOffsetFromCache(int key) { GMap.NET.GPoint? ret = null; try { using (SQLiteConnection connection = new SQLiteConnection()) { connection.ConnectionString = this.ConnectionString; connection.Open(); using (DbCommand command = connection.CreateCommand()) { command.CommandText = string.Format(sqlSelect, new object[] { key }); using (DbDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) { if (reader.Read()) { ret = new GMap.NET.GPoint(reader.GetInt32(1), reader.GetInt32(0)); } reader.Close(); } } connection.Close(); } } catch (System.Data.SQLite.SQLiteException) { } catch (Exception) { } return ret; }
static void ProcessLoadTask(LoadTask task, string ctid) { try { #region -- execute -- var m = task.Core.Matrix.GetTileWithReadLock(task.Zoom, task.Pos); if (!m.NotEmpty) { Debug.WriteLine(ctid + " - try load: " + task); Tile t = new Tile(task.Zoom, task.Pos); foreach (var tl in task.Core.provider.Overlays) { int retry = 0; do { PureImage img = null; Exception ex = null; if (task.Zoom >= task.Core.provider.MinZoom && (!task.Core.provider.MaxZoom.HasValue || task.Zoom <= task.Core.provider.MaxZoom)) { if (task.Core.skipOverZoom == 0 || task.Zoom <= task.Core.skipOverZoom) { // tile number inversion(BottomLeft -> TopLeft) if (tl.InvertedAxisY) { img = GMaps.Instance.GetImageFrom(tl, new GPoint(task.Pos.X, task.Core.maxOfTiles.Height - task.Pos.Y), task.Zoom, out ex); } else // ok { img = GMaps.Instance.GetImageFrom(tl, task.Pos, task.Zoom, out ex); } } } if (img != null && ex == null) { if (task.Core.okZoom < task.Zoom) { task.Core.okZoom = task.Zoom; task.Core.skipOverZoom = 0; Debug.WriteLine("skipOverZoom disabled, okZoom: " + task.Core.okZoom); } } else if (ex != null) { if ((task.Core.skipOverZoom != task.Core.okZoom) && (task.Zoom > task.Core.okZoom)) { if (ex.Message.Contains("(404) Not Found")) { task.Core.skipOverZoom = task.Core.okZoom; Debug.WriteLine("skipOverZoom enabled: " + task.Core.skipOverZoom); } } } // check for parent tiles if not found if (img == null && task.Core.okZoom > 0 && task.Core.fillEmptyTiles && task.Core.Provider.Projection is MercatorProjection) { int zoomOffset = task.Zoom > task.Core.okZoom ? task.Zoom - task.Core.okZoom : 1; long Ix = 0; GPoint parentTile = GPoint.Empty; while (img == null && zoomOffset < task.Zoom) { Ix = (long)Math.Pow(2, zoomOffset); parentTile = new GMap.NET.GPoint((task.Pos.X / Ix), (task.Pos.Y / Ix)); img = GMaps.Instance.GetImageFrom(tl, parentTile, task.Zoom - zoomOffset++, out ex); } if (img != null) { // offsets in quadrant long Xoff = Math.Abs(task.Pos.X - (parentTile.X * Ix)); long Yoff = Math.Abs(task.Pos.Y - (parentTile.Y * Ix)); img.IsParent = true; img.Ix = Ix; img.Xoff = Xoff; img.Yoff = Yoff; // wpf //var geometry = new RectangleGeometry(new Rect(Core.tileRect.X + 0.6, Core.tileRect.Y + 0.6, Core.tileRect.Width + 0.6, Core.tileRect.Height + 0.6)); //var parentImgRect = new Rect(Core.tileRect.X - Core.tileRect.Width * Xoff + 0.6, Core.tileRect.Y - Core.tileRect.Height * Yoff + 0.6, Core.tileRect.Width * Ix + 0.6, Core.tileRect.Height * Ix + 0.6); // gdi+ //System.Drawing.Rectangle dst = new System.Drawing.Rectangle((int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); //System.Drawing.RectangleF srcRect = new System.Drawing.RectangleF((float)(Xoff * (img.Img.Width / Ix)), (float)(Yoff * (img.Img.Height / Ix)), (img.Img.Width / Ix), (img.Img.Height / Ix)); } } if (img != null) { Debug.WriteLine(ctid + " - tile loaded: " + img.Data.Length / 1024 + "KB, " + task); { t.AddOverlay(img); } break; } else { if (ex != null) { lock (task.Core.FailedLoads) { if (!task.Core.FailedLoads.ContainsKey(task)) { task.Core.FailedLoads.Add(task, ex); if (task.Core.OnEmptyTileError != null) { if (!task.Core.RaiseEmptyTileError) { task.Core.RaiseEmptyTileError = true; task.Core.OnEmptyTileError(task.Zoom, task.Pos); } } } } } if (task.Core.RetryLoadTile > 0) { Debug.WriteLine(ctid + " - ProcessLoadTask: " + task + " -> empty tile, retry " + retry); { Thread.Sleep(1111); } } } }while (++retry < task.Core.RetryLoadTile); } if (t.HasAnyOverlays && task.Core.IsStarted) { task.Core.Matrix.SetTile(t); } else { t.Dispose(); } } #endregion } catch (Exception ex) { Debug.WriteLine(ctid + " - ProcessLoadTask: " + ex.ToString()); } finally { if (task.Core.Refresh != null) { task.Core.Refresh.Set(); } } }
public override GMap.NET.PureImage GetTileImage(GMap.NET.GPoint pos, int zoom) { return(m_provider.GetTileImage(pos, zoom)); }
private Point GetPoint(GpsPointData data, GMapControl map) { GMap.NET.GPoint pt0 = map.FromLatLngToLocal(new GMap.NET.PointLatLng(data.Latitude, data.Longitude)); return(new Point(pt0.X, pt0.Y)); }
// tile consumer thread void ProcessLoadTask() { LoadTask? task = null; long lastTileLoadTimeMs; bool stop = false; #if !PocketPC Thread ct = Thread.CurrentThread; string ctid = "Thread[" + ct.ManagedThreadId + "]"; #else int ctid = 0; #endif while(!stop && IsStarted) { task = null; Monitor.Enter(tileLoadQueue); try { while(tileLoadQueue.Count == 0) { Debug.WriteLine(ctid + " - Wait " + loadWaitCount + " - " + DateTime.Now.TimeOfDay); if(++loadWaitCount >= GThreadPoolSize) { loadWaitCount = 0; #region -- last thread takes action -- { LastTileLoadEnd = DateTime.Now; lastTileLoadTimeMs = (long)(LastTileLoadEnd - LastTileLoadStart).TotalMilliseconds; } #region -- clear stuff-- if(IsStarted) { GMaps.Instance.MemoryCache.RemoveOverload(); tileDrawingListLock.AcquireReaderLock(); try { Matrix.ClearLevelAndPointsNotIn(Zoom, tileDrawingList); } finally { tileDrawingListLock.ReleaseReaderLock(); } } #endregion UpdateGroundResolution(); #if UseGC GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); #endif Debug.WriteLine(ctid + " - OnTileLoadComplete: " + lastTileLoadTimeMs + "ms, MemoryCacheSize: " + GMaps.Instance.MemoryCache.Size + "MB"); if(OnTileLoadComplete != null) { OnTileLoadComplete(lastTileLoadTimeMs); } #endregion } if(!IsStarted || false == Monitor.Wait(tileLoadQueue, WaitForTileLoadThreadTimeout, false) || !IsStarted) { stop = true; break; } } if(IsStarted && !stop || tileLoadQueue.Count > 0) { task = tileLoadQueue.Pop(); } } finally { Monitor.Exit(tileLoadQueue); } if(task.HasValue && IsStarted) { try { #region -- execute -- var m = Matrix.GetTileWithReadLock(task.Value.Zoom, task.Value.Pos); if(!m.NotEmpty) { Debug.WriteLine(ctid + " - try load: " + task); Tile t = new Tile(task.Value.Zoom, task.Value.Pos); foreach(var tl in provider.Overlays) { int retry = 0; do { PureImage img = null; Exception ex = null; if (task.Value.Zoom >= provider.MinZoom && (!provider.MaxZoom.HasValue || task.Value.Zoom <= provider.MaxZoom)) { if(skipOverZoom == 0 || task.Value.Zoom <= skipOverZoom) { // tile number inversion(BottomLeft -> TopLeft) if(tl.InvertedAxisY) { img = GMaps.Instance.GetImageFrom(tl, new GPoint(task.Value.Pos.X, maxOfTiles.Height - task.Value.Pos.Y), task.Value.Zoom, out ex); } else // ok { img = GMaps.Instance.GetImageFrom(tl, task.Value.Pos, task.Value.Zoom, out ex); } } } if(img != null && ex == null) { if(okZoom < task.Value.Zoom) { okZoom = task.Value.Zoom; skipOverZoom = 0; Debug.WriteLine("skipOverZoom disabled, okZoom: " + okZoom); } } else if(ex != null) { if ((skipOverZoom != okZoom) && (task.Value.Zoom > okZoom)) { if(ex.Message.Contains("(404) Not Found")) { skipOverZoom = okZoom; Debug.WriteLine("skipOverZoom enabled: " + skipOverZoom); } } } // check for parent tiles if not found if(img == null && okZoom > 0 && fillEmptyTiles && Provider.Projection is MercatorProjection) { int zoomOffset = task.Value.Zoom > okZoom ? task.Value.Zoom - okZoom : 1; long Ix = 0; GPoint parentTile = GPoint.Empty; while(img == null && zoomOffset < task.Value.Zoom) { Ix = (long)Math.Pow(2, zoomOffset); parentTile = new GMap.NET.GPoint((task.Value.Pos.X / Ix), (task.Value.Pos.Y / Ix)); img = GMaps.Instance.GetImageFrom(tl, parentTile, task.Value.Zoom - zoomOffset++, out ex); } if(img != null) { // offsets in quadrant long Xoff = Math.Abs(task.Value.Pos.X - (parentTile.X * Ix)); long Yoff = Math.Abs(task.Value.Pos.Y - (parentTile.Y * Ix)); img.IsParent = true; img.Ix = Ix; img.Xoff = Xoff; img.Yoff = Yoff; // wpf //var geometry = new RectangleGeometry(new Rect(Core.tileRect.X + 0.6, Core.tileRect.Y + 0.6, Core.tileRect.Width + 0.6, Core.tileRect.Height + 0.6)); //var parentImgRect = new Rect(Core.tileRect.X - Core.tileRect.Width * Xoff + 0.6, Core.tileRect.Y - Core.tileRect.Height * Yoff + 0.6, Core.tileRect.Width * Ix + 0.6, Core.tileRect.Height * Ix + 0.6); // gdi+ //System.Drawing.Rectangle dst = new System.Drawing.Rectangle((int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); //System.Drawing.RectangleF srcRect = new System.Drawing.RectangleF((float)(Xoff * (img.Img.Width / Ix)), (float)(Yoff * (img.Img.Height / Ix)), (img.Img.Width / Ix), (img.Img.Height / Ix)); } } if(img != null) { Debug.WriteLine(ctid + " - tile loaded: " + img.Data.Length / 1024 + "KB, " + task); { t.AddOverlay(img); } break; } else { if(ex != null) { lock(FailedLoads) { if(!FailedLoads.ContainsKey(task.Value)) { FailedLoads.Add(task.Value, ex); if(OnEmptyTileError != null) { if(!RaiseEmptyTileError) { RaiseEmptyTileError = true; OnEmptyTileError(task.Value.Zoom, task.Value.Pos); } } } } } if(RetryLoadTile > 0) { Debug.WriteLine(ctid + " - ProcessLoadTask: " + task + " -> empty tile, retry " + retry); { Thread.Sleep(1111); } } } } while(++retry < RetryLoadTile); } if(t.HasAnyOverlays && IsStarted) { Matrix.SetTile(t); } else { t.Dispose(); } } #endregion } catch(Exception ex) { Debug.WriteLine(ctid + " - ProcessLoadTask: " + ex.ToString()); } finally { if(Refresh != null) { Refresh.Set(); } } } } #if !PocketPC Monitor.Enter(tileLoadQueue); try { Debug.WriteLine("Quit - " + ct.Name); lock(GThreadPool) { GThreadPool.Remove(ct); } } finally { Monitor.Exit(tileLoadQueue); } #endif }
private void BUT_geinjection_Click(object sender, EventArgs e) { GMapControl MainMap = new GMapControl(); MainMap.MapType = GMap.NET.MapType.GoogleSatellite; MainMap.CacheLocation = Path.GetDirectoryName(Application.ExecutablePath) + "/gmapcache/"; FolderBrowserDialog fbd = new FolderBrowserDialog(); try { fbd.SelectedPath = @"C:\Users\hog\Documents\albany 2011\New folder"; } catch { } fbd.ShowDialog(); if (fbd.SelectedPath != "") { string[] files = Directory.GetFiles(fbd.SelectedPath,"*.jpg",SearchOption.AllDirectories); foreach (string file in files) { log.Info(DateTime.Now.Millisecond + " Doing "+ file); Regex reg = new Regex(@"Z([0-9]+)\\([0-9]+)\\([0-9]+)"); Match mat = reg.Match(file); int temp = 1 << int.Parse(mat.Groups[1].Value); GMap.NET.GPoint pnt = new GMap.NET.GPoint(int.Parse(mat.Groups[3].Value), int.Parse(mat.Groups[2].Value)); BUT_geinjection.Text = file; BUT_geinjection.Refresh(); //MainMap.Projection. MemoryStream tile = new MemoryStream(); Image Img = Image.FromFile(file); Img.Save(tile,System.Drawing.Imaging.ImageFormat.Jpeg); tile.Seek(0, SeekOrigin.Begin); log.Info(pnt.X + " " + pnt.Y); Application.DoEvents(); MainMap.Manager.ImageCacheLocal.PutImageToCache(tile, GMap.NET.MapType.Custom, pnt, int.Parse(mat.Groups[1].Value)); Application.DoEvents(); } } }
public GMap.NET.GPoint GetOffset(int key) { GMap.NET.GPoint?offset = null; if (m_localDictionary.ContainsKey(key)) { offset = m_localDictionary[key]; } if (offset == null && this.Cache != null) { var ch = this.Cache.GetOffsetFromCache(key); if (ch.HasValue) { m_localDictionary[key] = ch.Value; offset = ch.Value; } } if (offset == null && this.CacheSecond != null) { var ch = this.CacheSecond.GetOffsetFromCache(key); if (ch.HasValue) { m_localDictionary[key] = ch.Value; offset = ch.Value; } } if (offset == null) { Data.DbHelper db = Feng.Data.DbHelper.CreateDatabase("GoogleMapOffset"); if (db != null) { var dt1 = db.ExecuteDataTable(string.Format("SELECT dlat, dlon FROM KeyOffset WHERE Id = {0}", key)); if (dt1.Rows.Count > 0) { offset = new GMap.NET.GPoint(Convert.ToInt32(dt1.Rows[0][1]), Convert.ToInt32(dt1.Rows[0][0])); if (this.Cache != null) { this.Cache.PutOffsetToCache(key, offset.Value); } if (this.CacheSecond != null) { this.CacheSecond.PutOffsetToCache(key, offset.Value); } m_localDictionary[key] = offset.Value; } } } if (offset == null) { return(GMap.NET.GPoint.Empty); } else { return(offset.Value); } }