|
@@ -1,129 +0,0 @@
|
|
|
-import { Pos } from '../types'
|
|
|
-import proj4 from 'proj4'
|
|
|
-
|
|
|
-export type Conversion = {
|
|
|
- scale: number
|
|
|
- rotation: number
|
|
|
- translate: Pos
|
|
|
-}
|
|
|
-
|
|
|
-enum Coordinate {
|
|
|
- AMap = `EPSG:4490`,
|
|
|
- WebMercator = `EPSG:4547`,
|
|
|
-}
|
|
|
-
|
|
|
-const definitions = {
|
|
|
- [Coordinate.AMap]: `+proj=longlat +ellps=GRS80 +no_defs`,
|
|
|
- [Coordinate.WebMercator]: `+proj=tmerc +lat_0=0 +lon_0=114 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs`,
|
|
|
-} as const
|
|
|
-
|
|
|
-for (const coord in definitions) {
|
|
|
- proj4.defs(coord, definitions[coord])
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * 通过两个映射点计算出矩阵
|
|
|
- */
|
|
|
-export const calcTransformByPoints = () => {
|
|
|
- // 数据集初始化校准
|
|
|
- // var fakePositions = [ {
|
|
|
- // x: -1.208132028579712,
|
|
|
- // y: 0.04820600152015686,
|
|
|
- // z: -2.257599115371704,
|
|
|
- // },
|
|
|
- // {
|
|
|
- // x: 1.6327489614486694,
|
|
|
- // y: 0.056550998240709305,
|
|
|
- // z: -2.1368539333343506,
|
|
|
- // },{
|
|
|
- // x: 0.05691400170326233,
|
|
|
- // y: 0.04810800030827522,
|
|
|
- // z: 0.97919100522995,
|
|
|
- // },{
|
|
|
- // x: -0.5570799708366394,
|
|
|
- // y: 0.04639599844813347,
|
|
|
- // z: 3.0515389442443848 ,
|
|
|
- // }
|
|
|
- // ]
|
|
|
- // var realPositions = [
|
|
|
- // { x: 458249.577950831, y: 2474529.667443291 },
|
|
|
- // { x: 458247.51758545433, y: 2474531.6324389814 },
|
|
|
- // {x: 458250.7569026919, y: 2474532.9341176464 },
|
|
|
- // {x: 458252.6196984933, y: 2474534.0980041157 }
|
|
|
- // ]//正确点位的点位
|
|
|
- // fakePositions = fakePositions.map(e=>{
|
|
|
- // return new THREE.Vector3(e.x, -e.z, 0);
|
|
|
- // })
|
|
|
- // realPositions = realPositions.map(e=>{
|
|
|
- // return new THREE.Vector3(e.x, e.y, 0);
|
|
|
- // })
|
|
|
- // var moveVec = new THREE.Vector3().subVectors(realPositions[0], fakePositions[0]) //平移向量
|
|
|
- // var vec1 = new THREE.Vector3().subVectors(fakePositions[0], fakePositions[1]) //旧的向量
|
|
|
- // var vec2 = new THREE.Vector3().subVectors(realPositions[0], realPositions[1])//新的向量
|
|
|
- // var angle = vec1.angleTo(vec2)
|
|
|
- // if(vec1.clone().cross(vec2).z < 0)angle *= -1 //这里不确定是<0还是>0
|
|
|
- // var matrix = new THREE.Matrix4().setPosition(moveVec.clone().sub(realPositions[0]))
|
|
|
- // var rotateMatrix = new THREE.Matrix4().makeRotationAxis(new THREE.Vector3(0,0,1), angle );
|
|
|
- // matrix.premultiply(rotateMatrix)
|
|
|
- // var moveBackMatrix = new THREE.Matrix4().setPosition(realPositions[0])
|
|
|
- // matrix.premultiply(moveBackMatrix)
|
|
|
- // var pos = fakePositions.map(e=>{
|
|
|
- // return e.clone().applyMatrix4(matrix)
|
|
|
- // })
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * 通过矩阵信息推导转化后的点信息
|
|
|
- */
|
|
|
-export const transformPoint = (point: Pos, cover: Conversion) => {
|
|
|
- const ctrla = cover.scale * Math.cos(cover.rotation)
|
|
|
- const ctrlb = cover.scale * Math.sign(cover.rotation)
|
|
|
-
|
|
|
- return {
|
|
|
- x: ctrla * point.x - ctrlb * point.y + cover.translate.x,
|
|
|
- y: ctrlb * point.x + ctrla * point.y + cover.translate.y,
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * 转换完成的点通过举证信息推到转换前的点
|
|
|
- */
|
|
|
-export const recoverTransformPoint = (after: Pos, cover: Conversion) => {
|
|
|
- const ctrla = cover.scale * Math.cos(cover.rotation)
|
|
|
- const ctrlb = cover.scale * Math.sign(cover.rotation)
|
|
|
- const y = (ctrla * (after.y - cover.translate.y) - ctrlb * (after.x - cover.translate.x)) / (Math.pow(ctrlb, 2) + Math.pow(ctrla, 2))
|
|
|
- const x = (after.y - ctrla * y - cover.translate.y) / ctrlb
|
|
|
-
|
|
|
- return { x, y }
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * 本地坐标转墨卡托投影
|
|
|
- */
|
|
|
-export const locationToMercator = transformPoint
|
|
|
-
|
|
|
-/**
|
|
|
- * 墨卡托投影转本地坐标
|
|
|
- */
|
|
|
-export const mercatorToLocation = recoverTransformPoint
|
|
|
-
|
|
|
-/**
|
|
|
- * 墨卡托投影转高德坐标
|
|
|
- */
|
|
|
-export const mercatorToAmap = (point: Pos) => proj4(Coordinate.WebMercator, Coordinate.AMap, point)
|
|
|
-
|
|
|
-/**
|
|
|
- * 高德坐标转墨卡托投影
|
|
|
- */
|
|
|
-export const amapToMercator = (point: Pos) => proj4(Coordinate.AMap, Coordinate.WebMercator, point)
|
|
|
-
|
|
|
-/**
|
|
|
- * 本地坐标转高德坐标
|
|
|
- */
|
|
|
-export const locationToAMap = (point: Pos, cover: Conversion) => mercatorToAmap(locationToMercator(point, cover))
|
|
|
-
|
|
|
-/**
|
|
|
- * 高德坐标转本地坐标
|
|
|
- */
|
|
|
-export const amapToLocation = (point: Pos, cover: Conversion) => mercatorToLocation(amapToMercator(point), cover)
|
|
|
-const merPos = amapToMercator({ x: 113.59582840373051, y: 22.3666282638448 })
|