From 321a114af75d62f66bd5d46f01a44c955cbde286 Mon Sep 17 00:00:00 2001
From: ZhuDongming <zdm773644075@hotmail.com>
Date: Mon, 02 Sep 2019 23:43:47 +0800
Subject: [PATCH] 更新污染传播接口

---
 src/main/webapp/view/pollutionsource.jsp |  187 ++++++++++++++++++++++++----------------------
 1 files changed, 96 insertions(+), 91 deletions(-)

diff --git a/src/main/webapp/view/pollutionsource.jsp b/src/main/webapp/view/pollutionsource.jsp
index c47f7ba..645061f 100644
--- a/src/main/webapp/view/pollutionsource.jsp
+++ b/src/main/webapp/view/pollutionsource.jsp
@@ -120,10 +120,9 @@
     var params = $.parseJSON($("#pollutionSourceParams").html());
     var month = params["month"];
     var device = params["device"];
-    var dirPoint=params["dirPoint"];
-    console.log(dirPoint.lng);
-    console.log(dirPoint.lat);
-    var getPollutionSourceData=params["getPollutionSourceData"];
+    var dirPoint = new BMap.Point(params["dirPoint"].lng, params["dirPoint"].lat);
+    var getPollutionSourceData = params["getPollutionSourceData"];
+    var windSpeed = parseFloat(getPollutionSourceData["e18"]);
     var map = new BMap.Map("mapCanvas", {enableMapClick: false});
     map.setMapStyle(mapStyle);
     map.enableScrollWheelZoom(true); // ������������������������
@@ -133,74 +132,86 @@
     });
     map.addControl(navigation);
     map.addControl(new BMap.ScaleControl());
-    if ($.isEmptyObject(dirPoint)||$.isEmptyObject(getPollutionSourceData)||getPollutionSourceData["e18"]==0) {
+    if ($.isEmptyObject(dirPoint) || $.isEmptyObject(getPollutionSourceData) || getPollutionSourceData["e6"] == 0 || getPollutionSourceData["e18"] == 0 || getPollutionSourceData["e23"] == 0 || windSpeed <= 0.03) {
         showNoData();
-    }else{
-        var humidity=getPollutionSourceData["e6"];
-        var windSpeed=getPollutionSourceData["e18"];
+    } else {
+        var humidity = parseFloat(getPollutionSourceData["e6"]);
+        var windDir = parseFloat(getPollutionSourceData["e23"]);
         var longitude = params["device"]["longitude"];
         var latitude = params["device"]["latitude"];
         var point = new BMap.Point(longitude, latitude);
         var icon = new BMap.Icon("/img/ico00.png", new BMap.Size(50, 50));
         var marker = new BMap.Marker(point, {icon: icon, offset: new BMap.Size(0, -20)});
         map.addOverlay(marker);
-        map.centerAndZoom(point, 17);
-        var polyline1 = new BMap.Polyline([
-                dirPoint,
-                new BMap.Point(point.lng+0.01, point.lat+0.01)
-            ],
-            {strokeColor: "#5298FF", strokeWeight: 4, strokeOpacity: 1}
-        );
-        var polyline2 = new BMap.Polyline([
-                dirPoint,
-                new BMap.Point( point.lng-0.02,  point.lat-0.01)
-            ],
-            {strokeColor: "#5298FF", strokeWeight: 4, strokeOpacity: 1}
-        );
-        var distance=windSpeed*3600;
-        console.log(distance);
-        var arrowLength;//���������������������
-        if (distance <= 5) {
-            arrowLength = 0;
-        } else if (distance > 5 && distance <= 20) {
-            arrowLength = 2;
-        } else if (distance > 20 && distance <= 50) {
-            arrowLength = 3;
-        } else if (distance > 50 && distance <= 100) {
-            arrowLength = 5;
-        } else if (distance > 100 && distance <= 200) {
-            arrowLength = 10;
-        } else if (distance > 200 && distance <= 500) {
-            arrowLength = 20;
-        } else if (distance > 500 && distance <= 1000) {
-            arrowLength = 40;
-        } else if (distance > 1000 && distance <= 2000) {
-            arrowLength = 80;
-        } else if (distance > 2000 && distance <= 3000) {
-            arrowLength = 120;
-        } else if (distance > 3000 && distance <= 10000) {
-            arrowLength = 500;
-        } else if (distance > 10000 && distance <= 20000) {
-            arrowLength = 1000;
-        } else if (distance > 20000 && distance <= 50000) {
-            arrowLength = 2500;
-        } else if (distance > 50000 && distance <= 100000) {
-            arrowLength = 5000;
-        } else if (distance > 100000 && distance <= 200000) {
-            arrowLength = 10000;
-        } else if (distance > 200000 && distance <= 500000) {
-            arrowLength = 25000;
-        } else if (distance > 500000 && distance <= 1000000) {
-            arrowLength = 50000;
-        } else if (distance > 1000000 && distance <= 2000000) {
-            arrowLength = 100000;
-        } else {
-            arrowLength = 150000;
+        map.centerAndZoom(point, 16);
+
+        //centre:���������������,X:������������,Y:������������
+        function add_oval(centre, x, y) {
+            var assemble = new Array();
+            var angle;
+            var dot;
+            var tangent = x / y;
+            for (i = 0; i < 36; i++) {
+                angle = (2 * Math.PI / 36) * i;
+                dot = new BMap.Point(centre.lng + Math.sin(angle) * y * tangent, centre.lat + Math.cos(angle) * y);
+                assemble.push(dot);
+            }
+            return assemble;
         }
-        map.addOverlay(polyline1);// ���������������
-        addArrow(polyline1, arrowLength, Math.PI / 7,windSpeed);
-        map.addOverlay(polyline2);// ���������������
-        addArrow(polyline2, arrowLength, Math.PI / 7,windSpeed);
+
+        //��������������������������������������������� ���������point������������������������radius������������sDegree���eDegree���������
+        function Sector(point, radius, sDegree, eDegree) {
+            var points = []; //���������������������������������
+            var step = ((eDegree - sDegree) / 10) || 10; //������������������������������������������������������������10
+            points.push(point);
+            for (var i = sDegree; i < eDegree + 0.001; i += step) { //������������������������������������������������������������
+                points.push(EOffsetBearing(point, radius, i));
+            }
+            points.push(point);
+            return points;
+        }
+
+        //������������������������������������������������������������������
+        function EOffsetBearing(point, dist, bearing) {
+            var lngConv = map.getDistance(point, new BMap.Point(point.lng + 0.1, point.lat)) * 10; //������������������������������
+            var latConv = map.getDistance(point, new BMap.Point(point.lng, point.lat + 0.1)) * 10; //������������������������������
+            var lat = dist * Math.sin(bearing * Math.PI / 180) / latConv; //������������������������������������������������������
+            var lng = dist * Math.cos(bearing * Math.PI / 180) / lngConv; //������������������������������������������������������
+            return new BMap.Point(point.lng + lng, point.lat + lat);
+        }
+
+        var distance = windSpeed * 3600;
+        var winDirStart = 240 - windDir;
+        var winDirEnd = 300 - windDir;
+        var oval = new BMap.Polygon(Sector(dirPoint, distance, winDirStart, winDirEnd), {
+            strokeColor: "grey",
+            strokeWeight: 1,
+            strokeOpacity: 0.8,
+            fillColor: "grey"
+        });
+        map.addOverlay(oval);
+        var oval = new BMap.Polygon(Sector(dirPoint, distance * 0.66, winDirStart, winDirEnd), {
+            strokeColor: "grey",
+            strokeWeight: 1,
+            strokeOpacity: 0.6,
+            fillColor: "grey"
+        });
+        map.addOverlay(oval);
+        var oval = new BMap.Polygon(Sector(dirPoint, distance * 0.33, winDirStart, winDirEnd), {
+            strokeColor: "grey",
+            strokeWeight: 1,
+            strokeOpacity: 0.4,
+            fillColor: "grey"
+        });
+        map.addOverlay(oval);
+
+        var polyline = new BMap.Polyline([
+                dirPoint,
+                point
+            ],
+            {strokeColor: "#5298FF", strokeWeight: 4, strokeOpacity: 1}
+        );
+        addArrow(polyline, 0, Math.PI / 7, windSpeed, humidity);
         var winfowTextCause = "<p style='height: 44px;line-height: 22px'>���������������������������������������������������������������������������������������������������������������������</p>";
         var winfowTextSource;
         var supplement;
@@ -208,40 +219,40 @@
             if (windSpeed >= 3.4) {
                 supplement = "���������������������������������������������������������������������������";
             }
-            if (humidity>=90.0) {
+            if (humidity >= 90.0) {
                 supplement = "������������������������������������������������������������������������";
-            }else{
-                supplement ="";
+            } else {
+                supplement = "";
             }
             winfowTextSource = "<p style='height: 22px;line-height: 22px'>���������������������������������������������������������������������������������" + supplement + "</p>";
         } else if (month == 3 || month == 4 || month == 5) {
             if (windSpeed >= 3.4) {
                 supplement = "���������������������������������������������������������������������������";
             }
-            if (humidity>=90.0) {
+            if (humidity >= 90.0) {
                 supplement = "������������������������������������������������������������������������";
-            }else{
-                supplement ="";
+            } else {
+                supplement = "";
             }
             winfowTextSource = "<p style='height: 22px;line-height: 22px'>���������������������������������������������������������������" + supplement + "</p>";
         } else if (month == 6 || month == 7) {
             if (windSpeed >= 3.4) {
                 supplement = "������������������������������������";
             }
-            if (humidity>=90.0) {
+            if (humidity >= 90.0) {
                 supplement = "���������������������������������������������������������������������������";
-            }else{
-                supplement ="";
+            } else {
+                supplement = "";
             }
             winfowTextSource = "<p style='height: 22px;line-height: 22px'>���������������������������������������,���������������������" + supplement + "</p>";
         } else if (month == 8 || month == 9 || month == 10 || month == 11) {
             if (windSpeed >= 3.4) {
                 supplement = "������������������������������������������";
             }
-            if (humidity>=90.0) {
+            if (humidity >= 90.0) {
                 supplement = "������������������������������������������������������������������������";
-            }else{
-                supplement ="";
+            } else {
+                supplement = "";
             }
             winfowTextSource = "<p style='height: 22px;line-height: 22px'>������������������������������������������������������������������������������������������������������" + supplement + "</p>";
         }
@@ -263,9 +274,7 @@
         });
     }
 
-
-
-    function addArrow(polyline, length, angleValue,windSpeed) {
+    function addArrow(polyline, length, angleValue, windSpeed, humidity) {
         var linePoint = polyline.getPath();// ���������������
         var arrowCount = linePoint.length;
         for (var i = 1; i < arrowCount; i++) { // ������������������������
@@ -276,7 +285,7 @@
             var delta = 0; // ���������������������������������
             var param = 0; // ������������������
             var pixelTemX, pixelTemY, poMiddleX, poMiddleY;// ���������������
-            var pixelX, pixelY, pixelX1, pixelY1;// ���������������
+            var pixelX, pixelY;// ���������������
             poMiddleX = (pixelEnd.x + pixelStart.x) / 2;
             poMiddleY = (pixelEnd.y + pixelStart.y) / 2;
             if (poMiddleX - pixelStart.x == 0) { // ������������������
@@ -288,8 +297,7 @@
                 }
                 // ���������������������������������������������������������������������������������������
                 pixelX = pixelTemX - r * Math.tan(angle);
-                pixelX1 = pixelTemX + r * Math.tan(angle);
-                pixelY = pixelY1 = pixelTemY;
+                pixelY = pixelTemY;
             } else { // ���������������
                 delta = (poMiddleY - pixelStart.y) / (poMiddleX - pixelStart.x);
                 param = Math.sqrt(delta * delta + 1);
@@ -303,24 +311,20 @@
                 // ���������������������������������������������������������������������������������������
                 pixelX = pixelTemX + Math.tan(angle) * r * delta / param;
                 pixelY = pixelTemY - Math.tan(angle) * r / param;
-                pixelX1 = pixelTemX - Math.tan(angle) * r * delta / param;
-                pixelY1 = pixelTemY + Math.tan(angle) * r / param;
             }
-            var pointArrow = map.pixelToPoint(new BMap.Pixel(pixelX, pixelY));
-            var pointArrow1 = map.pixelToPoint(new BMap.Pixel(pixelX1, pixelY1));
             var pointMiddle = map.pixelToPoint(new BMap.Pixel(poMiddleX, poMiddleY));
-            lab = new BMap.Label("���������"+windSpeed+"m/s", {position: pointMiddle, offset: new BMap.Size(0, -30)});
+            lab = new BMap.Label("<P>������:" + windSpeed + "m/s</p><P>������:" + humidity + "��</p>", {
+                position: pointMiddle,
+                offset: new BMap.Size(-50, -20)
+            });
             lab.setStyle({
-                color: "red",
+                color: "#FFFFFF",
                 fontSize: "16px",
                 backgroundColor: "1",
                 border: "0",
                 fontWeight: "bold"
             });
             map.addOverlay(lab);
-            var Arrow = new BMap.Polyline([pointArrow, pointMiddle, pointArrow1],
-                {strokeColor: "#5298FF", strokeWeight: 4, strokeOpacity: 1});
-            map.addOverlay(Arrow);
         }
     };
 
@@ -333,4 +337,5 @@
             document.getElementById("cpm").style.display = 'block';
         }, 250);
     };
+
 </script>

--
Gitblit v1.8.0