ansel0926
2022-05-17 20f5203f80444254892012e87e1672f2bc6001db
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//根据id获取单个建筑物
function getBuildingById(id){
    $.ajax({
        type : "post",
        url : "../../easyAPI/building/getBuildingById.action",
        data : "buildingId="+id,
        success : function(data) {
            if (data.length != 0) {
                showInfoBuilding_3D(data);
                showBuildingById(data);
            }else{
                swal("获取建筑物信息为空!","请重试!","error");
            }
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            console.log("ajax请求失败!","请重试!","error");
        }
    });
}
var buildingData;
function getBuildingAll(){
    $.ajax({
        type : "post",
        url : "../../easyAPI/building/getBuilding.action",
        contentType : "charset=utf-8",
        success : function(data) {
            buildingData = data;
            showBuildingAll(data);
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            console.log("ajax请求失败!","请重试!","error");
        }
    });
}
//条件查询建筑物信息
function queryBuilding(queryData) {
    var args = JSON.stringify(queryData);
    $.ajax({
        type : "post",
        url : "../../easyAPI/building/queryBuilding.action",
        data : args,
        contentType : "application/json;charset=utf-8",
        success : function(data) {
            if (data.length != 0) {
                showQueryBuilding(data);
            }else{
                console.log("获取建筑物信息为空!");
            }
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            console.log("条件查询建筑物信息失败!");
        }
    });
}
//上传方法
var jsonfullFileName;
function checkUpFile(){
    var acceptFile = ".shp||.dbf||.prj||.sbn||.sbx||.xml||.shx";
    var fileArr = file.files;
    var urlStr = randomString(15);
    for (var i = 0; i < fileArr.length; i++) {
        var filePath = fileArr[i].name;
        var ext = filePath.substring(filePath.lastIndexOf(".")).toLowerCase();
        if (acceptFile.indexOf(ext)!=-1) {
            var fileSize = 0;
            var fileMaxSize = 1024*500;//500M
            if(filePath){
                fileSize = fileArr[i].size;
                var size = fileSize / 1024;
                if (size > fileMaxSize) {
                    swal("文件大小不能大于500M!","请重新选择文件!","error");
                    file.value = "";
                }else if (size <= 0) {
                    swal("文件大小不能为0M!","请重新选择文件!","error");
                    file.value = "";
                }else{
                    var fileObj = document.getElementById("file").files[i]; // js 获取文件对象
                    var FileController = "../../easyAPI/uploadFile/uploadshp.action";// 接收上传文件的后台地址 
                    jsonfullFileName = urlStr + ext;
                    // FormData 对象
                    var form = new FormData();
                    form.append("fileName", urlStr);// 可以增加表单数据
                    form.append("file", fileObj);// 文件对象
                    
                    // XMLHttpRequest 对象
                    var xhr = new XMLHttpRequest();
                    xhr.open("post", FileController, true);
                    // XMLHttpRequest回调函数
                    xhr.onload = function(e) {
                        var divresult = document.getElementById("upResult");
                        //接收响应数据  
                        //判断对象状态是否交互完成,如果为4则交互完成 && 判断对象状态是否交互成功,如果成功则为200 
                        if(xhr.readyState == 4 && xhr.status == 200) {
                            divresult.value = "文件上传成功!";
                        }else{
                            divresult.value = "文件上传失败,请重新上传!";
                        }
                    };
                    xhr.send(form);
                }
            }else{
                swal("文件选择不成功!","请重新选择文件!","error");
            }
        }else{
            swal("请上传符合shp格式文件!","请重新选择文件!","error");
        }
    }
}
/**随机名称*/
function randomString(len) {
    len = len || 32;
    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
    var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
    var maxPos = chars.length;
    var randomStr = '';
    for (i = 0; i < len; i++) {
        randomStr += chars.charAt(Math.floor(Math.random() * maxPos));
    }
    return randomStr;
}
//解析SHP并利用geotools判断面面相交关系
function selectbyshp(){
    $.ajax({
        type : "post",
        url : "../../easyAPI/building/selectbyshp.action",
        data : "filename="+jsonfullFileName,
        success : function(data) {
            showShpQueryBuilding(data);
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            console.log("ajax请求失败!","请重试!","error");
        }
    });
}
//获取分层分户
function getFloorAll(){
    //请求数据
    $.ajax({
        type : "post",
        url : "../../easyAPI/floor/getFloor.action",
        contentType : "charset=utf-8",
        success : function(data) {
            showFloorAll(data);
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            swal("ajax请求失败!","请重试!","error");
        }
    });
}
//获取该户重点人口
function getFloorById(id){
    $.ajax({
        type : "post",
        url : "../../easyAPI/floor/getFloorById.action",
        data : "floorId="+id,
        success : function(data) {
            console.log(data);
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            swal("ajax请求失败!","请重试!","error");
        }
    });
}
//重点人口信息管理,根据地名地址ID获取人口详细信息
function queryKeypeopleByAddId(addId) {
    $.ajax({
        type : "post",
        url : "../../easyAPI/keyPeople/queryKeypeopleByAddId.action",
        data : "addId="+addId,
        success : function(data) {
            if (data.length != 0) {
                showInfoKeypeople_3D(data);
            }else{
                swal("获取重点人口信息为空!","请重试!","error");
            }
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            console.log("根据ID获取重点人口详细信息失败!");
        }
    });
}