| | |
| | | |
| | | import { map } from './index_old'; |
| | | |
| | | function _prepare4convert(lnglats) { |
| | | var coor = []; |
| | | var maxLength = 1000; |
| | | var start = 0; |
| | | var end = start + maxLength; |
| | | while (end <= lnglats.length) { |
| | | coor.push(lnglats.slice(start, end)); |
| | | start += maxLength; |
| | | end += maxLength; |
| | | } |
| | | if (start < lnglats.length) { |
| | | coor.push(lnglats.slice(start)); |
| | | } |
| | | return coor; |
| | | } |
| | | |
| | | function parse2LngLat(lnglats) { |
| | | // 创建包含4个节点的折线及文字标注 |
| | | var path = []; |
| | | lnglats.forEach(function (value) { |
| | | // eslint-disable-next-line no-undef |
| | | path.push(new AMap.LngLat(value[0], value[1])); |
| | | }); |
| | | return path; |
| | | } |
| | | |
| | | /** |
| | | * 将gps经纬度转换为高德地图经纬度 |
| | | * @param {*} lnglats |
| | | * @param {*} callback |
| | | */ |
| | | function _convertLatlng(index, coor, lnglats, callback) { |
| | | if (index < coor.length) { |
| | | var path = parse2LngLat(coor[index]); |
| | | // eslint-disable-next-line no-undef |
| | | AMap.convertFrom(path, 'gps', function (status, result) { |
| | | if (result.info === 'ok') { |
| | | lnglats.push.apply(lnglats, result.locations); |
| | | _convertLatlng(index + 1, coor, lnglats, callback); |
| | | } |
| | | }); |
| | | } else { |
| | | callback(lnglats); |
| | | } |
| | | } |
| | | |
| | | export default { |
| | | /** |
| | | * 根据坐标点、距离和角度,得到另一个坐标点 |
| | |
| | | coors_GD.push(p); |
| | | } |
| | | return coors_GD; |
| | | }, |
| | | |
| | | convertFromGPS: function (gps, callback) { |
| | | var coor = _prepare4convert(gps); |
| | | _convertLatlng(0, coor, [], function (result) { |
| | | var gd = []; |
| | | result.forEach((r) => { |
| | | gd.push([r.lng, r.lat]); |
| | | }); |
| | | callback(gd); |
| | | }); |
| | | } |
| | | }; |