Exemplo n.º 1
0
        /// <summary>
        /// 移动地图
        /// </summary>
        /// <param name="offset">屏幕像素单位</param>
        public void MoveMap(Vector2 offset)
        {
            //相机位置
            Vector3 vector      = new Vector3(offset.x, 0, offset.y);
            Vector3 worldOffset = transform.TransformPoint(vector * MapFunction.GetCameraMoveScale(mMapZoomLevel));

            mMapCamera.transform.position -= worldOffset;
            //判断移动是否超出范围
            Vector3 nextCameraPos    = mMapCamera.transform.position;
            Vector3 leftDownWorldPos = ScreenToWorldPoint(new Vector3(0, 0));
            Vector3 rightUpWorldPos  = ScreenToWorldPoint(new Vector3(Screen.width, Screen.height));

            if (leftDownWorldPos.x < mWorldPosRange.x)
            {
                nextCameraPos.x += mWorldPosRange.x - leftDownWorldPos.x;
            }
            else if (mWorldPosRange.width < rightUpWorldPos.x)
            {
                nextCameraPos.x += mWorldPosRange.width - rightUpWorldPos.x;
            }
            if (leftDownWorldPos.z < mWorldPosRange.y)
            {
                nextCameraPos.z += mWorldPosRange.y - leftDownWorldPos.z;
            }
            else if (mWorldPosRange.height < rightUpWorldPos.z)
            {
                nextCameraPos.z += mWorldPosRange.height - rightUpWorldPos.z;
            }
            mMapCamera.transform.position = nextCameraPos;
            //计算中心经纬度
            mCenterLngLat = WorldPos2LngLat(mMapCamera.transform.position);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 当前地图的缩放比例
 /// </summary>
 /// <returns></returns>
 public float GetMapScale()
 {
     return(MapFunction.GetCameraMoveScale(mMapZoomLevel));
 }