Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

bounds.js 735B

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