Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
micro-customization-system
/
oEshield
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 8cf43f19
authored
Feb 14, 2025
by
wangzhihui
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修复轨迹导出问题
1 parent
c2f62a00
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
121 additions
and
56 deletions
src/utils/mapBgeo.js
src/utils/mapBgeo.js
View file @
8cf43f1
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* @Author: 'wangzhihui' '1733904062@qq.com'
* @Author: 'wangzhihui' '1733904062@qq.com'
* @Date: 2024-11-28 16:37:15
* @Date: 2024-11-28 16:37:15
* @LastEditors: 'wangzhihui' '1733904062@qq.com'
* @LastEditors: 'wangzhihui' '1733904062@qq.com'
* @LastEditTime: 2025-0
1-16 11:15:49
* @LastEditTime: 2025-0
2-13 17:17:12
* @FilePath: \oEshield\src\utils\mapgeo.js
* @FilePath: \oEshield\src\utils\mapgeo.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
*/
...
@@ -33,27 +33,17 @@ const MAPGEO = {
...
@@ -33,27 +33,17 @@ const MAPGEO = {
},
},
transfer
(
obj
,
cb
)
{
transfer
(
obj
,
cb
)
{
const
data
=
obj
.
data
;
const
data
=
obj
.
data
;
obj
.
len
=
data
.
length
;
obj
.
times
=
obj
.
len
>
20
?
Math
.
ceil
(
obj
.
len
/
20
)
:
1
;
obj
.
totalNum
=
0
;
obj
.
totalNum
=
0
;
obj
.
realNum
=
0
;
//为了剔除脏数据,脏数据导致解析不回调
obj
.
realNum
=
0
;
//为了剔除脏数据,脏数据导致解析不回调
for
(
let
i
=
0
;
i
<
obj
.
times
;
i
++
)
{
let
lnglatArr
=
[];
let
initIdx
=
i
*
20
;
let
maxIdx
=
i
===
obj
.
times
-
1
?
obj
.
len
:
(
i
+
1
)
*
20
;
for
(
let
idx
=
initIdx
;
idx
<
maxIdx
;
idx
++
)
{
// 防止出现gps点:.00000的错误
if
(
Number
(
data
[
idx
].
blng
)
>
0
&&
Number
(
data
[
idx
].
blat
)
>
0
)
{
lnglatArr
.
push
([
data
[
idx
].
blng
,
data
[
idx
].
blat
])
obj
.
realNum
++
;
}
}
(
function
(
initIdx
)
{
geocoderGetAdr
(
lnglatArr
,
initIdx
)
})(
initIdx
)
}
data
.
forEach
(
item
=>
{
if
(
Number
(
item
.
blng
)
>
0
&&
Number
(
item
.
blat
)
>
0
)
{
obj
.
realNum
++
;
}
})
// console.log(data,'data')
Promise
.
race
([
geocoderGetAdr
(
data
),
limitload
()])
geocoderGetAdr
(
data
)
function
fixed6
(
num
)
{
function
fixed6
(
num
)
{
return
Number
(
num
).
toFixed
(
6
);
return
Number
(
num
).
toFixed
(
6
);
}
}
...
@@ -69,46 +59,121 @@ const MAPGEO = {
...
@@ -69,46 +59,121 @@ const MAPGEO = {
k
.
transferAddress
=
province
+
city
+
district
+
town
+
street
+
poi_desc
k
.
transferAddress
=
province
+
city
+
district
+
town
+
street
+
poi_desc
})
})
}
}
function
geocoderGetAdr
(
arr
,
initIdx
)
{
function
geocoderGetAdr
(
arr
,
initIdx
)
{
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
if
(
!
arr
||
arr
.
length
<=
0
)
{
return
false
;
}
for
(
const
item
of
arr
){
try
{
const
o
=
await
AMap
.
invoke
(
'Point'
,
item
.
blng
,
item
.
blat
);
await
new
Promise
(
resolve
=>
setTimeout
(
resolve
,
10
))
MAPGEO
.
geocoder
.
getLocation
(
o
,(
res
)
=>
{
setAddress
(
o
,
res
);
obj
.
totalNum
++
;
// console.log(obj.totalNum , obj.realNum,obj.totalNum === obj.realNum)
if
(
obj
.
totalNum
===
obj
.
realNum
&&
typeof
cb
===
'function'
)
{
cb
(
data
);
resolve
()
}
});
}
catch
(
error
)
{
console
.
error
(
`Error processing item
${
item
}
:`
,
error
);
}
}
})
if
(
!
arr
||
arr
.
length
<=
0
)
{
return
false
;
}
const
timeoutId
=
window
.
setTimeout
(()
=>
{
arr
.
forEach
(
item
=>
{
let
o
=
AMap
.
invoke
(
'Point'
,...
item
)
MAPGEO
.
geocoder
.
getLocation
(
o
,
function
(
res
){
setAddress
(
o
,
res
);
obj
.
totalNum
++
;
if
(
obj
.
totalNum
===
obj
.
realNum
)
{
cb
&&
cb
(
data
)
}
})
})
// MAPGEO.geocoder.getAddress(arr, function (status, result) {
// if (status === 'complete' && result.info === 'OK') {//获取地址成功
// result.regeocodes.forEach((item, idx) => {
// let o = arr[idx]
// setAddress(o, item);
// obj.totalNum++;
// });
// if (obj.totalNum === obj.realNum) {
// cb && cb(data)
// }
// } else {
// // geocoderGetAdr(arr, initIdx)
// }
// });
});
if
(
!
obj
.
timeoutIds
)
{
}
obj
.
timeoutIds
=
[]
function
limitload
(){
let
time
=
(
data
.
length
/
58
)
*
1000
;
new
Promise
(
resolve
=>
setTimeout
(()
=>
{
if
(
typeof
cb
===
'function'
)
{
cb
(
data
);
resolve
()
}
}
obj
.
timeoutIds
.
push
(
timeoutId
)
},
time
))
}
}
}
}
// transfer(obj, cb) {
// const data = obj.data;
// obj.count=0;
// obj.len = data.length;
// obj.times = obj.len > 20 ? Math.ceil(obj.len / 20) : 1;
// obj.totalNum = 0;
// obj.realNum = 0; //为了剔除脏数据,脏数据导致解析不回调
// for (let i = 0; i < obj.times; i++) {
// let lnglatArr = [];
// let initIdx = i * 20;
// let maxIdx = i === obj.times - 1 ? obj.len : (i + 1) * 20;
// for (let idx = 0; idx < obj.len; idx++) {
// // 防止出现gps点:.00000的错误
// if (Number(data[idx].blng) > 0 && Number(data[idx].blat) > 0) {
// lnglatArr.push([data[idx].blng, data[idx].blat])
// obj.realNum++;
// }
// }
// (function (initIdx) {
// geocoderGetAdr(lnglatArr, initIdx)
// // })(initIdx)
// }
// function fixed6(num) {
// return Number(num).toFixed(6);
// }
// // 循环设置地址,修复数组中相同经纬度只设置第一个的bug jack 20230720
// function setAddress(row, item) {
// const {content: {poi_desc, address_detail: {province, city, district, town, street}}} = item
// const _list = data.filter(
// (k) =>
// fixed6(k.blng) == fixed6(row.lng) && fixed6(k.blat) == fixed6(row.lat)
// )
// _list.map((k) => {
// k.transferAddress = province + city + district + town + street + poi_desc
// })
// }
// async function geocoderGetAdr(arr, initIdx) {
// obj.count+=arr.length
// if (!arr || arr.length <= 0) {
// return false;
// }
// // for(const item of arr){
// let i=0;
// for(;i < arr.length; i++){
// let item=arr[i]
// try {
// const o = await AMap.invoke('Point', ...item);
// const res = await new Promise((resolve)=>{
// MAPGEO.geocoder.getLocation(o,(res)=>{
// console.log('getLocation',res,i)
// if (!res) {
// throw new Error('Invalid result from getLocation');
// }
// resolve(res)
// });
// })
// // console.log(o, res,i)
// // setAddress(o, res);
// obj.totalNum++;
// console.log(obj.totalNum , obj.realNum,obj.totalNum === obj.realNum,obj.count)
// if (obj.totalNum === obj.realNum && typeof cb === 'function') {
// cb(data);
// }
// } catch (error) {
// console.error(`Error processing item ${item}:`, error);
// }
// }
// }
// }
}
}
export
default
MAPGEO
export
default
MAPGEO
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment