侧边栏壁纸
博主头像
johnliu博主等级

远离世上乱纷纷,清静凡心不染尘。 闲看山前腾紫气,静观天外涌祥云。 花间酌酒邀明月,柳下吟诗论古今。 坐卧随心天地近,悠然细品玉堂春。

  • 累计撰写 35 篇文章
  • 累计创建 10 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

基于管线的连通性分析研究--广度搜索(JavaScript)

冰灬夏
2019-07-30 / 0 评论 / 0 点赞 / 13 阅读 / 6341 字
温馨提示:
本文最后更新于 2024-05-27,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。
var AnalysisConnection = function (url, tableName, s_expno, e_expno, f_sExp, f_eExp) {
        var FMap = top.Freedom.Map;
        var FSuperMap = top.SuperMap;

        var foundList = [];
        var foundPath = [];
        var connPath = [];
        var waitFind = [];
        var count = 0;
        var isFind = false;
        var maxCount = 1000;

        this.Excute = function () {
            FMap.getTempLayer().removeAllFeatures();
            foundPath = [];
            foundPath = [];
            waitFind = [];
            connPath = [];
            isFind = false;
            maxCount = 1000;
            count = 0;
            foundList.push(s_expno);
            waitFind.push(s_expno);
            findWaitExp();
        };

        function findWaitExp() {
            if (!isFind) {
                if (waitFind.length > 0) {
                    if (count > maxCount) {
                        if (FMap.queryList.length == 0) {
                            top.$.messager.confirm({
                                title: '友情提示',
                                msg: '已经进行了 [' + count + '] 次查询,[' + foundList.length + '] 条记录,可能两个管点不连通!</br>是否继续搜索?',
                                fn: function (r) {
                                    if (r) {
                                        maxCount = maxCount + 1000;
                                        count++;
                                        findNextExp(waitFind[0]);
                                    }
                                }
                            });
                        }
                    } else {
                        count++;
                        findNextExp(waitFind[0]);
                    }
                }
            }
        };

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

        function redrawPath(path) {
            connPath.push(path);
            var feature = path.line;
            feature.style = FMap.selstyle;
            FMap.getTempLayer().addFeatures(feature);
            if (path.spoint != s_expno) {
                var find = null;
                $.each(foundPath, function (i, item) {
                    if (path.spoint == item.epoint) {
                        find = item;
                        return false;
                    }
                });
                if (find) {
                    redrawPath(find);
                }
            } else {
                $("#resultDataGrid").datagrid({
                    data: [connPath],
                    columns: [[
                            { field: 'line.attributes.埋设方式', title: 'Code', width: 100 },
                            { field: 'line.attributes.起始点号', title: 'Name', width: 100 },
                            { field: 'line.attributes.终止点号', title: 'Price', width: 100, align: 'right' }
                    ]]
                });
            }
        };

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

                            var path = {
                                spoint: expno,
                                epoint: sexpno,
                                line: item
                            };
                            foundPath.push(path);

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

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

                            var path = {
                                spoint: expno,
                                epoint: eexpno,
                                line: item
                            };
                            foundPath.push(path);

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

                            if (eexpno == e_expno) {
                                isFind = true;
                                //FMap.getTempLayer().removeAllFeatures();
                                //redrawPath(path);
                            } else {
                                findWaitExp();
                            }
                        }
                    });
                }
                checkFinished();
            }, function (e) {
                var d = e;
            });
        }
    };

0

评论区