餐饮油烟智能监测与监管一体化平台
riku
2026-03-18 8e8d00477b1f30183d0d09cd7ec744067595dc46
src/utils/map/util.js
@@ -1,5 +1,5 @@
import { map, AMap, isDragging } from '@/utils/map/index';
import marks from '@/utils/map/marks';
import { map, AMap, isDragging } from '@/utils/map/index'
import marks from '@/utils/map/marks'
/**
 * 坐标集合的最西南角和最东北角
@@ -7,35 +7,35 @@
 *  list 是接口获取的点 的数组
 */
const getBound = (list) => {
  const offset = 0.005;
  let south = null;
  let west = null;
  let north = null;
  let east = null;
  const offset = 0.05
  let south = null
  let west = null
  let north = null
  let east = null
  for (let item of list) {
    // 排除无效经纬度
    if (item[0] == 0 && item[1] == 0) {
      continue;
      continue
    }
    if ((west && item[0] < west) || !west) {
      west = item[0] - offset;
      west = item[0] - offset
    }
    if ((south && item[1] < south) || !south) {
      south = item[1] - offset;
      south = item[1] - offset
    }
    if ((east && item[0] > east) || !east) {
      east = item[0] + offset;
      east = item[0] + offset
    }
    if ((north && item[1] > north) || !north) {
      north = item[1] + offset;
      north = item[1] + offset
    }
  }
  if (!south || !west || !north || !east) {
    return { sw: null, ne: null };
    return { sw: null, ne: null }
  } else {
    return { sw: [west, south], ne: [east, north] };
    return { sw: [west, south], ne: [east, north] }
  }
};
}
/**
 * 根据中心点出发的半径,得到合适的地图缩放系数
@@ -45,64 +45,61 @@
 */
const distanceToZoom = (d) => {
  let baseDis = 250,
    z = 0;
    z = 0
  while (baseDis < d) {
    baseDis *= 2;
    z++;
    baseDis *= 2
    z++
  }
  // 多余的地图缩放系数
  const x = (baseDis - d) / (baseDis / 2);
  z -= x;
  z = z < 0 ? 0 : z;
  const x = (baseDis - d) / (baseDis / 2)
  z -= x
  z = z < 0 ? 0 : z
  z = 18 - z;
  z = z < 3 ? 3 : z;
  return z;
};
  z = 18 - z
  z = z < 3 ? 3 : z
  return z
}
export default {
  setCenter(lnglat, ignore = false) {
    if (!ignore && isDragging) {
      return;
      return
    }
    var now = new Date();
    if (
      this.lasttime == undefined ||
      now.getTime() - this.lasttime.getTime() >= 200
    ) {
      map.setCenter(lnglat);
      this.lasttime = now;
    var now = new Date()
    if (this.lasttime == undefined || now.getTime() - this.lasttime.getTime() >= 200) {
      map.setCenter(lnglat)
      this.lasttime = now
    }
  },
  addViews(view) {
    map.add(view);
    map.add(view)
  },
  removeViews(view) {
    map.remove(view);
    map.remove(view)
  },
  clearMap() {
    marks.clearMassMarks();
    map.clearMap();
    marks.clearMassMarks()
    map.clearMap()
  },
  setFitView(views) {
    if (views) {
      map.setFitView(views);
      map.setFitView(views)
    } else {
      map.setFitView();
      map.setFitView()
    }
  },
  setFitSector({ p, r }) {
    this.setCenter(p);
    const z = distanceToZoom(r);
    map.setZoom(z);
    this.setCenter(p)
    const z = distanceToZoom(r)
    map.setZoom(z)
  },
  setBound(lnglats_GD) {
    const { sw, ne } = getBound(lnglats_GD);
    const { sw, ne } = getBound(lnglats_GD)
    if (!sw || !ne) {
      return;
      return
    }
    var mybounds = new AMap.Bounds(sw, ne); // sw, ne > [xxx,xxx], [xxx,xxx]
    map.setBounds(mybounds);
  }
};
    var mybounds = new AMap.Bounds(sw, ne) // sw, ne > [xxx,xxx], [xxx,xxx]
    map.setBounds(mybounds)
  },
}