Пример #1
0
 public static MapPoint Subtract(MapPoint pt, MapSize sz)
 {
     return(new MapPoint(pt.X - sz.Width, pt.Y - sz.Height));
 }
Пример #2
0
 public void Offset(MapPoint p)
 {
     Offset(p.X, p.Y);
 }
Пример #3
0
 public static MapPoint Add(MapPoint pt, MapSize sz)
 {
     return(new MapPoint(pt.X + sz.Width, pt.Y + sz.Height));
 }
Пример #4
0
        bool PureImageCache.PutImageToCache(MemoryStream tile, MapType type, MapPoint pos, int zoom)
        {
            bool ret = true;

            if (Created)
            {
                try
                {
                    using (SQLiteConnection cn = new SQLiteConnection())
                    {
                        cn.ConnectionString = ConnectionString;
                        cn.Open();
                        {
                            using (DbTransaction tr = cn.BeginTransaction())
                            {
                                try
                                {
                                    using (DbCommand cmd = cn.CreateCommand())
                                    {
                                        cmd.Transaction = tr;
                                        cmd.CommandText = "INSERT INTO Tiles(X, Y, Zoom, Type, CacheTime) VALUES(@p1, @p2, @p3, @p4, @p5)";

                                        cmd.Parameters.Add(new SQLiteParameter("@p1", pos.X));
                                        cmd.Parameters.Add(new SQLiteParameter("@p2", pos.Y));
                                        cmd.Parameters.Add(new SQLiteParameter("@p3", zoom));
                                        cmd.Parameters.Add(new SQLiteParameter("@p4", (int)type));
                                        cmd.Parameters.Add(new SQLiteParameter("@p5", DateTime.Now));

                                        cmd.ExecuteNonQuery();
                                    }

                                    using (DbCommand cmd = cn.CreateCommand())
                                    {
                                        cmd.Transaction = tr;

                                        cmd.CommandText = "INSERT INTO TilesData(id, Tile) VALUES((SELECT last_insert_rowid()), @p1)";
                                        cmd.Parameters.Add(new SQLiteParameter("@p1", tile.GetBuffer()));

                                        cmd.ExecuteNonQuery();
                                    }
                                    tr.Commit();
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine("PutImageToCache: " + ex.ToString());

                                    tr.Rollback();
                                    ret = false;
                                }
                            }
                        }
                        cn.Close();
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("PutImageToCache: " + ex.ToString());
                    ret = false;
                }
            }
            return(ret);
        }
 /// <summary>
 /// gets pixel coordinate from tile coordinate
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public virtual MapPoint FromTileXYToPixel(MapPoint p)
 {
     return(new MapPoint((p.X * TileSize.Width), (p.Y * TileSize.Height)));
 }
 /// <summary>
 /// gets tile coorddinate from pixel coordinates
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public virtual MapPoint FromPixelToTileXY(MapPoint p)
 {
     return(new MapPoint((int)(p.X / TileSize.Width), (int)(p.Y / TileSize.Height)));
 }
Пример #7
0
        void UpdateBounds()
        {
            if (MapType == MapType.None)
            {
                return;
            }

            lock (tileLoadQueue)
            {
                tileDrawingListLock.AcquireWriterLock();
                try
                {
                    tileDrawingList.Clear();

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

                            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 (MapsManager.Instance.ShuffleTilesOnLoad)
                    {
                        Stuff.Shuffle <MapPoint>(tileDrawingList);
                    }

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

                //EnsureLoaderThreads();


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

                loadWaitCount = 0;

                Monitor.PulseAll(tileLoadQueue);
            }

            if (OnTileLoadStart != null)
            {
                OnTileLoadStart();
            }
        }
Пример #8
0
 public void BeginDrag(MapPoint pt)
 {
     dragPoint.X = pt.X - renderOffset.X;
     dragPoint.Y = pt.Y - renderOffset.Y;
     IsDragging  = true;
 }