/** * Created by liyulong on 2015/12/15. */ var gisTools = function () { var deviceCount = 0;//记录已入库的设备数 return { //修改所有调用后可删除: getFeatureLableByDevCode: function (devCode) { var layerLiquid = Gis.getGlobalControl().Globe.Layers.GetLayerByCaption(Gis.getLayerLiquid()); var features = layerLiquid.getAllFeatures(); for (var i = 0; i < features.Count; i++) { var feature = features.item(i); if (feature.Name.substring(5) == devCode) { return feature; } } return null; }, getFeatureDetails: function (feature) { var table = "<div style='width: 380px;padding:0;margin:0;'>"; table += "<table style='border: solid 1px #C1DAD7;margin: 0 auto; font-size:9pt;width:100%;' border='0' cellspacing='0' cellpadding='0' align='center'>"; table += "<tr style='background:#0066CC; color:#fff;font-weight:bold;'>"; table += "<td style='padding:5px 10px; text-align:center;border-bottom:1pt solid #C1DAD7;width:62px;'>属性</td>"; table += "<td style='padding:5px 10px; text-align:center;border-right:1pt solid #C1DAD7;border-bottom:1pt solid #C1DAD7;'>值</td>" table += "</tr>"; table += "</table>"; table += "<div style='width: 380px;overflow-y:scroll;height:220px;padding:0;margin:0;'>"; table += "<table style='border: solid 1px #C1DAD7;margin: 0 auto; font-size:9pt;width:100%;' border='0' cellspacing='0' cellpadding='0' align='center'>"; for (var i = 0; i < feature.GetFieldCount(); i++) { var defn = feature.GetFieldDefn(i); var fieldName = defn.Name; var fieldValue = feature.GetFieldValue(i); if (fieldValue == null || typeof (fieldValue) == 'undefined' || fieldValue == '') { fieldValue = "无"; } if (i % 2 == 1) { table += "<tr style='background-color:#F5FAFA;'>"; table += "<td style='padding:5px 10px; text-align:right;border-right:1pt solid #C1DAD7;border-bottom:1pt solid #C1DAD7;width:62px;'>" + fieldName + "</td>"; table += "<td style='padding:5px 10px; text-align:left;border-right:1pt solid #C1DAD7;border-bottom:1pt solid #C1DAD7;'>" + fieldValue + "</td>"; table += "</tr>"; } else { table += "<tr>"; table += "<td style='padding:5px 10px; text-align:right;border-right:1pt solid #C1DAD7;border-bottom:1pt solid #C1DAD7;width:62px;'>" + fieldName + "</td>"; table += "<td style='padding:5px 10px; text-align:left;border-right:1pt solid #C1DAD7;border-bottom:1pt solid #C1DAD7;'>" + fieldValue + "</td>"; table += "</tr>"; } } table += "</table>"; table += "</div>"; table += "</div>"; return table; }, getDevDetails: function (feature) { var table = "<div style='width: 380px;padding:0;margin:0;overflow-y:hidden;'>"; table += "<table style='border: solid 1px #C1DAD7;margin: 0 auto; font-size:9pt;width:100%;' border='0' cellspacing='0' cellpadding='0' align='center'>"; table += "<tr style='background:#0066CC; color:#fff;font-weight:bold;'>"; table += "<td style='padding:5px 10px; text-align:center;border-bottom:1pt solid #C1DAD7;width:62px;'>属性</td>"; table += "<td style='padding:5px 10px; text-align:center;border-right:1pt solid #C1DAD7;border-bottom:1pt solid #C1DAD7;'>值</td>" table += "</tr>"; table += "</table>"; table += "<div style='width: 380px;overflow-y:auto;height:220px;padding:0;margin:0;'>"; table += "<table style='border: solid 1px #C1DAD7;margin: 0 auto; font-size:9pt;width:100%;' border='0' cellspacing='0' cellpadding='0' align='center'>"; for (var i = 0; i < feature.GetFieldCount(); i++) { var defn = feature.GetFieldDefn(i); var fieldName = noneGisTools.getDevFieldShowName(defn.Name); var fieldValue = feature.GetFieldValue(i); if (fieldValue == null || typeof (fieldValue) == 'undefined' || fieldValue == '') { fieldValue = "无"; } else if (typeof fieldValue == 'number' && fieldName != '编码') { fieldValue = fieldValue.toFixed(2); } if (i % 2 == 1) { table += "<tr style='background-color:#F5FAFA;'>"; table += "<td style='padding:5px 10px; text-align:right;border-right:1pt solid #C1DAD7;border-bottom:1pt solid #C1DAD7;width:62px;'>" + fieldName + "</td>"; table += "<td style='padding:5px 10px; text-align:left;border-right:1pt solid #C1DAD7;border-bottom:1pt solid #C1DAD7;'>" + fieldValue + "</td>"; table += "</tr>"; } else { table += "<tr>"; table += "<td style='padding:5px 10px; text-align:right;border-right:1pt solid #C1DAD7;border-bottom:1pt solid #C1DAD7;width:62px;'>" + fieldName + "</td>"; table += "<td style='padding:5px 10px; text-align:left;border-right:1pt solid #C1DAD7;border-bottom:1pt solid #C1DAD7;'>" + fieldValue + "</td>"; table += "</tr>"; } } table += "</table>"; table += "</div>"; table += "</div>"; return table; }, getWellCodeByDevCode: function (devCode) { var layerDevice = Gis.getGlobalControl().Globe.Layers.GetLayerByCaption("传感设备图层"); var featuresDevice = layerDevice.GetAllFeatures(); for (var i = 0; i < featuresDevice.Count; i++) { var featureDevice = featuresDevice.Item(i); var defnDevice = featureDevice.GetFieldValue("DEVICEID"); if (defnDevice == devCode) { return featureDevice.getFieldValue("ATTACHID"); } } return ""; }, getWellLayerNameByDevCode: function (devCode) { var layerDevice = Gis.getGlobalControl().Globe.Layers.GetLayerByCaption("传感设备图层"); var featuresDevice = layerDevice.GetAllFeatures(); for (var i = 0; i < featuresDevice.Count; i++) { var featureDevice = featuresDevice.Item(i); var defnDevice = featureDevice.GetFieldValue("DEVICEID"); if (defnDevice == devCode) { return featureDevice.getFieldValue("ATTACHLAYER"); } } return ""; }, removeWaterLevelByWellCode: function (wellCode) { if (null == wellCode && "" == wellCode) { return; } var memoryLayer = Gis.getGlobalControl().Globe.Layers.GetLayerByCaption(Gis.getCacheLayer()); var features = memoryLayer.getFeatureByName("yewei," + wellCode, true); if (features.count > 0) { features.item(0).delete(); } }, removeWaterLevelByMarker: function (feature) { var wellCode = gisTools.getWellCodeByDevCode(feature.Name.substring(DeviceService.getMarkerPrefix().length)); gisTools.removeWaterLevelByWellCode(wellCode); }, getLayerLabel: function () { return "MemoryLabel"; }, getDevFeatureByDevCode: function (devCode) { var layerDevice = Gis.getGlobalControl().Globe.Layers.GetLayerByCaption("传感设备图层"); var featuresDevice = layerDevice.GetAllFeatures(); for (var i = 0; i < featuresDevice.Count; i++) { var featureDevice = featuresDevice.Item(i); var defnDevice = featureDevice.GetFieldValue("DEVICEID"); if (defnDevice == devCode) { return featureDevice; } } return featureDevice; }, showAllLayers: function () { $("#layer_manager").tree('check', $("#layer_manager").tree('getRoot').target); }, //隐藏marker关联的label hideLabel: function () { var liquidLayer = Gis.getGlobalControl().Globe.Layers.GetLayerByCaption(Gis.getLayerLiquid()); var features = liquidLayer.GetAllFeatures(); for (var k = 0; k < features.Count; k++) { var feature = features.Item(k); if ((null != feature) && (null != feature.Label)) { feature.Label.Visible = false; } } Gis.getGlobalControl().Refresh(); }, hideAllLayers: function () { for (var i = 0; i < Gis.getGlobalControl().Globe.Layers.Count; i++) { var pLayer = Gis.getGlobalControl().Globe.Layers.GetLayerByID(i); if (pLayer != null && "地面模型" != pLayer.Caption() && pLayer.Caption().indexOf("天地图") == -1) {//隐藏图层时过滤地面模型和天地图 pLayer.Visible = false; } } }, showLayerByPipe: function (pipeName) { var layerNameList = new Array(); switch (pipeName) { case "给水" : layerNameList.push("给水管线"); layerNameList.push("给水管线附属物"); layerNameList.push("给水管线特征管点"); break; case "雨水" : layerNameList.push("雨水管线"); layerNameList.push("雨水管线附属物"); layerNameList.push("雨水管线特征管点"); break; case "污水" : layerNameList.push("污水管线"); layerNameList.push("污水管线附属物"); layerNameList.push("污水管线特征管点"); break; case "天然气" : layerNameList.push("天然气管线"); layerNameList.push("天然气管线附属物"); layerNameList.push("天然气管线特征管点"); break; case "热力" : layerNameList.push("电通管线"); layerNameList.push("电通管线附属物"); layerNameList.push("电通管线特征管点"); break; case "供电" : layerNameList.push("供电管线"); layerNameList.push("供电管线附属物"); layerNameList.push("供电管线特征管点"); break; default : break; } Gis.showSomePipeLayer(layerNameList); }, getFiberMarkerFeats: function (devCode, isNormal) { var markFeats = parent.DeviceService.getFeaturesInLayer(devCode, DeviceService.getMainLayer()); var returnFeats = []; var isNormalStr = isNormal ? 'true' : 'false'; for (var i = 0; i < markFeats.Count; i++) { if (markFeats.item(i).Description.split(',')[0] == isNormalStr) { returnFeats.push(markFeats.item(i)); } } return returnFeats; }, /** * 在feature上面标注文字: * 注:feature目前只支持文字, * * @author liyulong * @time 2015.12.17 * * @param feat * @param desc */ addLabel: function (feat, desc, fontColor, fontSize) { var feature = Gis.getGlobalControl().CreateFeature(); if (feat.Geometry.Type == 305) { //处理点模型 var dynamicMarker = Gis.getGlobalControl().CreateGeoDynamicMarker(); dynamicMarker.Position = feat.Geometry.Position; feature.Geometry = dynamicMarker; } else if (feat.Geometry.Type == 302 || feat.Geometry.Type == 401) { //处理线模型 feature.Geometry = feat.Geometry; } else { //处理面模型 } var label = Gis.getGlobalControl().CreateLabel(); label.Text = desc; if (null != fontColor && null != fontSize) { label.Style = Gis.getGlobalControl().CreateLabelStyle(); label.Style.TextStyle = Gis.getGlobalControl().CreateTextStyle(); label.Style.TextStyle.ForeColor = fontColor; label.Style.TextStyle.FontSize = fontSize; } feature.Label = label; Gis.getGlobalControl().Globe.MemoryLayer.AddFeature(feature); return feature; }, //在管线的一端加label addLabelOnLineOneSide: function (feature, desc) { //不是线feature就不执行 if (feature.Geometry.Type == 302) { var point = feature.Geometry.item(0).item(0); var feature0 = Gis.getGlobalControl().CreateFeature(); var dynamicMarker = Gis.getGlobalControl().CreateGeoDynamicMarker(); dynamicMarker.Position = point; feature0.Geometry = dynamicMarker; var label = Gis.getGlobalControl().CreateLabel(); //透明度调节代码,现在不好使 //var labelStyle = Gis.getGlobalControl().CreateLabelStyle(); //var colorBegin = Gis.getGlobalControl().CreateColorRGBA(); //colorBegin.SetValue(255,255,255,0); //var colorMid = Gis.getGlobalControl().CreateColorRGBA(); //colorMid.SetValue(255,255,255,0); //var colorEnd = Gis.getGlobalControl().CreateColorRGBA(); //colorEnd.SetValue(255,255,255,0); //labelStyle.BackBeginColor = colorBegin; //labelStyle.BackEndColor = colorEnd; //labelStyle.BackMidColor = colorMid; //label.Style = labelStyle; label.Text = desc; feature0.Label = label; Gis.getGlobalControl().Globe.MemoryLayer.AddFeature(feature0); return feature0; } return null; }, getMarkerByDevCode: function (devCode) { if (null == devCode && "" == devCode) { return null; } var layer = Gis.getGlobalControl().Globe.Layers.GetLayerByCaption(Gis.getLayerLiquid()); var features = layer.getAllFeatures(); for (var i = 0; i < features.Count; i++) { var feature = features.Item(i); var defn = feature.Name.substring(6); if (defn == devCode) { return feature; } } return null; }, /** * predator:根据雨水管井的编号绘制方井 * @param wellCode:String * @param liquid:String */ addWaterLevelByWellCode: function (wellCode, liquid) { var layerDevice = Gis.getGlobalControl().Globe.Layers.GetLayerByCaption("传感设备图层"); var layerRainAppen = Gis.getGlobalControl().Globe.Layers.GetLayerByCaption("雨水管线附属物"); var featuresDevice = layerDevice.GetAllFeatures(); var featuresRainAppen = layerRainAppen.GetAllFeatures(); var featureRainPipeAppen = null; for (var i = 0; i < featuresDevice.Count; i++) { var featureDevice = featuresDevice.Item(i); var defn = featureDevice.GetFieldValue("DEVICEID"); if (defn == wellCode) { for (var j = 0; j < featuresRainAppen.Count; j++) { var featureRainAppen = featuresRainAppen.Item(j); var defn2 = featureRainAppen.GetFieldValue("编号"); if (defn2 == featureDevice.GetFieldValue("ATTACHID")) { featureRainPipeAppen = featureRainAppen; break; } } break; } } Gis.showDepthInFangJin(0.75, 0.75, liquid / 1.0, featureRainPipeAppen); }, //显示最新效果 addWaterLevelByMarker: function (markFeat, percent) { var devCode = markFeat.Name.substring(DeviceService.getMarkerPrefix().length); var devFeat = gisTools.getFeatureInLayer(devCode, "deviceid", "传感设备图层"); var wellFeatRain = gisTools.getFeatureInLayer(devFeat.GetFieldValue("ATTACHID"), "编号", "雨水管线附属物"); var wellFeatSewage = gisTools.getFeatureInLayer(devFeat.GetFieldValue("ATTACHID"), "编号", "污水管线附属物"); if (new Number(percent) > 1) { percent = 1.0; } if (null != wellFeatRain) Gis.showCircleWellLiquidLevel(wellFeatRain, percent, 0.2); else if (null != wellFeatSewage) Gis.showCircleWellLiquidLevel(wellFeatSewage, percent, 0.2); // if (null != wellFeatRain) { //雨水 // Gis.showDepthInFangJin(0.75, 0.75, percent, wellFeatRain); // } else if (null != wellFeatSewage) { //污水 // Gis.showCircleWellLiquidLevel(wellFeatSewage, percent, 1.0); // } }, //在polygon中获取某一图层中的管线,feature为设备marker getFeaturesInPolygonAndOneLayer: function (feature, alarmFeature) { var layerName = gisTools.getWellLayerNameByDevCode(feature.Name.substring(DeviceService.getMarkerPrefix().length)); var layerSupplyPipe = Gis.getGlobalControl().Globe.Layers.GetLayerByCaption(layerName.replace("附属物", "")); return layerSupplyPipe.FindFeaturesInPolygon(alarmFeature.Geometry, false); }, //设置起始结束日期,结束日期为今天,开始日期为今天减去dateNum天 setStartAndEndDate: function (dateBoxStart, dateBoxEnd, dateNum) { var now = new Date(); var startS = now.getTime() - 1000 * 3600 * 24 * dateNum; var start = new Date(startS); //以下逻辑比较复杂,但已经过测试没问题。 dateBoxStart.datebox().datebox('calendar').calendar({ validator: function (date) { var d1 = new Date(now.getFullYear(), now.getMonth(), now.getDate()); return date <= d1; } }); dateBoxEnd.datebox().datebox('calendar').calendar({ validator: function (date) { var d1 = new Date(start.getFullYear(), start.getMonth(), start.getDate()); return d1 <= date; } }); dateBoxEnd.datebox({ onSelect: function (date) { var startStr = dateBoxStart.datebox("getValue"); var endStr = dateBoxEnd.datebox("getValue"); if (endStr.indexOf('-') > -1 && endStr.split('-').length == 3) { dateBoxStart.datebox().datebox('calendar').calendar({ validator: function (date) { var end = endStr.split('-'); var d1 = new Date(end[0], end[1] - 1, end[2]); return date <= d1; } }); var startList = startStr.split('-'); var startNew = new Date(startList[0], startList[1] - 1, startList[2]); dateBoxStart.datebox("setValue", Gis.myformatter(startNew)); } } }); dateBoxStart.datebox({ onSelect: function (date) { var startStr = dateBoxStart.datebox("getValue"); var endStr = dateBoxEnd.datebox("getValue"); if (startStr.indexOf('-') > -1 && startStr.split('-').length == 3) { dateBoxEnd.datebox().datebox('calendar').calendar({ validator: function (date) { var startList = startStr.split('-'); var d1 = new Date(startList[0], startList[1] - 1, startList[2]); return date >= d1; } }); var endList = endStr.split('-'); var end = new Date(endList[0], endList[1] - 1, endList[2]); dateBoxEnd.datebox("setValue", Gis.myformatter(end)); } } }); dateBoxStart.datebox("setValue", Gis.myformatter(start)); dateBoxEnd.datebox("setValue", Gis.myformatter(now)); }, setStartAndEndDateForRate: function (dateBoxStart, dateBoxEnd, dateNum) { var now = new Date(); var startS = now.getTime() - 1000 * 3600 * 24 * dateNum; var start = new Date(startS); //以下逻辑比较复杂,但已经过测试没问题。 dateBoxStart.datebox().datebox('calendar').calendar({ validator: function (date) { var d1 = new Date(now.getFullYear(), now.getMonth(), now.getDate()); return date < d1; } }); dateBoxEnd.datebox().datebox('calendar').calendar({ validator: function (date) { var d1 = new Date(start.getFullYear(), start.getMonth(), start.getDate()); var now = new Date(); return d1 < date && date <= now; } }); dateBoxEnd.datebox({ onSelect: function (date) { var startStr = dateBoxStart.datebox("getValue"); var endStr = dateBoxEnd.datebox("getValue"); if (endStr.indexOf('-') > -1 && endStr.split('-').length == 3) { dateBoxStart.datebox().datebox('calendar').calendar({ validator: function (date) { var end = endStr.split('-'); var d1 = new Date(end[0], end[1] - 1, end[2]); return date < d1; } }); var startList = startStr.split('-'); var startNew = new Date(startList[0], startList[1] - 1, startList[2]); dateBoxStart.datebox("setValue", Gis.myformatter(startNew)); } } }); dateBoxStart.datebox({ onSelect: function (date) { var startStr = dateBoxStart.datebox("getValue"); var endStr = dateBoxEnd.datebox("getValue"); if (startStr.indexOf('-') > -1 && startStr.split('-').length == 3) { dateBoxEnd.datebox().datebox('calendar').calendar({ validator: function (date) { var startList = startStr.split('-'); var d1 = new Date(startList[0], startList[1] - 1, startList[2]); var now = new Date(); return date > d1 && now >= date; } }); var endList = endStr.split('-'); var end = new Date(endList[0], endList[1] - 1, endList[2]); dateBoxEnd.datebox("setValue", Gis.myformatter(end)); } } }); dateBoxStart.datebox("setValue", Gis.myformatter(start)); dateBoxEnd.datebox("setValue", Gis.myformatter(now)); }, bulkSaveDev: function (filePath) { deviceCount = 0; //创建操作EXCEL应用程序的实例 try { var excelObject = new ActiveXObject("Excel.application"); //打开指定路径的excel文件 var excelFile = excelObject.Workbooks.open(filePath); //操作第一个sheet(从一开始,而非零) excelFile.worksheets(1).select(); var excelSheet = excelFile.ActiveSheet; //文件总行数 var totalRows = excelSheet.usedrange.rows.count; } catch (e) { alert("对未标记为可执行脚本的ActiveX控件初始化并执行脚本未启用" + '\n' + "或将文件上载到服务器时包含本地目录路径未启用"); } try { //获取属性index var devCodeIndex = gisTools.getPropertyIndex(excelSheet, "编号"); var streetIndex = gisTools.getPropertyIndex(excelSheet, "所属道路"); var gaochengIndex = gisTools.getPropertyIndex(excelSheet, "到井盖距离"); var heightIndex = gisTools.getPropertyIndex(excelSheet, "安装高度"); var wellLayerNameIdIndex = gisTools.getPropertyIndex(excelSheet, "附属物名称"); var wellCodeIndex = gisTools.getPropertyIndex(excelSheet, "附属物编号"); var deviceTypeIdShapeIndex = gisTools.getPropertyIndex(excelSheet, "传感器编码"); var longitudeIndex = gisTools.getPropertyIndex(excelSheet, "X坐标"); var latitudeIndex = gisTools.getPropertyIndex(excelSheet, "Y坐标"); var simIdIndex = gisTools.getPropertyIndex(excelSheet, "SIMID"); //第一行是标题,从2开始d for (var i = 2; i <= totalRows; i++) { /* excel属性依次为 * 1.设备编号,2.所属道路,3.到井盖距离,4.所在附属物图层名称, * 5.所在附属物编号,6.传感器编码,7.经度,8.纬度 */ // 1.读取excel中的属性信息 var devCode = gisTools.getNotNullValue(excelSheet.Cells(i, devCodeIndex).value); var street = gisTools.getNotNullValue(excelSheet.Cells(i, streetIndex).value); var gaocheng = gisTools.getNotNullValue(excelSheet.Cells(i, gaochengIndex).value); var height = gisTools.getNotNullValue(excelSheet.Cells(i, heightIndex).value); var wellLayerNameId = gisTools.getNotNullValue(excelSheet.Cells(i, wellLayerNameIdIndex).value); var wellCode = gisTools.getNotNullValue(excelSheet.Cells(i, wellCodeIndex).value); var deviceTypeIdShape = gisTools.getNotNullValue(excelSheet.Cells(i, deviceTypeIdShapeIndex).value); var longitude = gisTools.getNotNullValue(excelSheet.Cells(i, longitudeIndex).value); var latitude = gisTools.getNotNullValue(excelSheet.Cells(i, latitudeIndex).value); var wellLayerName = gisTools.getWellLayerNameById(wellLayerNameId); var simId = gisTools.getNotNullValue(excelSheet.Cells(i, simIdIndex).value); var acceptPersonId = 50; var deviceTypeId = 0; var deviceTypeName = ""; var devName = ""; var modelPath = ""; if ("600" == deviceTypeIdShape) { //噪声记录仪 deviceTypeId = 1; deviceTypeName = "噪声记录仪"; devName = deviceTypeName + devCode; modelPath += "传感器" + "\\" + deviceTypeName + ".gcm"; } else if ("910" == deviceTypeIdShape) { //远传水表 deviceTypeId = 2; deviceTypeName = "远传水表"; devName = deviceTypeName + devCode; modelPath += "传感器" + "\\" + deviceTypeName + ".gcm"; } else if ("900" == deviceTypeIdShape) { //多功能漏损监测仪 deviceTypeId = 3; deviceTypeName = "多功能漏损监测仪"; devName = deviceTypeName + devCode; modelPath += "传感器" + "\\" + deviceTypeName + ".gcm"; } else if ("2007" == deviceTypeIdShape) { //水质监测仪,shaoe编号未确定 deviceTypeId = 4; deviceTypeName = "水质监测仪"; devName = deviceTypeName + devCode; modelPath += "传感器" + "\\" + deviceTypeName + ".gcm"; } else if ("500" == deviceTypeIdShape) { //液位监测仪 deviceTypeId = 5; deviceTypeName = "液位监测仪"; devName = deviceTypeName + devCode; modelPath += "传感器" + "\\" + deviceTypeName + ".gcm"; } else if ("2004" == deviceTypeIdShape) { //雨量计,shape编号未确定 deviceTypeId = 6; deviceTypeName = "雨量计"; devName = deviceTypeName + devCode; modelPath += "传感器" + "\\" + deviceTypeName + ".gcm"; } else if ("700" == deviceTypeIdShape) { //有害气体监测仪 deviceTypeId = 7; deviceTypeName = "有害气体监测仪"; devName = deviceTypeName + devCode; modelPath += "传感器" + "\\" + deviceTypeName + ".gcm"; } else if ("400" == deviceTypeIdShape) { //智能燃气监测终端 deviceTypeId = 8; deviceTypeName = "燃气智能监测终端"; devName = deviceTypeName + devCode; modelPath += "传感器" + "\\" + deviceTypeName + ".gcm"; } else if ("2005" == deviceTypeIdShape) { //入户燃气报警器,shaoe编号未确定 deviceTypeId = 9; deviceTypeName = "入户燃气报警器"; devName = deviceTypeName + devCode; modelPath += "传感器" + "\\" + deviceTypeName + ".gcm"; } else if ("2003" == deviceTypeIdShape) { //温度压力监测仪 deviceTypeId = 10; deviceTypeName = "温度压力监测仪"; devName = deviceTypeName + devCode; modelPath += "传感器" + "\\" + deviceTypeName + ".gcm"; } else if ("2011" == deviceTypeIdShape) { //保温层下腐蚀环境监测仪 deviceTypeId = 11; deviceTypeName = "保温层下腐蚀环境监测仪"; devName = deviceTypeName + devCode; modelPath += "传感器" + "\\" + deviceTypeName + ".gcm"; } else if ("2012" == deviceTypeIdShape) { //保温层下腐蚀速率监测仪 deviceTypeId = 12; deviceTypeName = "保温层下腐蚀速率监测仪"; devName = deviceTypeName + devCode; modelPath += "传感器" + "\\" + deviceTypeName + ".gcm"; } else if ("800" == deviceTypeIdShape) { //井盖状态监测仪 deviceTypeId = 13; deviceTypeName = "井盖状态监测仪"; devName = deviceTypeName + devCode; modelPath += "传感器" + "\\" + deviceTypeName + ".gcm"; } else if ("3008" == deviceTypeIdShape) { //集中器shp编号 deviceTypeId = 203; deviceTypeName = "数据集中器"; devName = deviceTypeName + devCode; modelPath += "传感器" + "\\" + deviceTypeName + ".gcm"; } else if ("3009" == deviceTypeIdShape) { //集中器shp编号 deviceTypeId = 20; deviceTypeName = "开挖监测仪"; devName = deviceTypeName + devCode; modelPath += "传感器" + "\\" + deviceTypeName + ".gcm"; } else if ("2008" == deviceTypeIdShape) { //消防栓防盗水监测仪 deviceTypeId = 14; deviceTypeName = "消防栓防盗水监测仪"; devName = deviceTypeName + devCode; modelPath += "传感器" + "\\" + deviceTypeName + ".gcm"; } else if ("2020" == deviceTypeIdShape) { //温湿度监测仪 deviceTypeId = 15; deviceTypeName = "温湿度监测仪"; devName = deviceTypeName + devCode; modelPath += "传感器" + "\\" + deviceTypeName + ".gcm"; } else { alert("新类型编号" + deviceTypeIdShape); continue; } // 2.存储新设备到传感设备图层 var device = new Object(); device.deviceTypeName = deviceTypeName; device.devCode = devCode; device.wellCode = wellCode; device.wellLayerName = wellLayerName; device.street = street; device.modelPath = modelPath; device.longitude = longitude; device.latitude = latitude; device.modelLocation = modelPath; device.acceptPersonId = acceptPersonId; device.devName = devName; device.deviceTypeId = deviceTypeId; device.height = height; device.gaocheng = gaocheng; device.simId = simId; gisTools.saveDevice(device); } alert("入库操作完成,已入库" + deviceCount + "台设备"); } catch (e) { alert("入库失败"); } $("#iframeDlg")[0].contentWindow.closeImport(); //退出操作excel的实例对象 excelObject.Application.Quit(); //手动调用垃圾收集器 CollectGarbage(); }, getWellLayerNameById: function (wellLayerNameId) { var wellLayerNameList = [ ["GD", "供电管线附属物"], ["GD", "供电管线附属物"], ["LD", "路灯管线附属物"], ["XH", "交通信号管线附属物"], ["DX", "电信管线附属物"], ["DS", "有线电视管线附属物"], ["WT", "网通管线附属物"], ["YD", "移动管线附属物"], ["LT", "联通管线附属物"], ["TT", "铁通管线附属物"], ["GT", "共通管线附属物"], ["JK", "监控管线附属物"], ["JS", "给水管线附属物"], ["WS", "污水管线附属物"], ["YS", "雨水管线附属物"], ["HS", "雨污合流管线附属物"], ["ZS", "中水管线附属物"], ["RQ", "燃气管线附属物"], ["TR", "天然气管线附属物"], ["RL", "热力管线附属物"], ["GY", "工业管线附属物"], ["ZH", "综合管沟管线附属物"], ["BM", "不明管线附属物"], ["LJ", "垃圾管线附属物"], ["KT", "空调管线附属物"], ["XF", "消防管线附属物"] ]; for (var i = 0; i < wellLayerNameList.length; i++) { if (wellLayerNameList[i][0] == wellLayerNameId) { return wellLayerNameList[i][1]; } } return null; }, //存储新设备到传感设备图层 saveDevice: function (device) { var fields = new Array(); fields.push("DEVICETYPE"); fields.push("DEVICEID"); fields.push("ATTACHID"); fields.push("ATTACHLAYER"); fields.push("ROAD"); fields.push("MODELPATH"); var values = new Array(); values.push(device.deviceTypeName); values.push(device.devCode); values.push(device.wellCode); values.push(device.wellLayerName); values.push(device.street); values.push(device.modelPath); var position = Gis.getGlobalControl().CreatePoint3d(); position.SetValue(device.longitude, device.latitude, 0); return gisTools.addModelToLayer(device.modelLocation, device.devName, "传感设备图层", position, device.devCode, fields, values, device); }, getNotNullValue: function (inValue) { var outValue = ""; if (typeof inValue == "string") { inValue = inValue.replace(/[\r|\n|\t|\s]/g, ""); } if (null != inValue) { outValue = inValue; } return outValue; }, getPropertyIndex: function (excelSheet, propertyName) { var index = 1; while (true) { var value = excelSheet.Cells(1, index).value; if (!value) { return -1; } else if (value == propertyName) { return index; } index++; } }, /* modelPath:模型在服务器端的路径 descn:feature的描述 layerName:图层的名称 pos:必须为var position=globalControl.CreatePoint3d(); featureName:要素的名称 */ addModelToLayer: function (modelPath, descn, layerName, pos, featureId, fields, values, device) { try { var layer = Gis.getGlobalControl().Globe.Layers.GetLayerByCaption(layerName); var features = layer.GetFeatureByName(featureId, true); if (features.Count != 0) { if (confirm("设备" + values[1] + "已经存在,是否覆盖?")) { for (var i = 0; i < features.Count; i++) { var feature = features.Item(i); feature.Delete(); Gis.getGlobalControl().Refresh(); } this.saveFeature(layer, modelPath, descn, layerName, pos, featureId, fields, values);//保存在设备图层 if (device.deviceTypeId == 203) {//为数据集中器时保存到alarm_concentrator表 this.saveConcen(device) } else { this.saveAlarmDevice(device);//除数据集中器外的设备保存到 alarm_device 表中 } } else { return false; } } else { this.saveFeature(layer, modelPath, descn, layerName, pos, featureId, fields, values); if (device.deviceTypeId == 203) {//为数据集中器时保存到alarm_concentrator表 this.saveConcen(device) } else { this.saveAlarmDevice(device);//除数据集中器外的设备保存到 alarm_device 表中 } } } catch (e) { alert("添加模型错误"); } }, saveFeature: function (layer, modelPath, descn, layerName, pos, featureId, fields, values) { var feature = layer.Dataset.CreateFeature(); var model = Gis.getGlobalControl().CreateGeoModel(); model.FilePath = modelPath; model.Position = pos; model.AltitudeMode = 0; feature.Geometry = model; feature.Name = featureId; for (var i = 0; i < fields.length; i++) { feature.SetFieldValue(fields[i], values[i]); } layer.AddFeature(feature); layer.save(); Gis.getGlobalControl().Refresh(); }, saveAlarmDevice: function (device) {//保存设备到数据库alarm_device表中 var date = new Date(); var today = date.getFullYear() + "-" + (date.getMonth() + 1).toString() + "-" + date.getDate(); $.ajax({ type: "POST", async: false, url: $("#context").val() + "/alarm/device!bulkSave.do", data: { devCode: device.devCode, devName: device.devName, roadName: device.street, gaocheng: device.gaocheng, height: device.height, setupDate: today, latitude: device.latitude, longtitude: device.longitude, attachLayer: device.wellLayerName, attachFeature: device.wellCode, ownerId: device.acceptPersonId, deviceTypeId: device.deviceTypeId }, success: function (result) { var result = eval("(" + result + ")"); if (!result.success) { alert("alarm_device" + result.msg); } deviceCount++; } }); }, saveConcen: function (device) {//保存集中器到数据库alarm_concentrator表中 $.ajax({ type: "POST", async: false, url: $("#context").val() + "/alarm/device-concentrator!bulkSave.do", data: { concenCode: device.devCode, roadName: device.street, latitude: device.latitude, longtitude: device.longitude, simId: device.simId }, success: function (result) { var result = eval("(" + result + ")"); if (!result.success) { alert("concen_device" + result.msg); } deviceCount++; } }); }, /* modelPath:模型在服务器端的路径 descn:feature的描述 layerName:图层的名称 pos:必须为var position=globalControl.CreatePoint3d(); featureName:要素的名称 */ getFeatureInLayer: function (fieldValue, fieldName, layerName) { var layer = Gis.getGlobalControl().Globe.Layers.GetLayerByCaption(layerName); if (layer == null) { return null; } var features = layer.GetAllFeatures(); for (var i = 0; i < features.Count; i++) { var feature = features.Item(i); var defn = feature.GetFieldValue(fieldName); if (defn == fieldValue) { return feature; } } return null; }, updateAlarmMarker: function (dev) { var devices = new Array(); //删除旧marker gisTools.deleteMarker(DeviceService.getMarkerPrefix() + dev.devCode); var desc = DeviceService._getLabelInfo(dev); var feature = DeviceService.getFeatureInLayer(dev.devCode, "传感设备图层"); if (feature != null) { var device = new DeviceBean(feature, dev.isNormal); devices.push(device); } DeviceService.show(devices); }, deleteMarker: function (markerName) { var oldMarkFeat = DeviceService.getFeatureInLayer(markerName, DeviceService.getMainLayer()); if (null != oldMarkFeat) { oldMarkFeat.delete(); Gis.getGlobalControl().Refresh(); } }, getDisInFiber: function (fiberFeat, x, y) { var line = fiberFeat.Geometry; var totalLength = line.GetSpaceLength(false, 6378137); var shortestPointDis = totalLength; var dis = 0; for (var i = 0; i < totalLength; i++) { var segment = line.GetSegment(0, i);//第二个参数是distance var point = segment.Item(segment.PartCount - 1).Item(segment.Item(segment.PartCount - 1).Count - 1); //var point = segment.Item(0).Item(0); var pointX = point.X.toFixed(7); var pointY = point.Y.toFixed(7); var pointDis = Math.sqrt(Math.pow((pointX - x), 2) + Math.pow((pointY - y), 2)); if (pointDis < shortestPointDis) { dis = i; shortestPointDis = pointDis; } } return dis; }, screenToScene: function (x, y) { var screenPoint = Gis.getGlobalControl().CreatePoint2d(); screenPoint.X = x; screenPoint.Y = y; var scenePoint = Gis.getGlobalControl().Globe.ScreenToScene(screenPoint);//SceneToScreen x = scenePoint.X; y = scenePoint.Y; return [x, y]; }, sceneToScreen: function (x, y) { var scenePoint = Gis.getGlobalControl().CreatePoint3d(); scenePoint.X = x; scenePoint.Y = y; scenePoint.Z = 0; var screenPoint = Gis.getGlobalControl().Globe.sceneToScreen(scenePoint); x = screenPoint.X; y = screenPoint.Y; return [x, y]; }, showSitePipe: function (ds, roleName) { if (roleName.indexOf("liuying") != -1) { for (var i = 0; i < ds.Count; i++) { var layerName = ds.Item(i).Caption(); if (layerName.indexOf("燃气") > -1 || layerName.indexOf("传感设备图层") > -1) { var layer = Gis.getGlobalControl().Globe.Layers.Add2(ds.Item(i)); } } } else { for (var i = 0; i < ds.Count; i++) { var layerName = ds.Item(i).Caption(); if (layerName.indexOf("给水") > -1 || layerName.indexOf("供电") > -1 || layerName.indexOf("燃气") > -1 || layerName.indexOf("污水") > -1 || layerName.indexOf("移动") > -1 || layerName.indexOf("电信") > -1 || layerName.indexOf("交通") > -1 || layerName.indexOf("路灯") > -1 || layerName.indexOf("雨水") > -1 || layerName.indexOf("传感设备图层") > -1) { var layer = Gis.getGlobalControl().Globe.Layers.Add2(ds.Item(i)); } } } for (var i = 0; i < ds.Count; i++) { var layerName = ds.Item(i).Caption(); if (layerName.indexOf("管线") == layerName.length - 2) { Gis.pipelineLiuXiang(layerName, false); } } Gis.getGlobalControl().refresh(); }, updateOneMarker: function (srcDevId, destDevId, destDevType) { Gis.removeFeatureById(srcDevId, Gis.getLayerLiquid()); var devices = new Array(); var feature = DeviceService.getFeatureInLayer(destDevId, "传感设备图层"); if (feature) { var device = new DeviceBean(feature, true); devices.push(device); } DeviceService.show(devices); }, getEyLocation: function () { var cameraState = Gis.getGlobalControl().CreateCameraState(); //二院 //cameraState.Longitude = 116.2629806; //cameraState.Latitude = 39.91115833; cameraState.Longitude = 114.87731944444444; cameraState.Latitude = 25.78916111111111; cameraState.Heading = 1; cameraState.Tilt = 44.392160966227; cameraState.Distance = 500; cameraState.Altitude = 0; cameraState.AltitudeMode = 2; return cameraState; }, /* ******************************************************************************************* * 代码块:清除所有地球关联各种操作的事件 */ //以下方法用来清除所有地球关联FireFeatureMouseClick的事件 clearFeatureMouseClickEvent: function () { Gis.detachEvent("FireFeatureMouseClick", Gis.showballoon); // Gis.detachEvent("FireFeatureMouseClick", Gis.showRQverticals); }, //以下方法用来清除所有地球关联MouseUp的事件 clearMouseUpEvent: function () { Gis.detachEvent("MouseUp", Gis.getGasLeakage0); Gis.detachEvent("MouseUp", Gis.addDevice); Gis.detachEvent("MouseUp", Gis.closeValveAnalysis); Gis.detachEvent("MouseUp", Gis.showOneRainLevel); Gis.detachEvent("MouseUp", Gis.showRQverticals); var alarmMsg2 = document.frames['iframeDlg'].alarmMsg2; if (undefined != alarmMsg2 && null != alarmMsg2) { Gis.detachEvent("MouseUp", alarmMsg2.SelectAlarmPos); } }, //以下方法用来清除所有地球关联FireTrackPolygonEnd的事件 clearFireTrackPolygonEndEvent: function () { Gis.detachEvent("FireTrackPolygonEnd", Gis.showCutLine); }, /* * 代码块:清除所有地球关联各种操作的事件结束 ***************************************************************************************** */ addSysLog: function (businessName, operationType, content) { jQuery.ajax({ type: "POST", dataType: 'json', data: { businessName: businessName, operationType: operationType, content: content }, url: $('#context').val() + "/alarm/sys-log!saveSysLog.do" }); } } }();