|
@@ -6,14 +6,13 @@
|
|
|
import { ref, onMounted, onUnmounted } from "vue";
|
|
|
import AMapLoader from "@amap/amap-jsapi-loader";
|
|
|
import eventBus from "@/api/eventBus";
|
|
|
+import { convertPointToArray } from "@/utils/index";
|
|
|
|
|
|
const map = ref(null);
|
|
|
const mouseTool = ref(null);
|
|
|
const selectedArea = ref(null);
|
|
|
const selectedPoints = ref([]);
|
|
|
-const allPoints = ref([
|
|
|
- { lng: 113.61448114737868, lat: 23.585550924763083 }, // 示例点位
|
|
|
-]);
|
|
|
+const allPoints = ref([]);
|
|
|
const defalutIcon = ref(null)
|
|
|
const activeIcon = ref(null)
|
|
|
|
|
@@ -30,8 +29,8 @@ const initMap = async () => {
|
|
|
}).then((AMap) => {
|
|
|
// 创建地图实例
|
|
|
map.value = new AMap.Map("map-container", {
|
|
|
- zoom: 17, // 初始缩放级别
|
|
|
- center: [113.61448114737868 ,23.585550924763083],
|
|
|
+ zoom: 18, // 初始缩放级别
|
|
|
+ center: [113.6149629 ,23.58594117],
|
|
|
layers: [
|
|
|
// 卫星
|
|
|
new AMap.TileLayer.Satellite(),
|
|
@@ -60,11 +59,12 @@ const initMap = async () => {
|
|
|
// 添加示例点位
|
|
|
allPoints.value.forEach((point) => {
|
|
|
point.icon = new AMap.Marker({
|
|
|
- position: [point.lng, point.lat],
|
|
|
+ position: point.lngLat,
|
|
|
map: map.value,
|
|
|
icon:defalutIcon.value,
|
|
|
- offset: defalutOffset.value
|
|
|
+ offset: defalutOffset.value,
|
|
|
});
|
|
|
+ point.type = 'defalutIcon'
|
|
|
});
|
|
|
startRectangleSelection()
|
|
|
|
|
@@ -104,6 +104,7 @@ const clearSelection = () => {
|
|
|
selectedPoints.value.forEach(item =>{
|
|
|
item.icon.setIcon(defalutIcon.value)
|
|
|
item.icon.setOffset(defalutOffset.value)
|
|
|
+ item.type = 'defalutIcon'
|
|
|
})
|
|
|
selectedPoints.value = []; // 清空选中的点位
|
|
|
}
|
|
@@ -115,18 +116,42 @@ const checkPointsInArea = () => {
|
|
|
|
|
|
const bounds = selectedArea.value.getBounds(); // 获取框选区域的边界
|
|
|
selectedPoints.value = allPoints.value.filter((point) => {
|
|
|
- return bounds.contains([point.lng, point.lat]); // 判断点位是否在框选区域内
|
|
|
+ return bounds.contains(point.lngLat); // 判断点位是否在框选区域内
|
|
|
});
|
|
|
selectedPoints.value.forEach(item =>{
|
|
|
- item.icon.setIcon(activeIcon.value)
|
|
|
- item.icon.setOffset(activeOffset.value)
|
|
|
+ if(item.type==='defalutIcon'){
|
|
|
+ item.icon.setIcon(activeIcon.value)
|
|
|
+ item.icon.setOffset(activeOffset.value)
|
|
|
+ item.type = 'activeIcon'
|
|
|
+ }else{
|
|
|
+ item.icon.setIcon(defalutIcon.value)
|
|
|
+ item.icon.setOffset(defalutOffset.value)
|
|
|
+ item.type = 'defalutIcon'
|
|
|
+ }
|
|
|
})
|
|
|
- eventBus.emit('map:list',selectedPoints.value)
|
|
|
+ const arr = selectedPoints.value.filter(item =>item.type==='activeIcon')
|
|
|
+ eventBus.emit('map:list',arr)
|
|
|
};
|
|
|
|
|
|
+const getList = () =>{
|
|
|
+ const params = {
|
|
|
+ farmId:sessionStorage.getItem('farmId'),
|
|
|
+ regionId:sessionStorage.getItem('regionId')
|
|
|
+ }
|
|
|
+ VE_API.variety.pointList(params).then(res =>{
|
|
|
+ allPoints.value = res.data.map(item =>{
|
|
|
+ return{
|
|
|
+ ...item,
|
|
|
+ lngLat:convertPointToArray(item.point)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ initMap();
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
// 组件挂载时初始化地图
|
|
|
onMounted(() => {
|
|
|
- initMap();
|
|
|
+ getList()
|
|
|
eventBus.on('handle:clear',clearSelection)
|
|
|
});
|
|
|
|