You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bounds.js 756B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-04-23 09:29:56
  4. */
  5. export default function bounds(positions = [], expand = 0) {
  6. let minLng = 180
  7. let minLat = 90
  8. let maxLng = -180
  9. let maxLat = -90
  10. positions.forEach(item => {
  11. minLng = Math.min(minLng, item.lng || item.x)
  12. minLat = Math.min(minLat, item.lat || item.y)
  13. maxLng = Math.max(maxLng, item.lng || item.x)
  14. maxLat = Math.max(maxLat, item.lat || item.y)
  15. })
  16. if (expand > 0) {
  17. let diffLng = Math.abs(maxLng - maxLng)
  18. let diffLat = Math.abs(maxLat - minLat)
  19. minLng -= diffLng * expand
  20. minLat -= diffLat * expand
  21. maxLng += diffLng * expand
  22. maxLat += diffLat * expand
  23. }
  24. return {
  25. west: minLng,
  26. south: minLat,
  27. east: maxLng,
  28. north: maxLat
  29. }
  30. }