Exemple #1
0
        /// <summary>
        /// 屏幕坐标转经纬度
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public PointLatLng PointToLatLng(PointInt p)
        {
            PointLatLng pll  = null;
            var         pPix = MapCenterPix.GetOffSet(p.X - ScreenArea.Width / 2, p.Y - ScreenArea.Height / 2);

            pll = MercatorHelper.PixelToLatLng(pPix, Zoom);
            return(pll);
        }
Exemple #2
0
        /// <summary>
        /// 地图中心偏移
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public void CenterMove(double x, double y, bool isUpdateTiles = true)
        {
            var centerPix = MapCenterPix;

            centerPix            = MapCenterPix.GetOffSet(x, y);
            _mapCenter           = MercatorHelper.PixelToLatLng(centerPix, Zoom);
            _isNeedToUpdateTiles = true;
            //Debug.WriteLine(string.Format("****缩放:鼠标点:【{0}】,中心坐标点:【{1}】,中心像素点:【{2}】,鼠标像素点【{3}】,鼠标经纬度【{8}】,层级:【{4}】,屏幕中心点:【{5}】\r\n像素偏移{6},屏幕坐标点偏移{7}"));

            if (RectTilesBitmap != null && RectTilesBitmap.Contains(TilesArea) && RotationAngle == 0)
            {
                RectTilesBitmap.OffSet(-(int)x, -(int)y);
            }
            else
            {
                if (isUpdateTiles)
                {
                    UpdateDrawTiles();
                }
            }

            //TileDrawOffset.Offset(-(int)x, -(int)y);
        }
Exemple #3
0
        public void UpdateDrawTiles()
        {
            IsTilesUpdating = true;
            TilesUpdateLock.AcquireWriterLock(1000);
            try
            {
                if (ScreenArea != null)
                {
                    var width  = TilesArea.Width;
                    var height = TilesArea.Height;



                    var pointLeftTopPix = TileCenterPix.GetOffSet(-width / 2, -height / 2); //左上角像素坐标
                    var tileXYLeftTop   = MercatorHelper.PixelToTileXY(pointLeftTopPix);    //左上角的瓦片索引
                    var tilePixLeftTop  = MercatorHelper.TileXYToPixel(tileXYLeftTop);      //左上角瓦片像素坐标
                    //var tileDrawPositionLeftTop = new PointInt((int)(tilePixLeftTop.X - pointLeftTopPix.X + 0.5), (int)(tilePixLeftTop.Y - pointLeftTopPix.Y + 0.5));//屏幕坐标系下左上角瓦片的屏幕坐标
                    var tileDrawPositionLeftTop = TilesArea.LeftTop.GetOffSet((int)(tilePixLeftTop.X - pointLeftTopPix.X), (int)(tilePixLeftTop.Y - pointLeftTopPix.Y));

                    var tileXYCenter = MercatorHelper.PixelToTileXY(TileCenterPix);//中心瓦片索引
                    //var tilePixCenter = MercatorHelper.TileXYToPixel(tileXYCenter);//中心瓦片左上角所在像素坐标

                    var xCount = (int)Math.Ceiling((double)width / TileSize.Width) + 1;   //X方向的瓦片数量
                    var yCount = (int)Math.Ceiling((double)height / TileSize.Height) + 1; //Y方向的瓦片数量

                    RectTilesBitmap         = new RectInt(tileDrawPositionLeftTop, xCount * TileSize.Width, yCount * TileSize.Height);
                    tileDrawPositionLeftTop = new PointInt(0, 0);
                    GridInfo = new DrawGrid
                    {
                        GridSize    = TileSize,
                        LeftTop     = RectTilesBitmap.LeftTop,
                        RightBottom = RectTilesBitmap.RightBottom,
                        XCount      = xCount,
                        YCount      = yCount,
                    };

                    //计算要显示的绘图瓦片
                    if (DicDrawTile == null)
                    {
                        DicDrawTile = new Dictionary <Tile, DrawTile>();
                    }
                    DicDrawTile.Clear();

                    var             minTileIndex  = MapHelper.GetTileMatrixMinXY(Zoom);
                    var             maxTileIndex  = MapHelper.GetTileMatrixMaxXY(Zoom);
                    List <Tile>     lstWantToLoad = new List <Tile>();
                    List <DrawTile> lstDrawTile   = new List <DrawTile>();
                    //DateTime rt = DateTime.Now;
                    for (int x = 0; x < xCount; x++)
                    {
                        for (int y = 0; y < yCount; y++)
                        {
                            var drawPostiton = tileDrawPositionLeftTop.GetOffSet(x * TileSize.Width, y * TileSize.Height);
                            //Tile t = new Tile(tileXYLeftTop.X + x, tileXYLeftTop.Y + y, Zoom);
                            Tile t = TileManager.Singleton.GetTile(Zoom, new PointInt64(tileXYLeftTop.X + x, tileXYLeftTop.Y + y));
                            if (t == null)
                            {
                                t = new Tile(tileXYLeftTop.X + x, tileXYLeftTop.Y + y, Zoom);
                            }
                            if (t.TileIndex.X >= minTileIndex.Width && t.TileIndex.Y >= minTileIndex.Height &&
                                t.TileIndex.X <= maxTileIndex.Width && t.TileIndex.Y <= maxTileIndex.Height)   //范围判断
                            {
                                var rt = new DrawTile()
                                {
                                    DrawPosition = drawPostiton,
                                    Tile         = t
                                };
                                lstDrawTile.Add(rt);
                                ////if (RotationAngle == 0 || MapHelper.CheckTileCrossRect(new RectInt(dt.DrawPosition.GetOffSet(TilesArea.LeftTop.X, TilesArea.LeftTop.Y), TileSize.Width, TileSize.Height), ScreenArea, RotationAngle))
                                //{
                                //    //DicDrawTile.Add(t, rt);
                                //    lstDrawTile.Add(rt);
                                //    //if (t.TileImg == null)
                                //    //{
                                //    //    lstWantToLoad.Add(t);

                                //    //}
                                //}
                            }
                        }
                    }
                    lstDrawTile = lstDrawTile.OrderBy(d => Math.Abs(d.Tile.TileIndex.X - tileXYCenter.X) + Math.Abs(d.Tile.TileIndex.Y - tileXYCenter.Y)).ToList();
                    foreach (var item in lstDrawTile)
                    {
                        if (item.Tile.State == TileState.New)
                        {
                            TileManager.Singleton.AddTile(item.Tile);
                        }
                        if (item.Tile.TileImg == null)
                        {
                            lstWantToLoad.Add(item.Tile);
                        }
                        item.Tile.ReadTime = DateTime.Now;
                        DicDrawTile.Add(item.Tile, item);
                    }



                    lstWantToLoad.ForEach(a => { TileManager.Singleton.LoadTile(a); });

                    //_lastTilesRect = tilesRect;
                    //TileDrawOffset = new PointInt(0,0);

                    if (TilesUpdateComplete != null)
                    {
                        TilesUpdateComplete(DicDrawTile);
                    }
                }
            }
            finally
            {
                IsTilesUpdating = false;
                TilesUpdateLock.ReleaseWriterLock();
            }
        }
Exemple #4
0
        /// <summary>
        /// 获取层级变更后的地图中心点
        /// </summary>
        /// <param name="mp">鼠标缩放所在屏幕坐标</param>
        /// <param name="mpLatLng">鼠标缩放前所在经纬度坐标</param>
        //private void GetCenterOfterZoom(PointInt mp,PointLatLng mpLatLng)
        //{
        //    var centerOffSet = new SizeDouble((double)(mp.X - ScreenArea.Center.X), (double)(mp.Y - ScreenArea.Center.Y));

        //    var mpPix = MercatorHelper.LatLngToPixel(mpLatLng, _zoom);
        //    var cPix = mpPix.GetOffSet(-centerOffSet.Width, -centerOffSet.Height);
        //    _mapCenter = MercatorHelper.PixelToLatLng(cPix, _zoom);
        //    //Debug.WriteLine(string.Format("****缩放:鼠标点:【{0}】,中心坐标点:【{1}】,中心像素点:【{2}】,鼠标像素点【{3}】,鼠标经纬度【{8}】,层级:【{4}】,屏幕中心点:【{5}】\r\n像素偏移{6},屏幕坐标点偏移{7}"
        //    //    , mp, MapCenter, MapCenterPix, mpPix,Zoom,ScreenArea.Center,mpPix.GetOffSet(-MapCenterPix.X,-MapCenterPix.Y),centerOffSet, mpLatLng));
        //    UpdateDrawTiles();
        //}


        /// <summary>
        /// 经纬度转屏幕坐标
        /// </summary>
        /// <param name="latlng"></param>
        /// <returns></returns>
        public PointInt LatLngToPoint(PointLatLng latlng)
        {
            var pPix = MercatorHelper.LatLngToPixel(latlng, Zoom).GetOffSet(-MapCenterPix.X, -MapCenterPix.Y).GetOffSet(ScreenArea.Width / 2, ScreenArea.Height / 2);

            return(new PointInt((int)pPix.X, (int)pPix.Y));
        }