Ejemplo n.º 1
0
        /// <summary>
        /// 坐标转经纬度
        /// </summary>
        /// <param name="worldPos"></param>
        /// <returns></returns>
        public static Vector2D Position2LngLat(Vector3 worldPos)
        {
            Vector2D vector2D = new Vector2D(worldPos.x * 256, worldPos.y * 256);


            return(MCTransform.ConvertMC2LL(vector2D));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 经纬度转坐标(x,y)
        /// 256个MC单位对应1个Unit单位
        /// </summary>
        /// <param name="lngLat"></param>
        /// <returns></returns>
        public static Vector3 LngLat2Position(Vector2D lngLat)
        {
            //转换MC坐标
            Vector2D vector2D = MCTransform.ConvertLL2MC(lngLat);

            //缩小到Unit单位范围内(-100000, 100000)
            return(new Vector2((float)(vector2D.x / 256), (float)(vector2D.y / 256)));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 将tile(瓦片)坐标系转换为LngLat(地理)坐标系
        /// 18级地图 瓦片图上1个像素等于1个MC单位
        /// </summary>
        /// <param name="tile">瓦片坐标</param>
        /// <param name="pixel">瓦片上的像素坐标</param>
        /// <param name="zoom">缩放比例</param>
        /// <returns></returns>
        public static Vector2D Tile2LngLat(TileData tileData)
        {
            Vector2D vector2D = new Vector2D();

            vector2D.x = tileData.tile.x * 256.0 + tileData.pixel.x;
            vector2D.y = tileData.tile.y * 256.0 + tileData.pixel.y;
            vector2D  /= Math.Pow(2, tileData.zoom - 18);
            return(MCTransform.ConvertMC2LL(vector2D));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 将LngLat地理坐标系转换为tile瓦片坐标系
        /// </summary>
        /// <param name="lngLat">经纬度信息</param>
        /// <param name="zoom">缩放比例</param>
        /// <param name="pixelOffset">像素偏移</param>
        /// <returns></returns>
        public static TileData LngLat2Tile(Vector2D lngLat, int zoom, Vector2 pixelOffset)
        {
            TileData tileData = new TileData(zoom);
            //转换MC坐标
            Vector2D vector2D = MCTransform.ConvertLL2MC(lngLat);

            //转换到缩放级别
            vector2D *= Math.Pow(2, zoom - 18);
            //偏移像素
            vector2D        += pixelOffset;
            tileData.tile.x  = (int)(vector2D.x / 256.0);
            tileData.tile.y  = (int)(vector2D.y / 256.0);
            tileData.pixel.x = ((int)vector2D.x % 256);
            tileData.pixel.y = ((int)vector2D.y % 256);
            return(tileData);
        }