Commit 0093e63c authored by 田翔's avatar 田翔

fix: 设备选择器支持同步地址

parent 4fdea49e
{
"name": "panda-xform",
"version": "6.10.22",
"description": "6.10.22 描述控件支持分组内",
"version": "6.10.23",
"description": "6.10.23 设备选择器支持同步地址",
"keywords": [
"panda-xform"
],
......
......@@ -3608,6 +3608,12 @@ const mapWidgets = [
widget: 'DeviceFieldshine',
default: [],
},
addressSync: {
title: '地址同步',
type: 'string',
widget: 'AddressSync',
description: '位置信息将会同步到下方字段中',
},
screenShot: {
title: '是否显示缩略图',
type: 'boolean',
......
......@@ -9,7 +9,8 @@ import {
Graphic
} from '@wisdom-map/arcgismap'
import point from './img/point.png'
import { isObject } from '../../../../utils'
import { isJson, isObject, mercatorToLngLat, lngmkt } from '../../../../utils'
import { getLocation, getLocationV5, GetAreaNameByCoordinate, placeAroundRelay } from '../../../../apis/process'
import Drag from '../../../components/Drag'
import styles from './index.less'
......@@ -30,6 +31,7 @@ const Device = (props) => {
layerName,
screenShot,
fieldshine,
addressSync,
} = schema
const [visible, setVisible] = useState(false)
const [text, setText] = useState(presetValue ? presetValue : '(空)')
......@@ -211,6 +213,103 @@ const Device = (props) => {
}
}
/**火星转84*/
const gcj02_To_gps84 = (lng, lat) => {
const pi = 3.1415926535897932384626;
const a = 6378245.0;
const ee = 0.00669342162296594323;
const x_pi = (pi * 3000.0) / 180.0;
const R = 6378137;
const transformLat = (x, y) => {
var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
ret += ((20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0) / 3.0;
ret += ((20.0 * Math.sin(y * pi) + 40.0 * Math.sin((y / 3.0) * pi)) * 2.0) / 3.0;
ret += ((160.0 * Math.sin((y / 12.0) * pi) + 320 * Math.sin((y * pi) / 30.0)) * 2.0) / 3.0;
return ret;
};
const transformLng = (x, y) => {
var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
ret += ((20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0) / 3.0;
ret += ((20.0 * Math.sin(x * pi) + 40.0 * Math.sin((x / 3.0) * pi)) * 2.0) / 3.0;
ret += ((150.0 * Math.sin((x / 12.0) * pi) + 300.0 * Math.sin((x / 30.0) * pi)) * 2.0) / 3.0;
return ret;
};
const transform = (lng, lat) => {
var dLat = transformLat(lng - 105.0, lat - 35.0);
var dLng = transformLng(lng - 105.0, lat - 35.0);
var radLat = (lat / 180.0) * pi;
var magic = Math.sin(radLat);
magic = 1 - ee * magic * magic;
var sqrtMagic = Math.sqrt(magic);
dLat = (dLat * 180.0) / (((a * (1 - ee)) / (magic * sqrtMagic)) * pi);
dLng = (dLng * 180.0) / ((a / sqrtMagic) * Math.cos(radLat) * pi);
var mgLat = lat + dLat;
var mgLng = lng + dLng;
var newCoord = {
lng: mgLng,
lat: mgLat,
};
return newCoord;
};
var coord = transform(lng, lat);
var lontitude = lng * 2 - coord.lng;
var latitude = lat * 2 - coord.lat;
var newCoord = {
lng: lontitude,
lat: latitude,
};
return newCoord;
};
const getTargetPath = (value) => {
let paths = Object.keys(addons.formData)
let targetPath = null
if (Array.isArray(paths)) {
paths.forEach(v => {
let values = addons.getValue(v)
if (isObject(values)) {
for (let key in values) {
if (key === value) {
targetPath = `${v}.${key}`
}
}
}
})
}
return targetPath
}
const addressSyncFun = async () => {
console.log(addressSync && geometrystr,)
if (addressSync && geometrystr) {
let targetPath = getTargetPath(addressSync)
if (targetPath) {
let x = geometrystr?.split(',')[0]
let y = geometrystr?.split(',')[1]
let LngLat = mercatorToLngLat(x, y)
let newCoord = gcj02_To_gps84(LngLat[0], LngLat[1])
let postStr = {
lon: newCoord.lng,
lat: newCoord.lat,
ver: 1,
}
let url = `http://api.tianditu.gov.cn/geocoder?postStr=${JSON.stringify(postStr)}&type=geocode&tk=a1d480f55b805db96e1ed295e62c72b1`
const { code, data } = await placeAroundRelay(url)
if (code === '0' && isJson(data)) {
let res = JSON.parse(data) || {}
let text = res?.result?.addressComponent?.poi || res?.result?.formatted_address || ''
const schema = addons.getSchemaByPath(targetPath);
if (['TextInput', 'fileUpload'].includes(schema.widget)) {
addons.setSchemaByPath(targetPath, { ...schema, otherValue: text });
} else {
console.log('targetPath', targetPath, text)
addons.setValue(targetPath, text || '');
}
}
}
}
}
const onOk = () => {
onChange(geometrystr)
let { paths } = addons.getSchemaByPath('#')
......@@ -253,6 +352,7 @@ const Device = (props) => {
}
})
}
addressSyncFun()
isSendQueryRef.current = false
setVisible(false)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment