From 824dece6f25bd50b53146463f856169aff6840b9 Mon Sep 17 00:00:00 2001
From: zengh <123456>
Date: Fri, 13 Nov 2020 15:35:42 +0800
Subject: [PATCH] 剖面分析集成

---
 widgets/MapSection/Widget.js       |  209 ----------------------
 widgets/MapSection/Widget1.js      |  276 ++++++++++++++++++++++++++++++
 widgets/MapSection/css/style.css   |    9 +
 widgets/MapSection/SectionChart.js |    4 
 4 files changed, 291 insertions(+), 207 deletions(-)

diff --git a/widgets/MapSection/SectionChart.js b/widgets/MapSection/SectionChart.js
index d2087cb..5b46558 100644
--- a/widgets/MapSection/SectionChart.js
+++ b/widgets/MapSection/SectionChart.js
@@ -15,6 +15,7 @@
     ],
     function (declare, lang, html, _WidgetBase, _TemplatedMixin,
               on, mouse, query, xhr, topic, JSON,domConstruct,echarts) {
+
         return declare([_WidgetBase, _TemplatedMixin], {
 
             templateString: '<div style="width:100%;height:100%;"><div   style="width:100%;height:100%;" >' +
@@ -80,10 +81,9 @@
             	
             },
             isResize:true,
-            postCreate: function () { 
+            postCreate: function () {
             	this.inherited(arguments);
             	this.query();
-            	
             	this.step = 0;
             	var lg = this.GetDistance(this.oList[0].lttd,this.oList[0].lgtd,this.oList[99].lttd,this.oList[99].lgtd);
             	this.step = lg/99;
diff --git a/widgets/MapSection/Widget.js b/widgets/MapSection/Widget.js
index a16643a..ebfce20 100644
--- a/widgets/MapSection/Widget.js
+++ b/widgets/MapSection/Widget.js
@@ -29,229 +29,28 @@
 ){
     return declare("MapSection", [BaseWidget],{
         baseClass:"demo-widgets-MapSection",
-        postCreate:function(){ 
-            this.inherited(arguments);
-         
-            this._tooltip = this.createTooltip(this.map.cesiumWidget.container);
-        },
-        createTooltip: function (frameDiv) {
-
-            var tooltip = function(frameDiv) {
-
-                var div = document.createElement('DIV');
-                div.className = "twipsy right";
-
-                var arrow = document.createElement('DIV');
-                arrow.className = "twipsy-arrow";
-                div.appendChild(arrow);
-
-                var title = document.createElement('DIV');
-                title.className = "twipsy-inner";
-                div.appendChild(title);
-
-                this._div = div;
-                this._title = title;
-
-                // add to frame div and display coordinates
-                frameDiv.appendChild(div);
-            }
-
-            tooltip.prototype.setVisible = function(visible) {
-                this._div.style.display = visible ? 'block' : 'none';
-            }
-
-            tooltip.prototype.showAt = function(position, message) {
-                if(position && message) {
-                    this.setVisible(true);
-                    this._title.innerHTML = message;
-                    this._div.style.left = position.x + 10 + "px";
-                    this._div.style.top = (position.y - this._div.clientHeight / 2) + "px";
-                }
-            }
-
-            return new tooltip(frameDiv);
-        },
         destroy:function(){
-
             this.inherited(arguments);
         },
-        // click:function(){
-        //     this.active = !this.active;
-        //     if(this.active){
-        //         this._tooltip.setVisible(true);
-        //     }else{
-        //         this._tooltip.setVisible(false);
-        //     }
-        //     this.clearEntity();
-        // },
         onOpen: function () {
             this.map.scene.globe.baseColor = Cesium.Color.BLACK;
             $($('div.cesium-viewer').find('.cesium-baseLayerPicker-choices')[0]).children('div:eq(3)').trigger('click');
             this.active = true;
-            this.clearEntity();
-            this._tooltip.setVisible(true);
-
-
         },
         onClose: function () {
             this.active = false;
             this.clearEntity();
-            this._tooltip.setVisible(false); },
-        active:false,
+            this._tooltip.setVisible(false);
+            },
         startup:function(){
             this.inherited(arguments);
+            var pm = new DC.mapSection(window.dcViewer,Popup,SectionChart);
 
-            var handler = new Cesium.ScreenSpaceEventHandler(window.viewer.scene.canvas);
-
-            handler.setInputAction(
-                lang.hitch(this,function (movement) {
-                    if(!this.active)return;
-                    var ellipsoid = window.viewer.scene.globe.ellipsoid;
-                    var ellipsoid = Cesium.Ellipsoid.WGS84;
-//	            	var cartesian = window.viewer.scene.camera.pickEllipsoid(movement.position, ellipsoid);//两种的经纬度获取的不一样
-                    var pickRay = window.viewer.scene.camera.getPickRay(movement.position);
-                    var cartesian = window.viewer.scene.globe.pick(pickRay, window.viewer.scene);
-
-                    if (cartesian) {
-
-                        var cartographic = ellipsoid.cartesianToCartographic(cartesian);
-                        var longitudeString = Cesium.Math.toDegrees(cartographic.longitude);//.toFixed(2);
-                        var latitudeString = Cesium.Math.toDegrees(cartographic.latitude);//.toFixed(2);
-
-                        this.points.push({"lgtd":longitudeString,"lttd":latitudeString});
-
-                        if(this.points.length==2){
-                            //计算
-                            var points = this.createHundryPoints(this.points);
-                            //弹出
-                            this.getData(points);
-                            this.points = [];
-                            this.active = false;
-                            this._tooltip.setVisible(false);
-                            this.bill2 = window.viewer.entities.add({
-                                position : Cesium.Cartesian3.fromDegrees(longitudeString, latitudeString ),
-                                billboard : {
-                                    image : "images/marker_green.png",
-                                    pixelOffset: new Cesium.Cartesian2(0, 0),
-                                    heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
-                                    disableDepthTestDistance: Number.POSITIVE_INFINITY
-                                }
-                            });
-                            return;
-                        }
-                        this.bill1 = window.viewer.entities.add({
-                            position : Cesium.Cartesian3.fromDegrees(longitudeString, latitudeString ),
-                            billboard : {
-                                image : "images/marker_green.png",
-                                pixelOffset: new Cesium.Cartesian2(0, 0),
-                                heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
-                                disableDepthTestDistance: Number.POSITIVE_INFINITY
-                            }
-                        });
-                    }
-
-                }), Cesium.ScreenSpaceEventType.LEFT_CLICK);
-
-            handler.setInputAction(
-                lang.hitch(this,function (movement) {
-                    if(!this.active)return;
-                    if(this.points.length==0){
-                        this._tooltip.showAt(movement.endPosition, "请获取起点");
-                        return;
-                    }
-                    this._tooltip.showAt(movement.endPosition, "点击结束");
-
-                }), Cesium.ScreenSpaceEventType.MOUSE_MOVE);
         },
-        clearEntity:function(){
+        clearEntity: function () {
             window.viewer.entities.remove(this.bill1);
             window.viewer.entities.remove(this.bill2);
             window.viewer.entities.remove(this.line);
         },
-        createHundryPoints:function(list){
-
-            var lgtd1 = list[0].lgtd;
-            var lgtd100 = list[1].lgtd;
-            var lgtdStep = (lgtd100-lgtd1)/1000;
-
-            var lttd1 = list[0].lttd;
-            var lttd100 = list[1].lttd;
-            var lttdStep = (lttd100-lttd1)/1000;
-            var ary = [];
-            for(var i=0;i<1000;i++){
-                var lgtd = lgtd1 +(lgtdStep*i);
-                var lttd = lttd1 +(lttdStep*i);
-                ary.push({"id":i,"lgtd":lgtd,"lttd":lttd});
-            }
-
-            return ary;
-        },
-        points:[],
-        getData:function(ary){
-            var mappints = [];
-            for(var j=0;j<ary.length;j++){
-                var pt = ary[j];
-                mappints.push({lgtd:pt.lgtd,lttd:pt.lttd,height:0});
-            }
-            //获取高程去
-            this.makeChange(mappints).then(lang.hitch(this,function(list){
-                var ptsAry = [];
-                var numbers_lgtd=[];
-                var numbers_lttd=[];
-                for(var j=0;j<list.length;j++){
-                    var pt = list[j];
-                    ptsAry.push(Number(pt.lgtd));
-                    ptsAry.push(Number(pt.lttd));
-                    ptsAry.push(Number(pt.height));
-
-                    numbers_lgtd.push(Number(pt.lgtd));
-                    numbers_lttd.push(Number(pt.lttd));
-                }
-
-
-                this.line = window.viewer.entities.add({
-                    polyline : {
-                        positions : Cesium.Cartesian3.fromDegreesArrayHeights(ptsAry),
-                        width : 3,
-                        material : new Cesium.PolylineOutlineMaterialProperty({
-                            color : Cesium.Color.ORANGE,
-                            outlineWidth : 1,
-                            outlineColor : Cesium.Color.BLACK
-                        }),
-                        clampToGround: true
-                    }
-                });
-
-                var panel = new SectionChart({list:ptsAry,oList:list});
-                new Popup({
-                    content: panel,
-                    titleLabel: "地形剖面图",
-                    width: 650,
-                    height: 370,
-                    buttons: [],
-                    onClose:lang.hitch(this,function(){
-                        return true;
-                    })
-                });
-            }));
-        },
-        makeChange:function(datas){
-            var datas = datas;
-            var def = new Deferred();
-            var tIds = [];
-            var pos = [];
-            for(var i=0;i<datas.length;i++){
-                var item = datas[i];
-                tIds.push(item.id);
-                pos.push(Cesium.Cartographic.fromDegrees(item.lgtd, item.lttd));
-            }
-            Cesium.sampleTerrain(window.viewer.terrainProvider, 9, pos).then(function (pos) {//去获取高程
-                for (var i=0; i<tIds.length; i++) {
-                    datas[i].height =   pos[i].height;
-                }
-                def.resolve(datas);
-            });
-            return def;
-        }
     });
 });
\ No newline at end of file
diff --git a/widgets/MapSection/Widget1.js b/widgets/MapSection/Widget1.js
new file mode 100644
index 0000000..335a7be
--- /dev/null
+++ b/widgets/MapSection/Widget1.js
@@ -0,0 +1,276 @@
+///////////////////////////////////////////////////////////////////////////
+// Copyright © 2018 NarutoGIS. All Rights Reserved.
+// 模块描述:获取两点间地形剖面
+///////////////////////////////////////////////////////////////////////////
+define([
+    "dojo/_base/declare",
+    "dojo/_base/lang",
+    'dojo/_base/html',
+    "dojo/_base/fx",
+    'jimu/BaseWidget',
+    "dojo/topic",
+    "dojo/Deferred",
+    "dojo/on",
+    'jimu/dijit/Popup',
+    "./SectionChart"
+
+], function (
+    declare,
+    lang,
+    html,
+    fx,
+    BaseWidget,
+    topic,
+    Deferred,
+    on,
+    Popup,
+    SectionChart
+) {
+    return declare("MapSection", [BaseWidget], {
+        baseClass: "demo-widgets-MapSection",
+        postCreate: function () {
+            this.inherited(arguments);
+            this._tooltip = this.createTooltip(this.map.cesiumWidget.container);
+        },
+        createTooltip: function (frameDiv) {
+
+            var tooltip = function (frameDiv) {
+                var div = document.createElement('DIV');
+                div.className = "twipsy right";
+
+                var arrow = document.createElement('DIV');
+                arrow.className = "twipsy-arrow";
+                div.appendChild(arrow);
+
+                var title = document.createElement('DIV');
+                title.className = "twipsy-inner";
+                div.appendChild(title);
+
+                this._div = div;
+                this._title = title;
+
+                // add to frame div and display coordinates
+                frameDiv.appendChild(div);
+            }
+
+            tooltip.prototype.setVisible = function (visible) {
+                this._div.style.display = visible ? 'block' : 'none';
+            }
+
+            tooltip.prototype.showAt = function (position, message) {
+                if (position && message) {
+                    this.setVisible(true);
+                    this._title.innerHTML = message;
+                    this._div.style.left = position.x + 10 + "px";
+                    this._div.style.top = (position.y - this._div.clientHeight / 2) + "px";
+                }
+            }
+
+            return new tooltip(frameDiv);
+        },
+        destroy: function () {
+
+            this.inherited(arguments);
+        },
+        // click:function(){
+        //     this.active = !this.active;
+        //     if(this.active){
+        //         this._tooltip.setVisible(true);
+        //     }else{
+        //         this._tooltip.setVisible(false);
+        //     }
+        //     this.clearEntity();
+        // },
+        onOpen: function () {
+            this.map.scene.globe.baseColor = Cesium.Color.BLACK;
+            $($('div.cesium-viewer').find('.cesium-baseLayerPicker-choices')[0]).children('div:eq(3)').trigger('click');
+            this.active = true;
+            this.clearEntity();
+            this._tooltip.setVisible(true);
+
+
+        },
+        onClose: function () {
+            this.active = false;
+            this.clearEntity();
+            this._tooltip.setVisible(false);
+        },
+        active: false,
+        startup: function () {
+
+            this.inherited(arguments);
+
+            var handler = new Cesium.ScreenSpaceEventHandler(window.viewer.scene.canvas);
+
+            handler.setInputAction(
+                lang.hitch(this, function (movement) {
+                    if (!this.active) return;
+                    var ellipsoid = window.viewer.scene.globe.ellipsoid;
+                    var ellipsoid = Cesium.Ellipsoid.WGS84;
+//	            	var cartesian = window.viewer.scene.camera.pickEllipsoid(movement.position, ellipsoid);//两种的经纬度获取的不一样
+                    var pickRay = window.viewer.scene.camera.getPickRay(movement.position);
+                    var cartesian = window.viewer.scene.globe.pick(pickRay, window.viewer.scene);
+
+                    if (cartesian) {
+
+                        var cartographic = ellipsoid.cartesianToCartographic(cartesian);
+                        var longitudeString = Cesium.Math.toDegrees(cartographic.longitude);//.toFixed(2);
+                        var latitudeString = Cesium.Math.toDegrees(cartographic.latitude);//.toFixed(2);
+
+                        this.points.push({"lgtd": longitudeString, "lttd": latitudeString});
+
+                        if (this.points.length == 2) {
+                            //计算
+                            var points = this.createHundryPoints(this.points);
+                            //弹出
+                            this.getData(points);
+                            this.points = [];
+                            this.active = false;
+                            this._tooltip.setVisible(false);
+                            this.bill2 = window.viewer.entities.add({
+                                position: Cesium.Cartesian3.fromDegrees(longitudeString, latitudeString),
+                                billboard: {
+                                    image: "images/marker_green.png",
+                                    pixelOffset: new Cesium.Cartesian2(0, 0),
+                                    heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
+                                    disableDepthTestDistance: Number.POSITIVE_INFINITY
+                                }
+                            });
+                            return;
+                        }
+                        this.bill1 = window.viewer.entities.add({
+                            position: Cesium.Cartesian3.fromDegrees(longitudeString, latitudeString),
+                            billboard: {
+                                image: "images/marker_green.png",
+                                pixelOffset: new Cesium.Cartesian2(0, 0),
+                                heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
+                                disableDepthTestDistance: Number.POSITIVE_INFINITY
+                            }
+                        });
+                    }
+
+                }), Cesium.ScreenSpaceEventType.LEFT_CLICK);
+
+            handler.setInputAction(
+                lang.hitch(this, function (movement) {
+                    if (!this.active) return;
+                    if (this.points.length == 0) {
+                        this._tooltip.showAt(movement.endPosition, "请获取起点");
+                        return;
+                    }
+                    this._tooltip.showAt(movement.endPosition, "点击结束");
+
+                }), Cesium.ScreenSpaceEventType.MOUSE_MOVE);
+        },
+        clearEntity: function () {
+            window.viewer.entities.remove(this.bill1);
+            window.viewer.entities.remove(this.bill2);
+            window.viewer.entities.remove(this.line);
+        },
+        createHundryPoints: function (list) {
+
+            var lgtd1 = list[0].lgtd;
+            var lgtd100 = list[1].lgtd;
+            var lgtdStep = (lgtd100 - lgtd1) / 1000;
+
+            var lttd1 = list[0].lttd;
+            var lttd100 = list[1].lttd;
+            var lttdStep = (lttd100 - lttd1) / 1000;
+            var ary = [];
+            for (var i = 0; i < 1000; i++) {
+                var lgtd = lgtd1 + (lgtdStep * i);
+                var lttd = lttd1 + (lttdStep * i);
+                ary.push({"id": i, "lgtd": lgtd, "lttd": lttd});
+            }
+
+            return ary;
+        },
+        points: [],
+        getData: function (ary) {
+            var mappints = [];
+            for (var j = 0; j < ary.length; j++) {
+                var pt = ary[j];
+                mappints.push({lgtd: pt.lgtd, lttd: pt.lttd, height: 0});
+            }
+            //获取高程去
+
+            var datas = mappints;
+            var tIds = [];
+            var pos = [];
+            for (var i = 0; i < datas.length; i++) {
+                var item = datas[i];
+                tIds.push(item.id);
+                pos.push(Cesium.Cartographic.fromDegrees(item.lgtd, item.lttd));
+            }
+
+            Cesium.sampleTerrain(window.viewer.terrainProvider, 9, pos).then(function (pos) {//去获取高程
+                for (var i = 0; i < tIds.length; i++) {
+                    datas[i].height = pos[i].height;
+                }
+
+                var list = datas;
+
+                var ptsAry = [];
+                var numbers_lgtd = [];
+                var numbers_lttd = [];
+                for (var j = 0; j < list.length; j++) {
+                    var pt = list[j];
+                    ptsAry.push(Number(pt.lgtd));
+                    ptsAry.push(Number(pt.lttd));
+                    ptsAry.push(Number(pt.height));
+
+                    numbers_lgtd.push(Number(pt.lgtd));
+                    numbers_lttd.push(Number(pt.lttd));
+                }
+
+
+                this.line = window.viewer.entities.add({
+                    polyline: {
+                        positions: Cesium.Cartesian3.fromDegreesArrayHeights(ptsAry),
+                        width: 3,
+                        material: new Cesium.PolylineOutlineMaterialProperty({
+                            color: Cesium.Color.ORANGE,
+                            outlineWidth: 1,
+                            outlineColor: Cesium.Color.BLACK
+                        }),
+                        clampToGround: true
+                    }
+                });
+
+                var panel = new SectionChart({list: ptsAry, oList: list});
+                new Popup({
+                    content: panel,
+                    titleLabel: "地形剖面图",
+                    width: 650,
+                    height: 370,
+                    buttons: [],
+                    onClose: lang.hitch(this, function () {
+                        return true;
+                    })
+                });
+
+            });
+
+        },
+        makeChange: function (datas) {
+            var datas = datas;
+            var def = new Deferred();
+            var tIds = [];
+            var pos = [];
+            for (var i = 0; i < datas.length; i++) {
+                var item = datas[i];
+                tIds.push(item.id);
+                pos.push(Cesium.Cartographic.fromDegrees(item.lgtd, item.lttd));
+            }
+
+            Cesium.sampleTerrain(window.viewer.terrainProvider, 9, pos).then(function (pos) {//去获取高程
+                for (var i = 0; i < tIds.length; i++) {
+                    datas[i].height = pos[i].height;
+                }
+                def.resolve(datas);
+            });
+
+            return def;
+        }
+    });
+});
\ No newline at end of file
diff --git a/widgets/MapSection/css/style.css b/widgets/MapSection/css/style.css
index aa79949..54325ad 100644
--- a/widgets/MapSection/css/style.css
+++ b/widgets/MapSection/css/style.css
@@ -9,6 +9,15 @@
   padding: 1px;
 }
 
+.jimu-popup .title {
+  position: absolute;
+  top: 0;
+  left: -10px;
+  width: 100%;
+  background: #094895;
+  color: #fff;
+}
+
 .twipsy {
   display: block;
   position: absolute;

--
Gitblit v1.9.3