Commit 01990e91 by 张杰

修改圆形围栏

1 parent 8bf5e171
......@@ -38,7 +38,10 @@
<div class="radio_cell">
<el-radio :label="1" v-model="form.shapeType">圆形</el-radio>
<el-form-item label="" prop="radius">
<el-input v-model.trim="form.radius" style="width: 80px;" maxlength="200" @change="changeRadius"></el-input>米
<el-input v-model.trim="form.radius" style="width:120px" maxlength="200">
<template slot="append">米</template>
</el-input>
<el-button type="primary" class="btn" :disabled="!form.radius" @click="changeRadius">更新</el-button>
</el-form-item>
</div>
<div class="radio_cell">
......@@ -289,7 +292,7 @@ export default {
}
showToast({
message: "保存成功",
type: "success"
type: "success",
});
})
.catch((error) => {
......@@ -457,20 +460,16 @@ export default {
},
// 监听圆形半径更改
changeRadius(e) {
changeRadius() {
let reg = /^\d+$/;
let e = this.form.radius;
if (!reg.test(e) || e > 10000) {
showToast({
message: "请输入1-10000间的整数",
});
return false;
}
this.$refs.fenceMap.updateFence({
fenceType: "circle",
lng: this.form.lng,
lat: this.form.lat,
radius: this.form.radius,
});
EventBus.$emit("uiMap.fence.updateFenceRadius", { fenceType:'circle',radius: e });
},
},
};
......
......@@ -300,6 +300,7 @@ export default {
}
}, 100);
},
// 更新围栏信息
updateFence(data) {
let _this = this;
let mapInterval = setInterval(function () {
......
......@@ -186,6 +186,7 @@ import { CONSTANT } from "@/constant";
import MapControll from "./MapControll.vue";
import { exportExcel } from "@/utils";
import { GET_MONITOR_ONLINELIST } from "@/api/services/monitor";
import AMapLoader from "@amap/amap-jsapi-loader";
export default {
data() {
let checkFilename = (rule, vaule, cb) => {
......@@ -1206,17 +1207,17 @@ export default {
},
},
created() {
if (window.AMap) {
this.initMap();
} else {
remoteLoad(`${CONSTANT.AMAP_URL}`).then(() => {
remoteLoad(`https://webapi.amap.com/ui/1.0/main.js?v=1.0.11`).then(
() => {
this.initMap();
}
);
});
}
// if (window.AMap) {
// this.initMap();
// } else {
// remoteLoad(`${CONSTANT.AMAP_URL}`).then(() => {
// remoteLoad(`https://webapi.amap.com/ui/1.0/main.js?v=1.0.11`).then(
// () => {
// this.initMap();
// }
// );
// });
// }
this.keyupSubmit();
EventBus.$on("uiMap.monitor.drawDone", this.drawDoneCb);
EventBus.$on("uiMap.monitor.changeELocate", this.changeELocate);
......@@ -1224,6 +1225,17 @@ export default {
this.getTreeData();
},
mounted(){
let _this = this;
AMapLoader.load({
key: CONSTANT.MAP_KEY,
version: "1.4.2",
plugins: CONSTANT.MAP_PLUGINS,
}).then((AMap) => {
window.AMap = AMap;
_this.initMap();
});
},
beforeDestroy() {
document.onkeydown = null;
EventBus.$emit("uiMap.monitor.destroy");
......
<template>
<v-full-layout>
<v-full-layout class="full_wrap_layout">
<template slot="breadcrumb">
<el-breadcrumb-item>车辆监控</el-breadcrumb-item>
</template>
......
......@@ -22,9 +22,10 @@ const fence = {
});
EventBus.$on('uiMap.fence.updateFenceRadius', (data) => {
this.circle.setRadius(data * 1);
mapService.setFitView()
console.log('监听围栏更新',data)
this.updateFenceInfo(data)
});
//this.circle.setRadius(data * 1);
EventBus.$on('uiMap.fence.createFenceMarker', (data) => {
this.createFenceMarker(data)
......@@ -126,11 +127,20 @@ const fence = {
const MAP = mapService.map;
_this.destroy();
let mapInterval = setInterval(() => {
if(MAP){
if (MAP) {
clearInterval(mapInterval)
console.log(data)
let lng = data.lng || _this.lng
let lat = data.lat || _this.lat
if (data.lng) {
_this.lng = data.lng
}
if (data.lat) {
_this.lat = data.lat
}
_this.circle = new AMap.Circle({
map: MAP,
center: mapService.getLngLat(data.lng, data.lat),
center: mapService.getLngLat(lng, lat),
radius: data.radius * 1,
strokeColor: "#F33",
strokeOpacity: 1,
......@@ -139,19 +149,20 @@ const fence = {
fillOpacity: 0.35,
zIndex: 0,
});
_this.circleEditor = new AMap.CircleEditor(MAP, _this.circle);
_this.circleEditor.on('adjust', function (e) {
//log.info('触发事件:adjust')
console.log('监听圆心改变', e)
EventBus.$emit('uiMap.fence.onFenceRadiusChange', e.radius / 1)
})
_this.circleEditor.on('move', function (e) {
EventBus.$emit('uiMap.fence.onFenceLngLatChange', {
lng: e.lnglat.lng,
lat: e.lnglat.lat
});
})
if (_this.isEditMode) {
_this.circleEditor.open();
} else {
......@@ -159,9 +170,10 @@ const fence = {
}
mapService.setFitView()
MAP.setZoom(14);
_this.bindContextMenu()
}
}, 100);
},
createFenceMarker(data) {
......@@ -283,6 +295,94 @@ const fence = {
item && window.clearTimeout(item);
});
this.timeoutIds = []
},
// 地图增加右键功能
bindContextMenu() {
const self = this;
const MAP = mapService.map;
var contextMenu = new AMap.ContextMenu();
contextMenu.addItem(
"设置围栏中心",
function () {
self.moveCenter();
},
0
);
//地图绑定鼠标右击事件——弹出右键菜单
MAP.on("rightclick", function (e) {
contextMenu.open(MAP, e.lnglat);
self.contextMenuPositon = e.lnglat;
});
},
// 改变圆心
moveCenter() {
this.lng = this.contextMenuPositon.lng;
this.lat = this.contextMenuPositon.lat;
let center = mapService.getLngLat(this.lng, this.lat);
this.circle.setCenter(center);
EventBus.$emit('uiMap.fence.onFenceLngLatChange', {
lng: this.lng,
lat: this.lat,
});
},
// 更新围栏
updateFenceInfo(data) {
let _this = this;
const MAP = mapService.map;
let mapInterval = setInterval(function () {
if (MAP) {
clearInterval(mapInterval);
MAP.clearMap();
_this.fenceType = data.fenceType;
_this.polyEditor && _this.polyEditor.close();
_this.mouseTool && _this.mouseTool.close();
// 更新圆形围栏
if (data.fenceType == 'circle') {
_this.fenceCircle = null;
if (data.lng) {
_this.lng = data.lng;
}
if (data.lat) {
_this.lat = data.lat;
}
if (data.radius) {
_this.radius = Number(data.radius);
}
console.log(data)
_this.createFenceCircle(data);
return false;
}
// 更新行政区域围栏
if (data.fenceType === "area") {
_this.areaCode = data.areaCode;
_this.drawDistrict(data);
return false
}
// 更新多边形围栏
if (data.fenceType === "polygon") {
if (data) {
if (Array.isArray(data)) {
this.polygonPath = data;
this.isEditMode = true;
} else if (('isEdit' in data) && !data.isEdit) {
this.polygonPath = data.path;
this.isEditMode = false;
}
}
_this.drawPolygon();
}
mapService.setFitView()
MAP.setZoom(14);
}
}, 100);
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!