Browse Source

地图级别修改

laiguoran 3 years ago
parent
commit
649190dacc
2 changed files with 28 additions and 12 deletions
  1. 27 11
      app/view/tender/detail.ejs
  2. 1 1
      app/view/tender/detail_modal.ejs

+ 27 - 11
app/view/tender/detail.ejs

@@ -1325,22 +1325,38 @@
                     centerPoint.lat = _.round(center.geometry.coordinates[1], 4);
                 }
                 // 地图级别计算
-                for (const c of pointList) {
-                    const distance = turf.distance(c, turf.point([centerPoint.lng, centerPoint.lat]));
-                    if (distance > maxDistance) {
-                        maxDistance = distance;
+                if (pointList.length === 1) {
+                    // 只有一条路线
+                    const map_json = JSON.parse(unescape(escape(tenderMapList[0].map_json)));
+                    for (const mj of map_json) {
+                        const distance = turf.distance(turf.point([mj.lng, mj.lat]), turf.point([centerPoint.lng, centerPoint.lat]));
+                        if (distance > maxDistance) {
+                            maxDistance = distance;
+                        }
+                    }
+                } else {
+                    for (const c of pointList) {
+                        const distance = turf.distance(c, turf.point([centerPoint.lng, centerPoint.lat]));
+                        if (distance > maxDistance) {
+                            maxDistance = distance;
+                        }
                     }
                 }
+                if (maxDistance === 0) {
+                    level = 15;
+                } else {
+                    // 级别区间
+                    // const range = [0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 25, 50, 100, 200, 500, 1000, 2000, 5000, 10000];
+                    const range = [10000, 5000, 2000, 1000, 500, 200, 100, 50, 25, 20, 10, 5, 2, 1, 0.5, 0.2, 0.1, 0.05, 0.02];
+                    level = _.findIndex(range, function (item) {
+                        return item <= maxDistance;
+                    })
+                    level = level + 1;
+                }
                 const result = gcoord.transform([centerPoint.lng, centerPoint.lat], gcoord.WGS84, gcoord.BD09);
                 centerPoint.lng = result[0];
                 centerPoint.lat = result[1];
-                // 级别区间
-                // const range = [0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 25, 50, 100, 200, 500, 1000, 2000, 5000, 10000];
-                const range = [10000, 5000, 2000, 1000, 500, 200, 100, 50, 25, 20, 10, 5, 2, 1, 0.5, 0.2, 0.1, 0.05, 0.02];
-                level = _.findIndex(range, function (item) {
-                    return item <= maxDistance;
-                })
-                level = level + 1;
+
             }
             // 初始化地图,设置中心点坐标和地图级别
             const point = new BMapGL.Point(centerPoint.lng, centerPoint.lat);

+ 1 - 1
app/view/tender/detail_modal.ejs

@@ -2198,9 +2198,9 @@
             const mapInfo = _.find(tenderMapList, { id });
             $('#map-name').val(mapInfo.name);
             $('#map-tips').val(mapInfo.tips);
+            $('#map-color-select').colorpicker("setValue", mapInfo.color);
             $('#map-color').val(mapInfo.color);
             $('#map-color').attr('value', mapInfo.color);
-            $('#map-color-select').colorpicker("setValue", mapInfo.color);
             SpreadJsObj.loadSheetData(mapSpread.getActiveSheet(), SpreadJsObj.DataType.Data, (mapInfo.map_json ? JSON.parse(unescape(escape(mapInfo.map_json))) : []));
         });
         const xPattern = /^-?(\d{1,2}(\.\d{1,8})?|1[0-7]\d(\.\d{1,8})?|180)$/;