我是程序猿

注册

 

发新话题 回复该主题

基于管线的连通性分析研究--广度搜索(JavaScript) [复制链接]

1#
  1. var AnalysisConnection = function (url, tableName, s_expno, e_expno, f_sExp, f_eExp) {
  2.         var FMap = top.Freedom.Map;
  3.         var FSuperMap = top.SuperMap;

  4.         var foundList = [];
  5.         var foundPath = [];
  6.         var connPath = [];
  7.         var waitFind = [];
  8.         var count = 0;
  9.         var isFind = false;
  10.         var maxCount = 1000;

  11.         this.Excute = function () {
  12.             FMap.getTempLayer().removeAllFeatures();
  13.             foundPath = [];
  14.             foundPath = [];
  15.             waitFind = [];
  16.             connPath = [];
  17.             isFind = false;
  18.             maxCount = 1000;
  19.             count = 0;
  20.             foundList.push(s_expno);
  21.             waitFind.push(s_expno);
  22.             findWaitExp();
  23.         };

  24.         function findWaitExp() {
  25.             if (!isFind) {
  26.                 if (waitFind.length > 0) {
  27.                     if (count > maxCount) {
  28.                         if (FMap.queryList.length == 0) {
  29.                             top.$.messager.confirm({
  30.                                 title: '友情提示',
  31.                                 msg: '已经进行了 [' + count + '] 次查询,[' + foundList.length + '] 条记录,可能两个管点不连通!</br>是否继续搜索?',
  32.                                 fn: function (r) {
  33.                                     if (r) {
  34.                                         maxCount = maxCount + 1000;
  35.                                         count++;
  36.                                         findNextExp(waitFind[0]);
  37.                                     }
  38.                                 }
  39.                             });
  40.                         }
  41.                     } else {
  42.                         count++;
  43.                         findNextExp(waitFind[0]);
  44.                     }
  45.                 }
  46.             }
  47.         };

  48.         function checkFinished() {
  49.             if (!isFind && waitFind.length == 0 && FMap.queryList.length == 0) {
  50.                 top.$.messager.alert('友情提示', '系统已经检索完所有连通的管线,两个管点不连通!', 'info');
  51.             } else if (isFind && FMap.queryList.length == 0) {
  52.                 FMap.getTempLayer().removeAllFeatures();
  53.                 redrawPath(foundPath[foundPath.length - 1]);
  54.             }
  55.         }

  56.         function redrawPath(path) {
  57.             connPath.push(path);
  58.             var feature = path.line;
  59.             feature.style = FMap.selstyle;
  60.             FMap.getTempLayer().addFeatures(feature);
  61.             if (path.spoint != s_expno) {
  62.                 var find = null;
  63.                 $.each(foundPath, function (i, item) {
  64.                     if (path.spoint == item.epoint) {
  65.                         find = item;
  66.                         return false;
  67.                     }
  68.                 });
  69.                 if (find) {
  70.                     redrawPath(find);
  71.                 }
  72.             } else {
  73.                 $("#resultDataGrid").datagrid({
  74.                     data: [connPath],
  75.                     columns: [[
  76.                             { field: 'line.attributes.埋设方式', title: 'Code', width: 100 },
  77.                             { field: 'line.attributes.起始点号', title: 'Name', width: 100 },
  78.                             { field: 'line.attributes.终止点号', title: 'Price', width: 100, align: 'right' }
  79.                     ]]
  80.                 });
  81.             }
  82.         };

  83.         function findNextExp(expno) {
  84.             waitFind.splice(0, 1);
  85.             var params = [];
  86.             var param = new FSuperMap.REST.FilterParameter({
  87.                 name: tableName,
  88.                 attributeFilter: f_sExp + "='" + expno + "' or " + f_eExp + "='" + expno + "'"
  89.             });
  90.             params.push(param);
  91.             var SQLParams = new FSuperMap.REST.QueryBySQLParameters({
  92.                 queryParams: params
  93.             });
  94.             FMap.queryBySQL(url, SQLParams, function (e) {
  95.                 if (e.result.currentCount > 0 && e.result.recordsets.length == 1 && !isFind) {
  96.                     var fs = e.result.recordsets[0].features;
  97.                     $.each(fs, function (i, item) {
  98.                         var sexpno = item.attributes[f_sExp], eexpno = item.attributes[f_eExp];
  99.                         if (foundList.indexOf(sexpno) == -1 && !isFind) {//表示找到的点不在已经找到的列表里,则继续向下查找
  100.                             foundList.push(sexpno)
  101.                             waitFind.push(sexpno);

  102.                             var path = {
  103.                                 spoint: expno,
  104.                                 epoint: sexpno,
  105.                                 line: item
  106.                             };
  107.                             foundPath.push(path);

  108.                             var feature = item;
  109.                             feature.style = FMap.selstyle;
  110.                             FMap.getTempLayer().addFeatures(feature);

  111.                             if (sexpno == e_expno) {
  112.                                 isFind = true;
  113.                                 //FMap.getTempLayer().removeAllFeatures();
  114.                                 //redrawPath(path);
  115.                             } else {
  116.                                 findWaitExp();
  117.                             }
  118.                         } else if (foundList.indexOf(eexpno) == -1 && !isFind) {//表示找到的点不在已经找到的列表里,则继续向下查找
  119.                             foundList.push(eexpno)
  120.                             waitFind.push(eexpno);

  121.                             var path = {
  122.                                 spoint: expno,
  123.                                 epoint: eexpno,
  124.                                 line: item
  125.                             };
  126.                             foundPath.push(path);

  127.                             var feature = item;
  128.                             feature.style = FMap.selstyle;
  129.                             FMap.getTempLayer().addFeatures(feature);

  130.                             if (eexpno == e_expno) {
  131.                                 isFind = true;
  132.                                 //FMap.getTempLayer().removeAllFeatures();
  133.                                 //redrawPath(path);
  134.                             } else {
  135.                                 findWaitExp();
  136.                             }
  137.                         }
  138.                     });
  139.                 }
  140.                 checkFinished();
  141.             }, function (e) {
  142.                 var d = e;
  143.             });
  144.         }
  145.     };
复制代码
分享 转发
TOP
发新话题 回复该主题