|
@@ -0,0 +1,94 @@
|
|
|
+
|
|
|
+ const positionpoint1 = [Cesium.Cartesian3.fromDegrees(-123.074394,44.050430,0),
|
|
|
+ Cesium.Cartesian3.fromDegrees(-123.074394,44.050397,0),
|
|
|
+ Cesium.Cartesian3.fromDegrees(-123.074396,44.050465,0),
|
|
|
+ Cesium.Cartesian3.fromDegrees(-123.074254,44.050431,0),
|
|
|
+ Cesium.Cartesian3.fromDegrees(-123.074250,44.050393,0),
|
|
|
+ Cesium.Cartesian3.fromDegrees(-123.074252,44.050468,0),
|
|
|
+ Cesium.Cartesian3.fromDegrees(-123.074216,44.050432,0),
|
|
|
+ Cesium.Cartesian3.fromDegrees(-123.074215,44.050467,0),
|
|
|
+ Cesium.Cartesian3.fromDegrees(-123.074216,44.050396,0),
|
|
|
+ Cesium.Cartesian3.fromDegrees(-123.074177,44.050433,0),
|
|
|
+ Cesium.Cartesian3.fromDegrees(-123.074174,44.050466,0),
|
|
|
+ Cesium.Cartesian3.fromDegrees(-123.074175,44.050393,0),
|
|
|
+ Cesium.Cartesian3.fromDegrees(-123.074060,44.050436,0),
|
|
|
+ Cesium.Cartesian3.fromDegrees(-123.074063,44.050469,0),
|
|
|
+ Cesium.Cartesian3.fromDegrees(-123.074061,44.050399,0),
|
|
|
+ Cesium.Cartesian3.fromDegrees(-123.073939,44.050430,0),
|
|
|
+ Cesium.Cartesian3.fromDegrees(-123.073943,44.050465,0),
|
|
|
+ Cesium.Cartesian3.fromDegrees(-123.073943,44.050406,0),];
|
|
|
+
|
|
|
+
|
|
|
+// 点击查询
|
|
|
+clickSearch(viewer);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //求路径
|
|
|
+ function dji(){
|
|
|
+ var start = Number(jQuery("#start").val())
|
|
|
+ var end = Number(jQuery("#end").val())
|
|
|
+ console.log(start,end)
|
|
|
+
|
|
|
+ let vertexs = ['0','1', '2', '3', '4', '5', '6', '7','8','9', '10', '11', '12', '13', '14', '15', '16', '17'];
|
|
|
+ let indexObj = { 0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6,7: 7, 8: 8, 9: 9, 10: 10,
|
|
|
+ 11: 11, 12: 12, 13: 13,14: 14, 15: 15, 16: 16, 17: 17 };
|
|
|
+ //边
|
|
|
+ let edges = ['0_1_1', '0_2_1', '0_3_1', '3_4_1', '3_5_1', '15_16_1', '17_15_1',
|
|
|
+ '3_6_1', '6_9_1', '9_12_1', '12_15_1', '6_7_1','8_6_1', '10_9_1', '9_11_1', '12_13_1', '12_14_1'];
|
|
|
+ //邻接矩阵
|
|
|
+ let vlen = vertexs.length;
|
|
|
+ let martrix = new Array(vlen);
|
|
|
+ for (let i = 0; i < vlen; i++) {
|
|
|
+ martrix[i] = new Array(vlen).fill(10000);
|
|
|
+ }
|
|
|
+ //插入边
|
|
|
+ for (let edge of edges) {
|
|
|
+ let edgeArr = edge.split('_');
|
|
|
+ martrix[indexObj[edgeArr[0]]][indexObj[edgeArr[1]]]
|
|
|
+ = martrix[indexObj[edgeArr[1]]][indexObj[edgeArr[0]]]
|
|
|
+ = parseInt(edgeArr[2])
|
|
|
+ }
|
|
|
+
|
|
|
+ let graph = new Graph(vertexs, martrix);
|
|
|
+ // console.log('初始状态:', graph);
|
|
|
+ graph.dsj(start);
|
|
|
+ // console.log('结束状态:', graph);
|
|
|
+ //打印路径和最短距离
|
|
|
+
|
|
|
+ let route = [end], pre = end;
|
|
|
+ console.log(`G点到${end}点的最短距离为:${graph.vv.dis[end]}`);
|
|
|
+ while (pre !== start) {
|
|
|
+ pre = graph.vv.pre_visited[pre];
|
|
|
+ route.unshift(vertexs[pre]);
|
|
|
+ }
|
|
|
+ console.log(`G点到${end}点的路径为:${route.join('->')}`);
|
|
|
+
|
|
|
+ var path = []
|
|
|
+ for(var i=0;i<route.length;i++){
|
|
|
+ path.push(positionpoint1[route[i]])
|
|
|
+ console.log(path)
|
|
|
+ }
|
|
|
+
|
|
|
+ //绘制路径
|
|
|
+ var entity = viewer.entities.add({
|
|
|
+ id:'path',
|
|
|
+ layerId: "layerId",
|
|
|
+ // objId: objId,
|
|
|
+ shapeType: "Polyline",
|
|
|
+ polyline: {
|
|
|
+ positions: path,
|
|
|
+ clampToGround: true,
|
|
|
+ width: 3,
|
|
|
+ // material: material
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ function cl(){
|
|
|
+ viewer.entities.removeById("path")
|
|
|
+ console.log("clear")
|
|
|
+ }
|
|
|
+ },
|