demo.txt 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. const positionpoint1 = [Cesium.Cartesian3.fromDegrees(-123.074394,44.050430,0),
  2. Cesium.Cartesian3.fromDegrees(-123.074394,44.050397,0),
  3. Cesium.Cartesian3.fromDegrees(-123.074396,44.050465,0),
  4. Cesium.Cartesian3.fromDegrees(-123.074254,44.050431,0),
  5. Cesium.Cartesian3.fromDegrees(-123.074250,44.050393,0),
  6. Cesium.Cartesian3.fromDegrees(-123.074252,44.050468,0),
  7. Cesium.Cartesian3.fromDegrees(-123.074216,44.050432,0),
  8. Cesium.Cartesian3.fromDegrees(-123.074215,44.050467,0),
  9. Cesium.Cartesian3.fromDegrees(-123.074216,44.050396,0),
  10. Cesium.Cartesian3.fromDegrees(-123.074177,44.050433,0),
  11. Cesium.Cartesian3.fromDegrees(-123.074174,44.050466,0),
  12. Cesium.Cartesian3.fromDegrees(-123.074175,44.050393,0),
  13. Cesium.Cartesian3.fromDegrees(-123.074060,44.050436,0),
  14. Cesium.Cartesian3.fromDegrees(-123.074063,44.050469,0),
  15. Cesium.Cartesian3.fromDegrees(-123.074061,44.050399,0),
  16. Cesium.Cartesian3.fromDegrees(-123.073939,44.050430,0),
  17. Cesium.Cartesian3.fromDegrees(-123.073943,44.050465,0),
  18. Cesium.Cartesian3.fromDegrees(-123.073943,44.050406,0),];
  19. // 点击查询
  20. clickSearch(viewer);
  21. //求路径
  22. function dji(){
  23. var start = Number(jQuery("#start").val())
  24. var end = Number(jQuery("#end").val())
  25. console.log(start,end)
  26. let vertexs = ['0','1', '2', '3', '4', '5', '6', '7','8','9', '10', '11', '12', '13', '14', '15', '16', '17'];
  27. let indexObj = { 0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6,7: 7, 8: 8, 9: 9, 10: 10,
  28. 11: 11, 12: 12, 13: 13,14: 14, 15: 15, 16: 16, 17: 17 };
  29. //边
  30. let edges = ['0_1_1', '0_2_1', '0_3_1', '3_4_1', '3_5_1', '15_16_1', '17_15_1',
  31. '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'];
  32. //邻接矩阵
  33. let vlen = vertexs.length;
  34. let martrix = new Array(vlen);
  35. for (let i = 0; i < vlen; i++) {
  36. martrix[i] = new Array(vlen).fill(10000);
  37. }
  38. //插入边
  39. for (let edge of edges) {
  40. let edgeArr = edge.split('_');
  41. martrix[indexObj[edgeArr[0]]][indexObj[edgeArr[1]]]
  42. = martrix[indexObj[edgeArr[1]]][indexObj[edgeArr[0]]]
  43. = parseInt(edgeArr[2])
  44. }
  45. let graph = new Graph(vertexs, martrix);
  46. // console.log('初始状态:', graph);
  47. graph.dsj(start);
  48. // console.log('结束状态:', graph);
  49. //打印路径和最短距离
  50. let route = [end], pre = end;
  51. console.log(`G点到${end}点的最短距离为:${graph.vv.dis[end]}`);
  52. while (pre !== start) {
  53. pre = graph.vv.pre_visited[pre];
  54. route.unshift(vertexs[pre]);
  55. }
  56. console.log(`G点到${end}点的路径为:${route.join('->')}`);
  57. var path = []
  58. for(var i=0;i<route.length;i++){
  59. path.push(positionpoint1[route[i]])
  60. console.log(path)
  61. }
  62. //绘制路径
  63. var entity = viewer.entities.add({
  64. id:'path',
  65. layerId: "layerId",
  66. // objId: objId,
  67. shapeType: "Polyline",
  68. polyline: {
  69. positions: path,
  70. clampToGround: true,
  71. width: 3,
  72. // material: material
  73. }
  74. })
  75. }
  76. function cl(){
  77. viewer.entities.removeById("path")
  78. console.log("clear")
  79. }
  80. },