|
@@ -77,6 +77,7 @@
|
|
|
<script>
|
|
|
|
|
|
import { addFenceInfo, listFenceInfo, updateFenceInfo } from '@/api/bd/fenceInfo';
|
|
|
+import maphandle from '@/views/bd/map/maphandle';
|
|
|
import Pannel from '@/views/bd/pannel/index.vue';
|
|
|
// this.drawtool = new BDLayers.Lib.Tools.CBDrawTool('mytool', this.mapView, 'Rectangle', true); // 绘制矩形,参数1:id,参数2:地图,参数3:绘制类型,参数4:是否可拖拽编辑
|
|
|
// this.drawtool.enable(); // 开始绘制
|
|
@@ -88,12 +89,12 @@ import Pannel from '@/views/bd/pannel/index.vue';
|
|
|
export default {
|
|
|
name: 'fence',
|
|
|
components: { Pannel },
|
|
|
+ mixins: [maphandle],
|
|
|
data() {
|
|
|
return {
|
|
|
playItem: {},
|
|
|
editState: false,
|
|
|
editPolyInfo: {},
|
|
|
- layer: null,
|
|
|
dialogVisible: false,
|
|
|
editingDrawGeom: null,
|
|
|
drawState: false,
|
|
@@ -115,7 +116,6 @@ export default {
|
|
|
},
|
|
|
// 组件卸载前清空图层信息
|
|
|
beforeDestroy() {
|
|
|
- window.map.removeLayersById('vl');
|
|
|
window.map.removeLayersById('drawLayer');
|
|
|
window.map.removeLayersById('distanceLayer');
|
|
|
this.drawtool?.disable();
|
|
@@ -153,10 +153,6 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
async getFenceList() {
|
|
|
- if (!this.layer) {
|
|
|
- this.layer = new BDLayers.Lib.Layer.CBVectorLayer('vl');
|
|
|
- window.map.addCustomLayers(this.layer);
|
|
|
- }
|
|
|
const { rows } = await listFenceInfo({
|
|
|
pageNum: 1,
|
|
|
pageSize: 10,
|
|
@@ -171,7 +167,7 @@ export default {
|
|
|
defenceName,
|
|
|
poly,
|
|
|
} = item;
|
|
|
- const polygon = this.drawPoly({
|
|
|
+ const polygon = this.custDrawPoly({
|
|
|
name: defenceName,
|
|
|
coordinates: this.polygonToCoordinates(poly),
|
|
|
bizAttr: {
|
|
@@ -179,7 +175,6 @@ export default {
|
|
|
name: defenceName,
|
|
|
},
|
|
|
});
|
|
|
- this.layer.addGeometry(polygon);
|
|
|
result.push({
|
|
|
id,
|
|
|
name: defenceName,
|
|
@@ -195,19 +190,6 @@ export default {
|
|
|
// duration: 5000,
|
|
|
// });
|
|
|
},
|
|
|
- polygonToCoordinates(polygon) {
|
|
|
- // 正则表达式匹配坐标点
|
|
|
- const regex = /(-?\d+(\.\d+)?\s-?\d+(\.\d+)?)/g;
|
|
|
- const matches = polygon.match(regex);
|
|
|
- if (matches && matches.length > 0) {
|
|
|
- return matches
|
|
|
- .map(point => {
|
|
|
- const [x, y] = point.trim().split(" ").map(Number);
|
|
|
- return [x, y];
|
|
|
- });;
|
|
|
- }
|
|
|
- return [];
|
|
|
- },
|
|
|
cancelEdit() {
|
|
|
this.drawtool.clear();
|
|
|
this.dialogVisible = false;
|
|
@@ -251,7 +233,7 @@ export default {
|
|
|
},
|
|
|
bizAttr: this.form,
|
|
|
});
|
|
|
- this.layer.addGeometry(polygon);
|
|
|
+ this.polyLayer.addGeometry(polygon);
|
|
|
this.editingDrawGeom = null;
|
|
|
this.editState = false;
|
|
|
this.$refs.form.resetFields();
|
|
@@ -288,30 +270,20 @@ export default {
|
|
|
* @param labelSymbol
|
|
|
* @returns {BDLayers.Lib.Overlays.Polygon}
|
|
|
*/
|
|
|
- drawPoly({
|
|
|
+ custDrawPoly({
|
|
|
name = '多边形',
|
|
|
coordinates,
|
|
|
symbol = {},
|
|
|
bizAttr = {},
|
|
|
labelSymbol = {},
|
|
|
}) {
|
|
|
- const polygon = new BDLayers.Lib.Overlays.Polygon('p1', {
|
|
|
- coordinates: coordinates,
|
|
|
- symbol: Object.assign({
|
|
|
- lineColor: '#34495e',
|
|
|
- lineWidth: 2,
|
|
|
- polygonFill: '#1bbc9b',
|
|
|
- polygonOpacity: 0.4,
|
|
|
- }, symbol),
|
|
|
- labelSymbol: Object.assign({
|
|
|
- labelText: name,
|
|
|
- labelColor: '#fefefe',
|
|
|
- labelTextSize: 20,
|
|
|
- }, labelSymbol),
|
|
|
- bizAttr: bizAttr,
|
|
|
- });
|
|
|
- //多边形的点击事件
|
|
|
- polygon.on('click', (data) => {
|
|
|
+ return this.drawPoly({
|
|
|
+ name,
|
|
|
+ coordinates,
|
|
|
+ symbol,
|
|
|
+ bizAttr,
|
|
|
+ labelSymbol,
|
|
|
+ polyOnClick: (data) => {
|
|
|
console.log(data.target.options);
|
|
|
if (this.editState) {
|
|
|
return;
|
|
@@ -342,8 +314,8 @@ export default {
|
|
|
this.editingDrawGeom.endEdit();
|
|
|
this.dialogVisible = true;
|
|
|
});
|
|
|
- });
|
|
|
- return polygon;
|
|
|
+ },
|
|
|
+ })
|
|
|
},
|
|
|
delFence(fence) {
|
|
|
// polygon.geom.startEdit();
|