From 56bae942caaaa197091cf4fa1f05481b1b643d48 Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Fri, 23 Apr 2021 18:16:53 +0800
Subject: [PATCH] 修改路径

---
 public/map/widgets/securityMap/SecurityMap.js |  282 +++++++++++++++++++++++++++++++-------------------------
 1 files changed, 155 insertions(+), 127 deletions(-)

diff --git a/public/map/widgets/securityMap/SecurityMap.js b/public/map/widgets/securityMap/SecurityMap.js
index 3599e89..4e57a9d 100644
--- a/public/map/widgets/securityMap/SecurityMap.js
+++ b/public/map/widgets/securityMap/SecurityMap.js
@@ -125,18 +125,10 @@
         _siteLayer: new GraphicsLayer(),
         layuiLayer: null,
         layuiLadate: null,
-        tabIndex: 0,
 
         // 保留添加实体图层的变量
         addEntitys: null,
         entitysData: [],
-
-
-        // 用来存储区域名称
-        globalRegionName: null,
-
-        // 用来区域得最大最小经纬度
-        currentDrawing: [],
 
         // 存储新增点,线,面,数据的地方
         polygonData: [],
@@ -150,8 +142,8 @@
         //当前处警员是否已有电子围栏
         isEngineer: false,
 
-        //当前处警员是否有位置信息
-        isPosition: true,
+        //是否可编辑
+        isEdit: false,
 
         // 用来记录巡逻区域或者巡逻路线的下标的
         patrolIndex: 0,
@@ -163,9 +155,12 @@
         offset: null,
         moveThis: null,
 
+        //编辑工具激活后为true
+        editToolbarStatus: false,
+
         //基础路径
-        pathUrl: "http://localhost:89",
-        //pathUrl:"https://web.byisf.com/api/blade-jfpts",
+        //pathUrl: "http://localhost:89",
+        pathUrl: "https://web.byisf.com/api/blade-jfpts",
 
         // 电子围栏需要新增的Id
         newElectronicFenceId: null,
@@ -180,6 +175,7 @@
             this._map = options.map;
             objThis = this;
 
+            //创建图层
             this.addEntitys = new GraphicsLayer({
                 id: 'addEntitys'
             });
@@ -206,50 +202,60 @@
             var that = this;
 
             //删除电子围栏点击事件
-            $(".mapBtn .delete").click(function() {
+            $(".mapBtn .delBtn").click(function() {
                 //需选中电子围栏,然后进行删除
-                if (that.isChecked) {
-                    that.addPolygonEntitys.clear();
+                layer.confirm('是否确认删除', {
+                    btn: ['确定', '取消'], //按钮
+                    title: false
+                }, function() {
                     //删除数据库数据
-                    //更新电子围栏数据
                     $.ajax({
-                            url: that.pathUrl + '/enclosure/enclosure/deleteByAnumber',
-                            type: 'POST',
-                            dataType: 'JSON',
-                            data: {
-                                anumber: anumber
-                            },
-                            success: function(result) {
-                                if (result.code == 200) {}
+                        url: that.pathUrl + '/enclosure/enclosure/deleteByAnumber',
+                        type: 'POST',
+                        dataType: 'JSON',
+                        data: {
+                            anumber: anumber
+                        },
+                        success: function(result) {
+                            if (result.code == 200) {
+                                layui.use('layer', function() {
+                                    layui.layer.msg('删除电子围栏成功!')
+                                })
                             }
-                        })
-                        //修改围栏状态
-                    that.isEngineer = false;
-                } else {
-                    layui.use('layer', function() {
-                        layui.layer.msg('请先选中需要删除的电子围栏');
+                        }
                     })
-                }
+                    that.addPolygonEntitys.clear();
+                    //修改围栏状态
+                    that.isEngineer = false;
+                })
             })
 
             //新增电子围栏
-            $('.mapBtn .insert').click(function() {
-                if (that.isPosition) {
-                    if (that.isEngineer) {
-                        layui.use('layer', function() {
-                            layui.layer.msg('已存在电子围栏');
-                        })
-                    } else {
-                        layui.use('layer', function() {
-                            layui.layer.msg('请开始划分电子围栏');
-                        })
-                        that.polygonFlag = true;
-                    }
+            $('.mapBtn .insBtn').click(function() {
+                //修改按钮样式
+                $("#insertEngineeringMap").css("color", "#3385FF")
+                    //判断
+                if (that.isEngineer) {
+                    layui.use('layer', function() {
+                        layui.layer.msg('已存在电子围栏');
+                    })
                 } else {
                     layui.use('layer', function() {
-                        layui.layer.msg('当前处警员无位置信息,不能划分电子围栏');
+                        layui.layer.msg('请开始划分电子围栏');
                     })
+                    that.polygonFlag = true;
                 }
+            })
+
+
+            //编辑电子围栏
+            $('.mapBtn .editBtn').click(function() {
+                $("#editEngineeringMap").css("color", "#3385FF");
+                //修改为可编辑状态
+                that.isEdit = true;
+                layui.use('layer', function() {
+                    layui.layer.msg('点击电子围栏图形即可编辑');
+                })
             })
 
         },
@@ -275,63 +281,55 @@
             var lttd = that.getQueryStringByKey('wd');
             anumber = that.getQueryStringByKey('code');
             realname = that.getQueryString('name');
-            console.log(lgtd, 1111);
             //如果处警员的位置信息存在
             if (lgtd != null && lgtd != "") {
                 //所在位置标记
                 that.addPoint(that.addEntitys, lgtd, lttd, './images/security.png');
-                //获取当前处警员的电子围栏信息
-                $.ajax({
-                    url: this.pathUrl + '/enclosure/enclosure/selectEnclosureDetail',
-                    type: 'GET',
-                    dataType: 'JSON',
-                    data: {
-                        anumber: anumber
-                    },
-                    success: function(result) {
-                        //如果已有电子围栏信息,展示出围栏区域,并且可以编辑
-                        if (result.code == 200) {
-                            if (JSON.stringify(result.data) != "{}") {
-                                var entityArr = [];
-                                var coordinate = result.data.coordinate.match(/\(([^)]*)\)/).toString();
-                                var a = coordinate.indexOf("(");
-                                var b = coordinate.indexOf(")");
-                                coordinate = coordinate.substring(a + 1, b) + "";
-                                if (coordinate && coordinate != '') {
-                                    coordinate = coordinate.split(',');
-                                    for (var i = 0; i < coordinate.length; i++) {
-                                        entityArr.push([Number(coordinate[i].split(' ')[0]), Number(coordinate[i].split(' ')[1])]);
-                                    }
+            }
+
+            //获取当前处警员的电子围栏信息
+            $.ajax({
+                url: this.pathUrl + '/enclosure/enclosure/selectEnclosureDetail',
+                type: 'GET',
+                dataType: 'JSON',
+                data: {
+                    anumber: anumber
+                },
+                success: function(result) {
+                    //如果已有电子围栏信息,展示出围栏区域,并且可以编辑
+                    if (result.code == 200) {
+                        if (JSON.stringify(result.data) != "{}") {
+                            var entityArr = [];
+                            var coordinate = result.data.coordinate.match(/\(([^)]*)\)/).toString();
+                            var a = coordinate.indexOf("(");
+                            var b = coordinate.indexOf(")");
+                            coordinate = coordinate.substring(a + 1, b) + "";
+                            if (coordinate && coordinate != '') {
+                                coordinate = coordinate.split(',');
+                                for (var i = 0; i < coordinate.length; i++) {
+                                    entityArr.push([Number(coordinate[i].split(' ')[0]), Number(coordinate[i].split(' ')[1])]);
                                 }
-                                that.isEngineer = true;
-                                that.addPolygon(that.addPolygonEntitys, entityArr);
-                            } else {
-                                //如果无电子围栏信息,则提示请编辑电子围栏信息
-                                //编辑好电子围栏信息后,将当前处警员的电子围栏信息保存到数据库
-                                that.newElectronicFenceId = null;
-                                //that.polygonFlag = true;
-                                that.newElectronicFenceId = anumber;
                             }
+                            that.isEngineer = true;
+                            that.addPolygon(that.addPolygonEntitys, entityArr);
+                        } else {
+                            //如果无电子围栏信息,则提示请编辑电子围栏信息
+                            //编辑好电子围栏信息后,将当前处警员的电子围栏信息保存到数据库
+                            that.newElectronicFenceId = null;
+                            that.newElectronicFenceId = anumber;
                         }
                     }
-                })
-            } else {
-                //当前处警员没有位置信息,则默认定位到市中心位置
-                that.isPosition = false;
-            }
+                }
+            })
 
             //调用点击事件
             that.clickHand();
 
             //鼠标右击事件
             document.getElementById('mainMapWidget').onmousedown = function(event) {
+                //去除系统默认右键功能
+                event.preventDefault();
                 if (event.button == 2) {
-                    if (that.polygonData.length < 2) {
-                        layui.use('layer', function() {
-                            layui.layer.msg('不能形成区域,请继续划分!!!')
-                        })
-                        return;
-                    }
                     if (that.polygonFlag == true) {
                         // 勾画最后一个点
                         var normalizedVal = webMercatorUtils.xyToLngLat(event.mapPoint.x, event.mapPoint.y);
@@ -357,8 +355,7 @@
 
                         //将数据存入数据库
                         $.ajax({
-                            url: that
-                                .pathUrl + '/enclosure/enclosure/insertes',
+                            url: that.pathUrl + '/enclosure/enclosure/insertes',
                             type: 'POST',
                             dataType: 'JSON',
                             data: {
@@ -367,7 +364,11 @@
                                 routeInfo: dataStr
                             },
                             success: function(result) {
-                                if (result.code == 200) {}
+                                if (result.code == 200) {
+                                    layui.use('layer', function() {
+                                        layui.layer.msg('新增电子围栏成功!')
+                                    })
+                                }
                             }
                         })
                     }
@@ -384,7 +385,6 @@
         // 鼠标点击事件
         clickHand: function() {
             var that = this;
-
             var self = this;
             self._map.onClick = mapClick;
 
@@ -420,58 +420,75 @@
 
                         that.isChecked = true;
 
-                        self.modifyPolygon();
+                        //self.modifyPolygon();
 
-                        self.activateToolbar(evt.graphic);
+                        //进入编辑状态
+                        //self.activateToolbar(evt.graphic);
                     } else { // 点击不在图形上
                         //修改电子围栏选中状态
                         that.isChecked = false;
+
                         self.modifyPolygon()
+                    }
+
+                    if (that.isEdit) {
+                        that.isChecked = true;
+                        self.modifyPolygon();
+                        //进入编辑状态
+                        self.activateToolbar(evt.graphic);
                     }
                 }
 
             }
 
             // 提示信息
-            $(document).off('mousemove').mousemove(function(e) {
-                var y = e.clientY + 10;
-                var x = e.clientX + 20;
-
-                if (e.clientX < 40) {
-                    var x = 40;
-                }
-
-                if (e.clientY < 42) {
-                    y = 42;
-                }
-
-                if (e.clientY > ($(window).height() - 82)) {
-                    y = ($(window).height() - 66);
-                }
-
-                if (e.clientX > ($(window).width() - 184)) {
-                    x = ($(window).width() - 184);
-                }
-
+            $(document).off('mousemove').mousemove(function(ev) {
+                var oEvent = ev || event;
+                //鼠标移动
+                var oDiv1 = document.getElementById('securityMapTips1');
+                var oDiv2 = document.getElementById('securityMapTips2');
+                var oDiv3 = document.getElementById('securityMapTips3');
+                var oDiv4 = document.getElementById('securityMapTips4');
+                //新增电子围栏提示语
                 if (self.polygonFlag == true) {
-                    $('.securityMapTips').stop().show();
-
+                    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
+                    var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
                     if (self.polygonData.length == 0) {
-                        $('.securityMapTips').text('单击左键开始绘制。');
-                    } else {
-                        if (e.clientY > ($(window).height() - 98)) {
-                            y = ($(window).height() - 88);
-                        }
-                        $('.securityMapTips').text('单击左键新增加点。单击右键完成绘制。');
+                        oDiv1.style.left = oEvent.clientX + scrollLeft + 15 + 'px';
+                        oDiv1.style.top = oEvent.clientY + scrollTop + 'px';
+                        oDiv1.style.display = 'block';
                     }
 
-                    $('.securityMapTips').css({
-                        'top': y,
-                        'left': x,
-                    })
+                    if (self.polygonData.length == 1) {
+                        oDiv1.style.display = 'none';
+                        oDiv2.style.left = oEvent.clientX + scrollLeft + 15 + 'px';
+                        oDiv2.style.top = oEvent.clientY + scrollTop + 'px';
+                        oDiv2.style.display = 'block';
+                    }
+
+                    if (self.polygonData.length > 1) {
+                        oDiv2.style.display = 'none';
+                        oDiv3.style.left = oEvent.clientX + scrollLeft + 15 + 'px';
+                        oDiv3.style.top = oEvent.clientY + scrollTop + 'px';
+                        oDiv3.style.display = 'block';
+                    }
                 } else {
-                    $('.securityMapTips').stop().hide();
+                    oDiv3.style.display = 'none';
                 }
+
+                //编辑电子围栏提示语
+                if (that.editToolbarStatus) {
+                    $("#securityMapTips4").css("width", "200px");
+                    $("#securityMapTips4").css("height", "36");
+                    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
+                    var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
+                    oDiv4.style.left = oEvent.clientX + scrollLeft + 15 + 'px';
+                    oDiv4.style.top = oEvent.clientY + scrollTop + 'px';
+                    oDiv4.style.display = 'block';
+                } else {
+                    oDiv4.style.display = 'none';
+                }
+
             })
         },
 
@@ -526,15 +543,24 @@
                         routeInfo: dataStr
                     },
                     success: function(result) {
-                        if (result.code == 200) {}
+                        if (result.code == 200) {
+                            layui.use('layer', function() {
+                                layui.layer.msg('电子围栏修改成功!');
+                            })
+                            $("#editEngineeringMap").css("color", "#757575");
+                            self.isEdit = false;
+                            self.editToolbarStatus = false;
+                        }
                     }
                 })
-
             }
         },
 
 
         activateToolbar: function(graphic) {
+            var that = this;
+
+            that.editToolbarStatus = true;
             var tool = 0;
 
             this.editToolbar = new Edit(this._map);
@@ -605,5 +631,7 @@
         }
 
     });
+
+
     return Widget;
 });
\ No newline at end of file

--
Gitblit v1.9.3