2 次代碼提交 bbc31331c5 ... 9f0d6979dd

作者 SHA1 備註 提交日期
  周壕 9f0d6979dd Merge remote-tracking branch 'origin/master' 10 月之前
  周壕 88238cdfcf 地图定位sql 10 月之前
共有 1 個文件被更改,包括 75 次插入99 次删除
  1. 75 99
      src/main/resources/static/a4gis/index.html

+ 75 - 99
src/main/resources/static/a4gis/index.html

@@ -228,7 +228,6 @@
             isMercator: true, // 地图是否采用Mercator坐标系
             mustTile: true // 支持全球连续模式
           });
-        console.log("MapControl",map.MainMap, map);
 
         // 地图参数配置
         mapConfig = {
@@ -281,18 +280,27 @@
 
         map.MainMap.on("load", function (){
           console.log("map.MainMap.on.load",arguments);
-          //添加一个图层,用户坐标点显示
-          if(graLayer==null) {
-            graLayer = new GraphicsLayer();
-            map.MainMap._innerAddLayer(graLayer);
+          //通知父页面,加载完成
+          window.parent.postMessage({action:'test', message:'hello,我即将传给父项目'}, "*");
+        });
 
-            //通知父页面,加载完成
-            window.parent.postMessage({action:'test', message:'hello,我即将传给父项目'}, "*");
+        //创建GraphicsLayer
+        app.graLayer = new GraphicsLayer();
+        map.AddLayer(app.graLayer);
+        app.graLayer.on("mouse-over", function (evt) {
+          map.MainMap.setMapCursor("pointer");
+        });
+        app.graLayer.on("click", function (evt) {
+          console.log('app.graLayer click',evt);
+          if(evt && evt.graphic && evt.graphic.attributes){
+            //map.MainMap.infoWindow.show(evt.graphic.geometry);
+            //map.MainMap.infoWindow.setFeatures(evt.graphic);
+            zoomToCenter(evt.graphic.attributes, false);
+            console.log('app.graLayer click evt.graphic', evt.graphic);
           }
         });
-        map.MainMap.on("click", function (event){
-          //testers.push({x:event.mapPoint2.x, y:event.mapPoint2.y});
-          //console.log("map.MainMap.on.click", JSON.stringify(testers));
+        app.graLayer.on("mouse-out", function (evt) {
+          map.MainMap.setMapCursor("default");
         });
 
         // 图层初始化完成事件
@@ -302,39 +310,13 @@
           // 创建空间引用
           app.sr = new SpatialReference(4326);
 
-          //创建GraphicsLayer
-          app.graLayer = new GraphicsLayer();
-
-          //将GraphicsLayer添加到地图
-          map.AddLayer(app.graLayer);
-
-          //添加一个图层,用户坐标点显示
-          if(graLayer==null) {
-            graLayer = new GraphicsLayer();
-            map.MainMap._innerAddLayer(graLayer);
-
-            //通知父页面,加载完成
-            window.parent.postMessage({action:'test', message:'hello,我即将传给父项目'}, "*");
-          }
+          //通知父页面,加载完成
+          window.parent.postMessage({action:'test', message:'hello,我即将传给父项目'}, "*");
 
           // 地图级别更改事件
           on(map, "MapLevelChanged", function (level) {
             console.log('map1', map.GetLevel());
           });
-          // 鼠标移入事件
-          app.graLayer.on("mouse-over", function (evt) {
-            map.MainMap.setMapCursor("pointer");
-          });
-
-          // 鼠标点击事件
-          app.graLayer.on("click", function (evt) {
-            console.log('e',evt);
-          });
-
-          // 鼠标移出事件
-          app.graLayer.on("mouse-out", function (evt) {
-            map.MainMap.setMapCursor("default");
-          });
 
           // 设置app参数
           app.layer = findLayerByName("地面工程");
@@ -347,8 +329,6 @@
         });
         on(map, "GraphicMouseClick", function (evt) {
           console.log('GraphicMouseClick', evt);
-          // 自定义window方法,vue组件注册,完成vue与iframe的通信,注册方法见baidu-page -> CenterCenter,搜索handleSpanClick
-          //window.parent['handleSpanClick'](evt.name, evt.graphic.attributes);
         });
 
         // 加载地图服务数据
@@ -779,76 +759,72 @@
     var pgs = {};
     var pointObjects = {};
     function setSymbols(points) {
-      graLayer.clear();
-      pgs = {};
-      pointObjects = {};
-
-      require(["esri/geometry/Point", "esri/graphic", "esri/Color", "esri/symbols/SimpleMarkerSymbol", "esri/InfoTemplate"],
-        function (Point, Graphic, Color, SimpleMarkerSymbol, InfoTemplate) {
-          let minx=points[0].x, maxx=points[0].x;
-          let miny=points[0].y, maxy=points[0].y;
-
-          //显示所有标注
-          for(let i=0;i<points.length;i++) {
-            let obj = points[i];
-            if(obj.x==null || obj.x==undefined) continue;
-            if(obj.y==null || obj.y==undefined) continue;
-            obj.x = obj.x *1;
-            obj.y = obj.y *1;
-
-            let point = new Point(obj.x, obj.y, app.sr);
-            let pointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE,
-                    12, null, new Color([255, 0, 0, 1]));
-
-            let template = new InfoTemplate();
-            template.setTitle("<b>${well_id}</b>");
-            template.setContent("井名:${well_common_name}<br>地址:${geo_description}");
-
-            obj.index = i;
-            var pg = new Graphic(point, pointSymbol, obj, template);
-            // 添加图形到GraphicsLayer
-            graLayer.add(pg);
-            pgs[obj.well_id] = pg;
-            pointObjects[obj.well_id] = point;
-
-            if(obj.x < minx) minx = obj.x;
-            if(obj.x > maxx) maxx = obj.x;
-            if(obj.y < miny) miny = obj.y;
-            if(obj.y > maxy) maxy = obj.y;
-          }
-          //地图放大缩小
-          let border = 0.3;
-          console.log("max min", minx, miny, maxx, maxy);
-          minx = minx*1 - border;
-          miny = miny*1 - border;
-          maxx = maxx*1 + border;
-          maxy = maxy*1 + border;
-          console.log("max min", minx, miny, maxx, maxy);
-          map.ZoomToExtent(minx, miny, maxx, maxy);
-        });
-    }
-
-    function clearSymbols(){
-      graLayer.clear();
-      let long = document.getElementById("long").value;
-      let lat = document.getElementById("lat").value;
-      map.ZoomToLevel(9, long, lat);
+      try {
+        app.graLayer.clear();
+        pgs = {};
+        pointObjects = {};
+
+        require(["esri/geometry/Point", "esri/graphic", "esri/Color", "esri/symbols/SimpleMarkerSymbol", "esri/InfoTemplate"],
+                function (Point, Graphic, Color, SimpleMarkerSymbol, InfoTemplate) {
+                  let minx = points[0].x, maxx = points[0].x;
+                  let miny = points[0].y, maxy = points[0].y;
+
+                  //显示所有标注
+                  for (let i = 0; i < points.length; i++) {
+                    let obj = points[i];
+                    if (obj.x == null || obj.x == undefined) continue;
+                    if (obj.y == null || obj.y == undefined) continue;
+                    obj.x = obj.x * 1;
+                    obj.y = obj.y * 1;
+
+                    let point = new Point(obj.x, obj.y, app.sr);
+                    let pointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE,
+                            12, null, new Color([255, 0, 0, 1]));
+
+                    let template = new InfoTemplate();
+                    template.setTitle("<b>${well_id}</b>");
+                    template.setContent("井名:${well_common_name}<br>地址:${geo_description}");
+
+                    obj.index = i;
+                    var pg = new Graphic(point, pointSymbol, obj, template);
+                    // 添加图形到GraphicsLayer
+                    app.graLayer.add(pg);
+                    pgs[obj.well_id] = pg;
+                    pointObjects[obj.well_id] = point;
+
+                    if (obj.x < minx) minx = obj.x;
+                    if (obj.x > maxx) maxx = obj.x;
+                    if (obj.y < miny) miny = obj.y;
+                    if (obj.y > maxy) maxy = obj.y;
+                  }
+                  //地图放大缩小
+                  let border = 0.3;
+                  console.log("max min", minx, miny, maxx, maxy);
+                  minx = minx * 1 - border;
+                  miny = miny * 1 - border;
+                  maxx = maxx * 1 + border;
+                  maxy = maxy * 1 + border;
+                  console.log("max min", minx, miny, maxx, maxy);
+                  map.ZoomToExtent(minx, miny, maxx, maxy);
+                });
+      }
+      catch (ex) {
+        console.log("setSymbolsLayer", mGraLayer, ex);
+      }
     }
 
-    function zoomToCenter(obj){
+    function zoomToCenter(obj, isCenter){
       if(obj.x==null || obj.x==undefined) return;
       if(obj.y==null || obj.y==undefined) return;
       obj.x = obj.x *1;
       obj.y = obj.y *1;
 
-      //map.ZoomToLevel(9, obj.x, obj.y);
-
       if(pointObjects[obj.well_id]) {
         console.log("zoomToCenter",pointObjects[obj.well_id]);
         // 设置弹窗自动显示
         map.MainMap.infoWindow.show(pointObjects[obj.well_id]);
         map.MainMap.infoWindow.setFeatures([pgs[obj.well_id]]);
-        map.MainMap.centerAt(pointObjects[obj.well_id]);
+        if(isCenter) map.MainMap.centerAt(pointObjects[obj.well_id]);
       }
     }
 
@@ -862,7 +838,7 @@
       }
       if(event.data.action=="setCenter"){
         let point = JSON.parse(event.data.item);
-        zoomToCenter(point);
+        zoomToCenter(point, true);
       }
     }, false);
   </script>