/** * 根據一組點位([緯度,經度])計算出中心點 * @param pointArray * @returns {*[]} */ const calculateCenterPoint=(pointArray)=>{ const sortedLongitudeArray=pointArray.map(item=>item.lng).sort(); const sortedLatitudeArray=pointArray.map(item=>item.lat).sort(); const centerLongitude=((sortedLongitudeArray[0]+sortedLongitudeArray[sortedLongitudeArray.length-1])/2).toFixed(4); const centerLatitude=((sortedLatitudeArray[0]+sortedLatitudeArray[sortedLatitudeArray.length-1])/2).toFixed(4); return [centerLongitude,centerLatitude]; }; export default calculateCenterPoint;