window.maps = {}; window.panels = {}; window.utils = {}; window.Q = {}; var allLayers = new Map(); var map, crs, resultLayer, TempLayer; var mapLayer = null,lableLayer = null, subLayers , plotting, plottingLayer, drawMapControl, drawLayer; var url = URL_CONFIG.GX_Map_BaseUrl, dataUrl = URL_CONFIG.GX_Datas_BaseUrl, serverUrl = URL_CONFIG.GX_Plot_BaseUrl, spatialanalystUrl = URL_CONFIG.GX_Spatialanalyst_BaseUrl, drawType = "", transportationAnalystUrl = URL_CONFIG.GX_TransportationAnalyst_BaseUrl; $(document).ready(function() { layui.use(['layer'], function() { let layer = layui.layer; layer.config({ extend: 'cool/cool.css' }); }); onload(); $('#tool-clickQuery').click(function() { clearLays(); clickQuery(); }); $('#tool-dis').click(function() { clearLays(); measureDistance(); }); $('#tool-area').click(function() { clearLays(); measureArea(); }); $('#tool-clear').click(function() { clearLays(); }); $('#tool-CircleQuery').click(function() { clearLays(); drawCircle(); }); $('#tool-SquarenessQuery').click(function() { clearLays(); drawRectangle(); }); $('#tool-ScopeQuery').click(function() { clearLays(); drawPolygon(); }); $('#tool-layerCtrl').click(function(e) { clearLays(); panels.openLayerTreePanel(); }); $('#tool-fullscreen').click(function() { toggleFullScreen(); }); $('#tool-dmfx').click(function() { clearLays(); dmfx(); }); $('#tool-kwLine').click(function(e) { clearLays(); pzfx(); }); $('#tool-ftfx').click(function(e) { clearLays(); ftfx(); }); $('#tool-ltfx').click(function(e) { clearLays(); ltfx(); }); $('#tool-layerEdit').click(function(e) { clearLays(); layerEdit(); }); }); function onload() { layui.use('element', function() {}); panels.regEvents(); panels.setDateTime(); loadLayerTrees(); $("#load_bg").remove(); //关闭加载动画 $(".load_box").remove(); } panels.setDateTime = function() { setInterval(() => { let dt = new Date(); let yyyymmdd = dt.getFullYear() + " " + (dt.getMonth() + 1) + " " + dt.getDate(); let sec = dt.getSeconds(); sec = sec < 10 ? "0" + sec : sec + ""; let time = (dt.getHours() < 12 ? "上午" : "下午") + " " + dt.getHours() + ":" + dt.getMinutes() + ":" + sec; $('.datetime .time').html(time); $('.datetime .date').html(yyyymmdd); }, 1000); } panels.menuLevel = {}; panels.regEvents = function() { $('.query-type-enum div').click(function(e) { $('.query-type-enum div').removeClass("query-type-enum-select"); $(this).addClass("query-type-enum-select"); $("#queryType-subType").html(''); if (panels.lastResultPanelIndex != undefined) { layui.layer.close(panels.lastResultPanelIndex); layui.layer.closeAll(); } panels.menuLevel[panels.menuLevel.L1] = this; let id = $(this).find('span').attr('qs-name'); if (id == undefined) return; $("#queryType-subType").html($(this).find('span').html()); let htmlUrl = "/pipeline/bs/" + id + ".html"; $.ajax({ url: htmlUrl, success: function(htmlContext) { $('.queryConditionsContainer').html(''); $('.queryConditionsContainer').html(htmlContext); layui.use(['form'], function() { let form = layui.form; form.render(); }); }, error: function() { $('.queryConditionsContainer').html(''); layui.layer.msg('功能未实现!', { icon: 7 }); } }); }); $('.head-menus span').click(function(e) { if (panels.lastResultPanelIndex != undefined) { layui.layer.close(panels.lastResultPanelIndex); layui.layer.closeAll(); } $("#queryType-subType").html('未选择类型'); $(".query-type-enum div").removeClass('query-type-enum-select '); let selected = $(this).hasClass('head-menus-menu-select'); $('.head-menus span').removeClass('head-menus-menu-select'); if (!selected) { $(this).addClass('head-menus-menu-select'); $('.q-s-icon').removeClass('qs-hidden'); } else { $('.q-s-icon').addClass('qs-hidden'); $('.q-s-type').addClass('qs-hidden'); } let qureyOrStatics = $(this).hasClass('qs-q'); //点击了查询按钮 if (qureyOrStatics) { panels.menuLevel.L1 = 2; $('.qs-q').removeClass('qs-hidden'); $('.qs-s').addClass('qs-hidden'); } else { panels.menuLevel.L1 = 1; $('.qs-s').removeClass('qs-hidden'); $('.qs-q').addClass('qs-hidden'); } if (panels.menuLevel[panels.menuLevel.L1] != undefined) { $(panels.menuLevel[panels.menuLevel.L1]).trigger('click'); } $('.queryConditionsContainer').html(''); }); $("#cdts-ctrl").click(function(e) { var notDisplayCdts = $(this).find('img').eq(0).hasClass('qs-hidden'); if (notDisplayCdts) { $(this).find('img').eq(0).removeClass('qs-hidden'); $(this).find('img').eq(1).addClass('qs-hidden'); $('.q-s-type').addClass('qs-hidden'); } else { $(this).find('img').eq(1).removeClass('qs-hidden'); $(this).find('img').eq(0).addClass('qs-hidden'); $('.q-s-type').removeClass('qs-hidden'); } }); } function loadLayerTrees () { proj4.defs("EPSG:4549","+proj=tmerc +lat_0=0 +lon_0=120 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs"); // crs = L.Proj.CRS("EPSG:4549",{ // bounds: L.bounds([384751.09,3977225.45], [558877.26,4071961.92]), // origin:[384751.09,4071961.92], // }); // var pt = crs.unproject(L.point(395917.83 , 4060264.75)); // map = L.map('cesiumContainer', { // preferCanvas: true, // crs: crs, // center:[pt.lat,pt.lng], // zoom: 5, // logoControl: false, // attributionControl: false // }); // mapLayer = L.supermap.tiledMapLayer(url, {noWrap: true}); // map.addLayer(mapLayer); // 添加地图服务 crs = L.Proj.CRS("EPSG:4549"); map = L.map('cesiumContainer', { preferCanvas: true, center: [45.507908,124.290565], zoom: 14, crs: L.CRS.TianDiTu_WGS84 }); mapLayer = L.supermap.tiandituTileLayer({ key: "1d109683f4d84198e37a38c442d68311" }); map.addLayer(mapLayer); lableLayer = L.supermap.tiandituTileLayer({ isLabel: true, key: "1d109683f4d84198e37a38c442d68311" }); map.addLayer(lableLayer); var thisLayer = {}; thisLayer.layer = mapLayer; thisLayer.isShow = true; allLayers.set("baseMap",thisLayer) var lyrs = CONST_VALUES.GX_Datas; for (var index = 0; index < lyrs.length; index++) { var lyr = lyrs[index]; var lyrid = lyr.id; var dataSourceName = lyr.dataSourceName; var dataSetName = lyr.dataSetName; addLayerData(dataSourceName,dataSetName,lyrid,""); } // 添加鹰眼 var osm2 = L.supermap.tiandituTileLayer({ key: "1d109683f4d84198e37a38c442d68311" }); // var osm2 = L.supermap.tiledMapLayer(url, {minZoom: 0, maxZoom: 13,noWrap: true}); L.control.minimap(osm2, {mapOptions:{ logoControl: false},toggleDisplay: true}).addTo(map); // 添加比例尺 L.control.scale().addTo(map); // 启动绘制功能 InitDraw(); map.on('zoomend', function(e) { var nowZoom = e.target.getZoom(); var lyrs = CONST_VALUES.GX_Datas; for (var index = 0; index < lyrs.length; index++) { var lyr = lyrs[index]; var layId = lyr.id; var showZoom = lyr.showZoom; if(showZoom == undefined || showZoom == 0){ continue; } var thisLayer = allLayers.get(layId); var isShow = thisLayer.isShow; var layTmp = thisLayer.layer; if(nowZoom >= showZoom){ if(isShow && !map.hasLayer(layTmp)){ map.addLayer(layTmp); } } else{ if(isShow && map.hasLayer(layTmp)){ map.removeLayer(layTmp); } } } }); resultLayer = L.featureGroup().addTo(map); TempLayer = L.featureGroup().addTo(map); $('body').append("
"); let openThePanel = function() { if ($("#layerTree").html().length > 0) { panels.loadLayerTreePanelByDom('layerTree'); return; } panels.loadLayerTreePanelByDom('layerTree', function() { var allLayersTemp = []; for (var index = 0; index < lyrs.length; index++) { var lyr = lyrs[index]; var nodeLayerInScene = { title: lyr.name, id: lyr.id, layer: lyr, checked: true }; allLayersTemp.push(nodeLayerInScene); } var nodeLayerInScene = { title: "地图服务", id: "baseMap", layer: mapLayer, checked: true }; allLayersTemp.push(nodeLayerInScene); layui.use('tree', function() { const tree = layui.tree; tree.render({ elem: '#layerTree', data: allLayersTemp, showCheckbox: true, showLine: true, oncheck: function(obj) { var layId = obj.data.id; var thisLayer = allLayers.get(layId); var layTmp = thisLayer.layer; if(obj.checked){ if(!map.hasLayer(layTmp)){ map.addLayer(layTmp); thisLayer.isShow = true; allLayers.set(layId,thisLayer); if(layId == "baseMap" && lableLayer != null){ map.addLayer(lableLayer); } } } else{ if(map.hasLayer(layTmp)){ map.removeLayer(layTmp); thisLayer.isShow = false; allLayers.set(layId,thisLayer); if(layId == "baseMap" && lableLayer != null){ map.removeLayer(lableLayer); } } } // 重新指定一下中心点,解决不刷新图层的问题 map.panTo(map.getCenter()); } }); }); }); } panels.openLayerTreePanel = openThePanel; } function addLayerData(dataSourceName,dataSetName,lyrid,showCss) { Q.queryBySql(dataSetName, dataSourceName, "SmID > 0", 0, 2000000, "", function(rs) { if (rs.result == undefined) return; var result = L.Util.transform(rs.result.features, crs, L.CRS.EPSG4326); var rsLayer; var thisLayer = {}; if(lyrid == "waterLine"){ rsLayer = L.geoJSON(result,{style:{color: "#070af3"}}); map.addLayer(rsLayer); } else{ var circleStyle = layerStyles.get(lyrid); var graphics = []; //设置每个点的经纬度和传入样式 for(var i = 0; i < result.features.length; i++) { var feature = result.features[i]; var coordinates = feature.geometry.coordinates; var pointVector = L.supermap.graphic({ latLng: L.latLng(coordinates[1], coordinates[0]), style: circleStyle.getStyle() }); graphics.push(pointVector) } //将管点要素画在地图上 rsLayer = L.supermap.graphicLayer(graphics, {render: "canvas"}); } thisLayer.layer = rsLayer; thisLayer.isShow = true; allLayers.set(lyrid,thisLayer); }); } panels.loadLayerTreePanelByDom = function(domID, callback) { layui.use('layer', function() { const layer = layui.layer; panels.layerTreePanelIndex = layer.open({ anim: 3, id: 'layerTreePanel', area: "280px", skin: 'layui-ext-coolskin', title: ["全部图层", 'font-size:14px;'], offset: ['65px', panels.SideWidth() + 5 + "px"], shade: 0, type: 1, content: $('#' + domID), //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响 cancel: function() {}, success: function(layero, index) {} }); if (callback != undefined) { callback(); } }); } panels.SideWidth = function() { return $(".layui-side").width(); } /** * 点选查询 */ function clickQuery() { let lyrs = CONST_VALUES.GX_Datas; let lyrsSelect = '
'; let listStr = ""; for (let index = 0; index < lyrs.length; index++) { const lyr = lyrs[index]; let dom = listStr.replace('THENAME', lyr.name); dom = dom.replace('THETITLE', lyr.name); dom = dom.replace('THEID', lyr.id); dom = dom.replace('THEWS', lyr.dataSourceName); dom = dom.replace('THEDATASETNAME', lyr.dataSetName); lyrsSelect += dom; } lyrsSelect += '
'; layui.use('layer', function() { let layer = layui.layer; layer.open({ id: "panel-layerSelect", type: 1, area: ["300px", "220px"], btn: ['确定'], title: "请选择图层", skin: 'layui-ext-coolskin', content: lyrsSelect, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响 cancel: function(index, layero) { layer.close(index); }, yes: function(e) { var layers = $("#layers input:checked"); if (layers.length == 0) { layer.msg('请至少选择一个图层!', {icon: 7}); return; } layer.close(e); map.on('click', function (evt) { var pt = crs.project(evt.latlng); var _Point = L.marker([pt.y, pt.x]); for (var index = 0; index < layers.length; index++) { if(index == layers.length-1){ map.off("click"); } let checked = layers[index].checked; if (!checked) continue; var ws = layers[index].attributes.dataSourceName.value; var dataSetName = layers[index].attributes.dataSetName.value; var thatsubtitleP = layers[index].title; clicQueryProcess(thatsubtitleP, dataSetName, ws, _Point); } }); } }); layui.use(['form'], function() { let form = layui.form; form.render(); }); }); } function clicQueryProcess(subtitle, dataSetName, ws, _Point) { Q.queryByGeometry(subtitle,undefined,dataSetName, ws, _Point, function(result) { if (result.result == undefined) return; panels.createResultPanelWithDataGrid({ subTitle: subtitle, features: result.result.features.features, title: "点击查询结果", //count: count, dataSetName: dataSetName, dataSourceName: ws }, function() { }); // 坐标系转换 var result = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326); L.geoJSON(result, { style:{color: "#ef5b9c"}, onEachFeature: function (feature, layer) { let attributes = ""; let lyrs = CONST_VALUES.GX_Datas; for (var index = 0; index < lyrs.length; index++) { var lyr = lyrs[index]; if(ws == lyr.dataSourceName && dataSetName == lyr.dataSetName){ var showCols = lyr.cols; if(showCols != undefined && showCols != ""){ var colsArr = showCols.split(","); for(var i = 0; i < colsArr.length; i++){ var colArr = colsArr[i].split(":"); let attValue = feature.properties[colArr[0]]; let attr = colArr[1] + ":" + attValue + "
"; attributes += attr; } } break; } } layer.bindPopup(attributes); } }).addTo(resultLayer); }); } /*距离测量*/ function measureDistance() { map.off('click'); map.off('dblclick'); $("#tips").css('display', 'block'); var isFirstPoint = true; //判断是否是起始点 var latLngTemp = null;//存储上一点击点临时变量 var resultDis = 0; //总距 map.on('click', function(ev) { TempLayer.clearLayers(); $("#tips").css('display', 'none'); var polyLine; if(isFirstPoint) { L.marker([ev.latlng.lat, ev.latlng.lng]).addTo(resultLayer); //起始点 var texticon = L.divIcon({ //定义图标 html: "起点", iconSize: [30, 20], iconAnchor: [15, 0] }); L.marker([ev.latlng.lat, ev.latlng.lng], { icon: texticon }).addTo(resultLayer); //marker实现文本框显示 latLngTemp = ev.latlng; //存储上一点击点 isFirstPoint = false; } else { if(!latLngTemp.equals(ev.latlng)) { //避免出现结束双击,导致距离为0 polyLine = L.polyline([ //与上一点连线 [latLngTemp.lat, latLngTemp.lng], [ev.latlng.lat, ev.latlng.lng] ], { color: "red" }); resultLayer.addLayer(polyLine); L.marker([ev.latlng.lat, ev.latlng.lng]).addTo(resultLayer); // 最后点击点经纬度 var from = turf.point([latLngTemp.lng, latLngTemp.lat]); var to = turf.point([ev.latlng.lng, ev.latlng.lat]); var options = {units: 'kilometers'}; var jl11 = turf.distance(from, to, options) * 1000; latLngTemp = ev.latlng; //更新临时变量为新点 resultDis += jl11; // 距离根据地图单位进行换算成米或者千米 var content = "距上点:" + Number(jl11).toFixed(2) + "米" + "
总距:" + Number(resultDis).toFixed(2) + "米"; var texticon = L.divIcon({ html: content, iconSize: [110, 40], iconAnchor: [55, -5] //设置标签偏移避免遮盖 }); L.marker([ev.latlng.lat, ev.latlng.lng], { icon: texticon }).addTo(resultLayer); TempLayer.clearLayers(); } } map.on("mousemove", function(ev) { TempLayer.clearLayers(); var TempLine = L.polyline([ //虚线临时线段 [latLngTemp.lat, latLngTemp.lng], [ev.latlng.lat, ev.latlng.lng] ], { color: "red", dashArray: "5,5" }); TempLayer.addLayer(TempLine); // 对坐标系进行转换 var pt1 = crs.project(latLngTemp); var pt2 = crs.project(ev.latlng); var TempLineDis = L.polyline([ //与上一点连线 [pt1.y, pt1.x], [pt2.y, pt2.x] ]); var from = turf.point([latLngTemp.lng, latLngTemp.lat]); var to = turf.point([ev.latlng.lng, ev.latlng.lat]); var options = {units: 'kilometers'}; var jl11 = turf.distance(from, to, options) * 1000; var texticon = L.divIcon({ html: Number(jl11).toFixed(2) + "米", iconSize: 90, className: 'my-div-icon', iconAnchor: [45, -5] }); L.marker([ev.latlng.lat, ev.latlng.lng], { icon: texticon }).addTo(TempLayer); }); }); map.on('dblclick', function(ev) { map.off('click'); map.off('dblclick'); map.off('mousemove'); }); } /*面积测量*/ function measureArea() { drawType = "measureArea"; // 创建绘制控件,并启用 var handler = new L.Draw.Polygon(map); handler.enable(); map.on(L.Draw.Event.CREATED,function (e) { if(drawType != "measureArea"){ return; } var type = e.layerType, layer = e.layer; if (type === 'marker') { layer.bindPopup('A popup!'); } //将图形信息传给下一步,进行查询功能 var locationArray = e.layer.getLatLngs()[0]; var polygonArray = Array(); var turfPolygonArray = Array(); var midArray = Array(); var turfMidArray = Array(); var firstX = locationArray[0].lat; var firstY = locationArray[0].lng; for(var i =0;i请重新设置查询条件!'); return -1; } var layer = layui.layer; panels.createPanelBase(layer,params.title); panels.createPagesByFeatures(params); if (callback != undefined) { callback(); } }); } panels.createPanelBase = function(layer,title, resizeCb) { //兼容两个页面 let pc = $("#panel-condition"); let theTarget; if (pc.length > 0) { theTarget = pc.parent(); } else { theTarget = $(".q-s-type"); } const conditionLeft = parseInt(theTarget.css("left").replace('px', '')); const conditionWidth = parseInt(theTarget.width()); const conditionHeight = parseInt(theTarget.height()); const conditionTop = parseInt(theTarget.css("top").replace('px', '')); let x = conditionLeft + conditionWidth + 5 + "px"; let y = conditionTop + conditionHeight + 10 + "px"; let offset = ['65px']; if (pc.length === 0) { x = conditionLeft + "px"; offset = [y, x] } panels.lastResultPanelIndex = layer.open({ id: "panel-result", anim: 3, area: ['412px', '400px'], title: "" + title + "", skin: 'layui-ext-coolskin', offset: offset, shade: 0, type: 1, maxmin: true, resizing: function(layero) { if (resizeCb) resizeCb(layero); }, full:function(layero){ if (resizeCb) resizeCb(layero); }, restore:function(layero){ if (resizeCb) resizeCb(layero); }, success: function(layero, index) {} }); } panels.createPagesByFeatures = function(params) { panels.createMonitor(); let subTitle = params.subTitle; let features = params.features; let dataSourceName = params.dataSourceName; let dataSetName = params.dataSetName; if (features.length == 0) return; let tableNew = "
"; const tableNewID = utils.guid(); while (tableNew.indexOf('THETABLEID') > -1) tableNew = tableNew.replace('THETABLEID', tableNewID); let cols = []; var showZoom = 10; let lyrs = CONST_VALUES.GX_Datas; for (var index = 0; index < lyrs.length; index++) { var lyr = lyrs[index]; if(dataSourceName == lyr.dataSourceName && dataSetName == lyr.dataSetName){ var showCols = lyr.cols; showZoom = lyr.showZoom; if(showCols != undefined && showCols != ""){ var colsArr = showCols.split(","); for(var i = 0; i < colsArr.length; i++){ var colArr = colsArr[i].split(":"); cols.push({ field: colArr[0], title: colArr[1], sort: true, width: 80 }); } } break; } } if(cols.length == 0){ for (const property in features[0].properties) { let tmpProperty = property.toUpperCase(); if (tmpProperty.startsWith("SM") && tmpProperty != "SMID") continue; if (tmpProperty.startsWith("SS")) continue; cols.push({ field: property, title: property, sort: true }); } } let datas = []; for (let i in features) { datas.push(features[i].properties); } let tabControl = "
" + "" + "
"; let tabControlID = utils.guid(); tabControl = tabControl.replace('THETABCONTROLID', tabControlID); if ($('div[lay-filter="resultTabControl"]').length == 0) { $(tabControl).appendTo($("#panel-result")); } layui.use('element', function() { let element = layui.element; element.render(); let tabID = utils.guid(); element.tabAdd('resultTabControl', { title: subTitle, content: tableNew //支持传入html , id: tabID }); layui.use('table', function() { let table = layui.table; table.render({ elem: '#' + tableNewID, data: datas, page: true, "lay-size": 'sm', limit: 6, done:function (res, curr, count){ $("table").css("width", "100%"); }, cols: [cols], // toolbar: true, // totalrow: true, // title: '导出结果' }); table.on('row(' + tableNewID + ')', function(obj) { Q.queryBySql(dataSetName, dataSourceName, "SMID = " + obj.data.SMID, 0, 10, "", function(result) { if (result.result == undefined) return; // 坐标系转换 var result = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326); L.geoJSON(result, { style:{color: "#f80202"}, onEachFeature: function (feature, layer) { if(feature.geometry.type == 'Point'){ map.flyTo(layer._latlng, showZoom); } else{ map.flyToBounds(layer._bounds); } let attributes = ""; let lyrs = CONST_VALUES.GX_Datas; for (var index = 0; index < lyrs.length; index++) { var lyr = lyrs[index]; if(dataSourceName == lyr.dataSourceName && dataSetName == lyr.dataSetName){ var showCols = lyr.cols; if(showCols != undefined && showCols != ""){ var colsArr = showCols.split(","); for(var i = 0; i < colsArr.length; i++){ var colArr = colsArr[i].split(":"); let attValue = feature.properties[colArr[0]]; let attr = colArr[1] + ":" + attValue + "
"; attributes += attr; } } break; } } layer.bindPopup(attributes); } }).addTo(resultLayer); }); }); }); element.tabChange('resultTabControl', tabID); const thisTitle = $('.layui-layer-title'); thisTitle.addClass("layui-layer-title-transparent"); }); } panels.createMonitor = function() { if (panels.createMonitor.created == true) return; panels.createMonitor.created = true; function imitateClick(oElement, iClientX, iClientY) { var oEvent; if (document.createEventObject) { //For IE oEvent = document.createEventObject(); oEvent.clientX = iClientX; oEvent.clientY = iClientY; oElement.fireEvent("onclick", oEvent); } else { oEvent = document.createEvent("MouseEvents"); oEvent.initMouseEvent("click", true, true, window, 0, 0, 0, iClientX, iClientY); oElement.dispatchEvent(oEvent); } } panels.createMonitor.moniter = imitateClick; } utils.guid = function() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { let r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); } Q.queryBySql = function(datasetName, wsName, sql, fromIndex, toIndex, aggregations, callback) { let sqlParam = new SuperMap.GetFeaturesBySQLParameters({ queryParameter: { name: datasetName + "@" + wsName, attributeFilter: sql }, datasetNames: [wsName + ":" + datasetName], fromIndex: fromIndex, toIndex: toIndex, maxFeatures: toIndex }); L.supermap.featureService(dataUrl).getFeaturesBySQL(sqlParam, function(serviceResult) { if (callback != undefined) { callback(serviceResult) } }); } Q.queryByBounds = function(title,datasetName, wsName, bounds, callback) { var paramsTmp = {}; paramsTmp.title = title; paramsTmp.dataSetName = datasetName; paramsTmp.dataSourceName = wsName; var geometryParam = new SuperMap.GetFeaturesByGeometryParameters({ datasetNames: [wsName + ":" + datasetName], geometry: bounds, spatialQueryMode: "INTERSECT" }); L.supermap .featureService(dataUrl) .getFeaturesByGeometry(geometryParam, function (serviceResult) { if (callback != undefined) { callback(serviceResult,paramsTmp) } }); } Q.queryByGeometry = function(title,distanceTmp,datasetName, wsName, geometry, callback) { var paramsTmp = {}; paramsTmp.title = title; paramsTmp.dataSetName = datasetName; paramsTmp.dataSourceName = wsName; if(distanceTmp == undefined){ distanceTmp = CONST_VALUES.QUERY_BufferDistance; } var bufferParam = new SuperMap.GetFeaturesByBufferParameters({ datasetNames: [wsName + ":" + datasetName], bufferDistance: distanceTmp, geometry: geometry }); L.supermap .featureService(dataUrl) .getFeaturesByBuffer(bufferParam, function (serviceResult) { if (callback != undefined) { callback(serviceResult,paramsTmp) } }); } function InitDraw() { // 创建一个名为“plottingLayer”的标绘图层。 plottingLayer = L.supermap.plotting.plottingLayer("plot", serverUrl); // 向map中添加标绘图层 plottingLayer.addTo(map); // 标绘控件 drawMapControl = L.supermap.plotting.drawControl(plottingLayer); drawMapControl.addTo(map); plotting = L.supermap.plotting.getControl(map, serverUrl); drawMapControl.on(SuperMap.Plot.Event.featureadded, function (event) { drawLayer = event.feature; var symbolType = drawLayer.symbolType; if (symbolType === SuperMap.Plot.SymbolType.ARBITRARYPOLYGONSYMBOL) { } else if (symbolType === SuperMap.Plot.SymbolType.CIRCLESYMBOL) { var latLngs = drawLayer.getLatLngs(); var pt = crs.project(latLngs[0]); var _Point = L.marker([pt.y, pt.x]); var dataSourceName = CONST_VALUES.GX_DataSourceName; var dataSetName = CONST_VALUES.GX_DataSetName; var bufferParam = new SuperMap.GetFeaturesByBufferParameters({ datasetNames: [dataSourceName + ":" + dataSetName], bufferDistance: CONST_VALUES.QUERY_BufferDistance, geometry: _Point }); // 判断点击的点是否在管线上 L.supermap .featureService(dataUrl) .getFeaturesByBuffer(bufferParam, function (result) {}); } else if (symbolType === SuperMap.Plot.SymbolType.RECTANGLESYMBOL) { } // 覆土分析 if(drawType == "FTFX"){ ftfxProcess(drawLayer); } else{ let lyrs = CONST_VALUES.GX_Datas; let lyrsSelect = '
'; let listStr = ""; for (let index = 0; index < lyrs.length; index++) { const lyr = lyrs[index]; let dom = listStr.replace('THENAME', lyr.name); dom = dom.replace('THETITLE', lyr.name); dom = dom.replace('THEID', lyr.id); dom = dom.replace('THEWS', lyr.dataSourceName); dom = dom.replace('THEDATASETNAME', lyr.dataSetName); lyrsSelect += dom; } lyrsSelect += '
'; layui.use('layer', function() { let layer = layui.layer; layer.open({ id: "panel-layerSelect", type: 1, area: ["300px", "220px"], btn: ['确定'], title: "请选择图层", skin: 'layui-ext-coolskin', content: lyrsSelect, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响 cancel: function(index, layero) { layer.close(index); }, yes: function(e) { var layers = $("#layers input:checked"); if (layers.length == 0) { layer.msg('请至少选择一个图层!', { icon: 7 }); return; } layer.close(e); // 矩形查询 if (symbolType === SuperMap.Plot.SymbolType.RECTANGLESYMBOL) { var rectangleTemp = L.Util.transform(drawLayer._bounds, L.CRS.EPSG4326, crs); var ptArrayTemp = rectangleTemp.geometry.coordinates[0]; var ptArray = Array(); for(var i = 0; i < ptArrayTemp.length; i++) { var tempArr = ptArrayTemp[i]; var ptTemp = Array(); ptTemp.push(tempArr[1]); ptTemp.push(tempArr[0]); ptArray.push(ptTemp); } var polygonTmp = L.polygon(ptArray); for (var index = 0; index < layers.length; index++) { let checked = layers[index].checked; if (!checked) continue; var ws = layers[index].attributes.dataSourceName.value; var dataSetName = layers[index].attributes.dataSetName.value; var thatsubtitleP = layers[index].title; Q.queryByBounds(thatsubtitleP, dataSetName, ws, polygonTmp, function(result,titleTmp) { if (result.result == undefined) return; panels.createResultPanelWithDataGrid({ subTitle: titleTmp.title, features: result.result.features.features, title: "范围查询结果", //count: count, dataSetName: titleTmp.dataSetName, dataSourceName: titleTmp.dataSourceName }, function() { //debugger; }); // 坐标系转换 // var result = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326); // // L.geoJSON(result, { // style:{color: "red"}, // onEachFeature: function (feature, layer) { // let attributes = ""; // let lyrs = CONST_VALUES.GX_Datas; // for (var index = 0; index < lyrs.length; index++) { // var lyr = lyrs[index]; // if(ws == lyr.dataSourceName && dataSetName == lyr.dataSetName){ // var showCols = lyr.cols; // if(showCols != undefined && showCols != ""){ // var colsArr = showCols.split(","); // for(var i = 0; i < colsArr.length; i++){ // var colArr = colsArr[i].split(":"); // let attValue = feature.properties[colArr[0]]; // let attr = colArr[1] + ":" + attValue + "
"; // attributes += attr; // } // } // break; // } // } // layer.bindPopup(attributes); // } // }).addTo(resultLayer); }); } } else if (symbolType === SuperMap.Plot.SymbolType.CIRCLESYMBOL) { var latLngs = drawLayer.getLatLngs(); var from = turf.point([latLngs[0].lng, latLngs[0].lat]); var to = turf.point([latLngs[1].lng, latLngs[1].lat]); var options = {units: 'kilometers'}; var jl11 = turf.distance(from, to, options) * 1000; var pt = crs.project(latLngs[0]); var _Point = L.marker([pt.y, pt.x]); var radius = Math.sqrt(Math.pow((latLngs[1].lng - latLngs[0].lng)*1000, 2) + Math.pow((latLngs[1].lat - latLngs[0].lat)*1000, 2)); for (var index = 0; index < layers.length; index++) { let checked = layers[index].checked; if (!checked) continue; var ws = layers[index].attributes.dataSourceName.value; var dataSetName = layers[index].attributes.dataSetName.value; var thatsubtitleP = layers[index].title; var bufferParam = new SuperMap.GetFeaturesByBufferParameters({ datasetNames: [ws + ":" + dataSetName], bufferDistance: jl11, geometry: _Point }); Q.queryByGeometry(thatsubtitleP, jl11, dataSetName, ws, _Point, function(result,titleTmp) { if (result.result == undefined) return; panels.createResultPanelWithDataGrid({ subTitle: titleTmp.title, features: result.result.features.features, title: "范围查询结果", //count: count, dataSetName: titleTmp.dataSetName, dataSourceName: titleTmp.dataSourceName }, function() { }); // 坐标系转换 // var result = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326); // // L.geoJSON(result, { // style:{color: "red"}, // onEachFeature: function (feature, layer) { // let attributes = ""; // let lyrs = CONST_VALUES.GX_Datas; // for (var index = 0; index < lyrs.length; index++) { // var lyr = lyrs[index]; // if(ws == lyr.dataSourceName && dataSetName == lyr.dataSetName){ // var showCols = lyr.cols; // if(showCols != undefined && showCols != ""){ // var colsArr = showCols.split(","); // for(var i = 0; i < colsArr.length; i++){ // var colArr = colsArr[i].split(":"); // let attValue = feature.properties[colArr[0]]; // let attr = colArr[1] + ":" + attValue + "
"; // attributes += attr; // } // } // break; // } // } // layer.bindPopup(attributes); // } // }).addTo(resultLayer); }) } } } }); layui.use(['form'], function() { let form = layui.form; form.render(); }); }); } drawMapControl.handler.disable(); }); } function polygonQueryProcess(subtitle, dataSetName, ws, bounds) { Q.queryByBounds(subtitle, dataSetName, ws, bounds, function(result,titleTmp) { if (result.result == undefined) return; panels.createResultPanelWithDataGrid({ subTitle: titleTmp.title, features: result.result.features.features, title: "范围查询结果", //count: count, dataSetName: titleTmp.dataSetName, dataSourceName: titleTmp.dataSourceName }, function() { }); // 坐标系转换 var result = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326); L.geoJSON(result, { style:{color: "red"}, onEachFeature: function (feature, layer) { let attributes = ""; let lyrs = CONST_VALUES.GX_Datas; for (var index = 0; index < lyrs.length; index++) { var lyr = lyrs[index]; if(ws == lyr.dataSourceName && dataSetName == lyr.dataSetName){ var showCols = lyr.cols; if(showCols != undefined && showCols != ""){ var colsArr = showCols.split(","); for(var i = 0; i < colsArr.length; i++){ var colArr = colsArr[i].split(":"); let attValue = feature.properties[colArr[0]]; let attr = colArr[1] + ":" + attValue + "
"; attributes += attr; } } break; } } layer.bindPopup(attributes); } }).addTo(resultLayer); }); } // 范围查询 function drawPolygon() { drawType = "drawPolygon"; var handler = new L.Draw.Polygon(map); handler.enable(); map.on(L.Draw.Event.CREATED,function (e) { if (drawType != "drawPolygon") { return; } //将图形信息传给下一步,进行查询功能 var locationArray = e.layer.getLatLngs()[0]; var polygonArray = Array(); var midArray = Array(); var polygonArrayTmp = Array(); var midArrayTmp = Array(); var firstX = locationArray[0].lat; var firstY = locationArray[0].lng; for (var i = 0; i < locationArray.length; i++) { var pt2 = crs.project(locationArray[i]); var x = locationArray[i].lat; var y = locationArray[i].lng; midArray.push(x); midArray.push(y); polygonArray.push(midArray); midArray = Array(); midArrayTmp.push(pt2.y); midArrayTmp.push(pt2.x); polygonArrayTmp.push(midArrayTmp); midArrayTmp = Array(); } midArray.push(firstX); midArray.push(firstY); polygonArray.push(midArray); var pt2 = crs.project(locationArray[0]); midArrayTmp.push(pt2.y); midArrayTmp.push(pt2.x); polygonArrayTmp.push(midArrayTmp); var polygonTmp = L.polygon(polygonArrayTmp); var polygon = L.polygon(polygonArray, {color: "#00FF00"}); resultLayer.addLayer(polygon); let lyrs = CONST_VALUES.GX_Datas; //debugger; let lyrsSelect = '
'; let listStr = ""; for (let index = 0; index < lyrs.length; index++) { const lyr = lyrs[index]; let dom = listStr.replace('THENAME', lyr.name); dom = dom.replace('THETITLE', lyr.name); dom = dom.replace('THEID', lyr.id); dom = dom.replace('THEWS', lyr.dataSourceName); dom = dom.replace('THEDATASETNAME', lyr.dataSetName); lyrsSelect += dom; } lyrsSelect += '
'; layui.use('layer', function() { let layer = layui.layer; layer.open({ id: "panel-layerSelect", type: 1, area: ["300px", "220px"], btn: ['确定'], title: "请选择图层", skin: 'layui-ext-coolskin', content: lyrsSelect, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响 cancel: function(index, layero) { layer.close(index); }, yes: function(e) { var layers = $("#layers input:checked"); if (layers.length == 0) { layer.msg('请至少选择一个图层!', { icon: 7 }); return; } layer.close(e); for (var index = 0; index < layers.length; index++) { let checked = layers[index].checked; if (!checked) continue; var ws = layers[index].attributes.dataSourceName.value; var dataSetName = layers[index].attributes.dataSetName.value; var thatsubtitleP = layers[index].title; Q.queryByBounds(thatsubtitleP,dataSetName, ws, polygonTmp, function(result,titleTmp) { if (result.result == undefined) return; panels.createResultPanelWithDataGrid({ subTitle: titleTmp.title, features: result.result.features.features, title: "范围查询结果", //count: count, dataSetName: titleTmp.dataSetName, dataSourceName: titleTmp.dataSourceName }, function() { //debugger; }); // 坐标系转换 // var result = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326); // // L.geoJSON(result, { // style:{color: "red"}, // onEachFeature: function (feature, layer) { // let attributes = ""; // let lyrs = CONST_VALUES.GX_Datas; // for (var index = 0; index < lyrs.length; index++) { // var lyr = lyrs[index]; // if(ws == lyr.dataSourceName && dataSetName == lyr.dataSetName){ // var showCols = lyr.cols; // if(showCols != undefined && showCols != ""){ // var colsArr = showCols.split(","); // for(var i = 0; i < colsArr.length; i++){ // var colArr = colsArr[i].split(":"); // let attValue = feature.properties[colArr[0]]; // let attr = colArr[1] + ":" + attValue + "
"; // attributes += attr; // } // } // break; // } // } // layer.bindPopup(attributes); // } // }).addTo(resultLayer); }); } } }); layui.use(['form'], function() { let form = layui.form; form.render(); }); }); }); } function drawCircle() { drawType = ""; setDefualtStyle(); drawMapControl.handler.disable(); drawMapControl.handler.libID = 0; drawMapControl.handler.code = 29; drawMapControl.handler.serverUrl = serverUrl; drawMapControl.handler.enable(); } function drawRectangle() { drawType = ""; setDefualtStyle(); drawMapControl.handler.disable(); drawMapControl.handler.libID = 0; drawMapControl.handler.code = 26; drawMapControl.handler.serverUrl = serverUrl; drawMapControl.handler.enable(); } //设置选择区域的线色 function setDefualtStyle() { var defualtStyle = plotting.getDefaultStyle(); defualtStyle.defaultFlag = true; defualtStyle.lineColor = "#00FF00"; defualtStyle.fillSymbolID = 0; defualtStyle.fillColor = "#00FF00"; } function processCompleted(result,selectTitle,gx) { var gxArr = gx.split(":"); panels.createResultPanelWithDataGrid({ subTitle: selectTitle, features: result.features, title: "按范围查询结果", count: result.features.length, dataSetName: gxArr[1], dataSourceName: gxArr[0] }, function() { }); } function toggleFullScreen() { var el = document.body; var isFullscreen = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen; if (!isFullscreen) { //进入全屏,多重短路表达式 (el.requestFullscreen && el.requestFullscreen()) || (el.mozRequestFullScreen && el.mozRequestFullScreen()) || (el.webkitRequestFullscreen && el.webkitRequestFullscreen()) || (el.msRequestFullscreen && el.msRequestFullscreen()); } else { //退出全屏,三目运算符 document.exitFullscreen ? document.exitFullscreen() : document.mozCancelFullScreen ? document.mozCancelFullScreen() : document.webkitExitFullscreen ? document.webkitExitFullscreen() : ''; } } panels.createResultPanelWithChart = function(xAxis, groupBy, data, title, subTitle, xTypeName, yTypeName, typeOfECharts, callback) { layui.use('layer', function() { let chart; let resizeCb = function(layerno) { if (chart == undefined) return; var autoHeight = $("#panel-result").height() - 100; chart.getDom().style.height = autoHeight + "px"; chart.getDom().childNodes[0].style.height = autoHeight + "px"; chart.getDom().childNodes[0].childNodes[0].setAttribute("height",autoHeight); chart.getDom().childNodes[0].childNodes[0].style.height = autoHeight + "px"; var autoWidth = $("#panel-result").width(); chart.getDom().style.width = autoWidth + "px"; chart.getDom().childNodes[0].style.width = autoWidth + "px"; chart.getDom().childNodes[0].childNodes[0].setAttribute("width",autoWidth); chart.getDom().childNodes[0].childNodes[0].style.width = autoWidth + "px"; chart.resize(); } var layer = layui.layer; panels.createPanelBase(layer,title, resizeCb); chart = panels.createChart(xAxis, groupBy,data, title, subTitle, xTypeName, yTypeName, typeOfECharts); panels.createChartPages(xAxis, groupBy, data); if (callback != undefined) { callback(); } }); } panels.createChart = function(xAxis, groupBy, data, title, subTitle, xTypeName, yTypeName, typeOfECharts) { if (data.length == 0) return; let xAxisData = []; for (let val in data) { xAxisData.push(data[val][groupBy]) } let seriesData = []; for (let i = 0; i < xAxis.length; i++) { let series = {}; series.name = xAxis[i]; series.type = typeOfECharts; series.data = []; for (let j = 0; j < data.length; j++) { series.data.push(parseFloat(data[j][xAxis[i]])); } seriesData.push(series); } const chartDivID = "statistics-Chart"; const chartDom = "
"; let tabControl = "
" + "" + "
"; let tabControlID = utils.guid(); tabControl = tabControl.replace('THETABCONTROLID', tabControlID); if ($('div[lay-filter="resultTabControl"]').length == 0) { $(tabControl).appendTo($("#panel-result")); } layui.use('element', function() { let element = layui.element; element.render(); let tabID = utils.guid(); element.tabAdd('resultTabControl', { title: "统计图", content: chartDom //支持传入html , id: tabID }); }); const myChart = echarts.init(document.getElementById("statistics-Chart"), null); // 指定图表的配置项和数据 const option = { tooltip: {}, legend: { bottom: '0', left: 'right', data: xAxis, textStyle: { color: "#fffffb" } }, toolbox: { feature: { magicType: { type: ['line', 'bar'] }, saveAsImage: { pixelRatio: 2 } }, iconStyle: { color: "#fffffb" } }, xAxis: { data: xAxisData, name: xTypeName, axisLabel: { interval: 0, rotate: 30, color: "#fffffb", formatter: function(value, index) { return value /* + 'mm'*/ ; } } }, yAxis: { axisLine: { onZero: false, lineStyle: { color: "#fffffb" } }, name: yTypeName }, series: seriesData }; // 使用刚指定的配置项和数据显示图表。 myChart.setOption(option); var autoHeight = $("#panel-result").height() - 100; myChart.getDom().style.height = autoHeight + "px"; myChart.getDom().childNodes[0].style.height = autoHeight + "px"; myChart.getDom().childNodes[0].childNodes[0].setAttribute("height",autoHeight); myChart.getDom().childNodes[0].childNodes[0].style.height = autoHeight + "px"; var autoWidth = $("#panel-result").width(); myChart.getDom().style.width = autoWidth + "px"; myChart.getDom().childNodes[0].style.width = autoWidth + "px"; myChart.getDom().childNodes[0].childNodes[0].setAttribute("width",autoWidth); myChart.getDom().childNodes[0].childNodes[0].style.width = autoWidth + "px"; myChart.resize(); const thisTitle = $('.layui-layer-title'); thisTitle.addClass("layui-layer-title-transparent"); return myChart; } panels.createChartPages = function(xAxis, groupBy, data) { if (data.length == 0) return; let tableNew = "
"; const tableNewID = utils.guid(); while (tableNew.indexOf('THETABLEID') > -1) tableNew = tableNew.replace('THETABLEID', tableNewID); let cols = [{ field: groupBy, title: groupBy, sort: true }]; for (let i = 0; i < xAxis.length; i++) { cols.push({ field: xAxis[i], title: xAxis[i], sort: true }); } let datas = data; let tabControl = "
" + "" + "
"; let tabControlID = utils.guid(); tabControl = tabControl.replace('THETABCONTROLID', tabControlID); if ($('div[lay-filter="resultTabControl"]').length == 0) { $(tabControl).appendTo($("#panel-result")); } layui.use('element', function() { let element = layui.element; element.render(); let tabID = utils.guid(); element.tabAdd('resultTabControl', { title: "统计报表", content: tableNew //支持传入html , id: tabID }); layui.use('table', function() { let table = layui.table; table.render({ elem: '#' + tableNewID, data: datas, page: true, "lay-size": 'sm', limit: 6, done: function (res, curr, count){ $("table").css("width", "100%"); }, cols: [cols] }); }); element.tabChange('resultTabControl', tabID); const thisTitle = $('.layui-layer-title'); thisTitle.addClass("layui-layer-title-transparent"); }); } function dmfx(){ map.off('click'); //map.off('dblclick'); $("#tips").css('display', 'block'); var isFirstPoint = true; //判断是否是起始点 var latLngTemp = null;//存储上一点击点临时变量 var resultDis = 0; //总距 map.on('click', function(ev) { TempLayer.clearLayers(); $("#tips").css('display', 'none'); var polyLine; if(isFirstPoint) { L.marker([ev.latlng.lat, ev.latlng.lng]).addTo(resultLayer); //起始点 latLngTemp = ev.latlng; //存储上一点击点 isFirstPoint = false; } else { if(!latLngTemp.equals(ev.latlng)) { //避免出现结束双击,导致距离为0 L.marker([ev.latlng.lat, ev.latlng.lng]).addTo(resultLayer); //终点 map.off('click'); map.off('mousemove'); polyLine = L.polyline([ //与上一点连线 [latLngTemp.lat, latLngTemp.lng], [ev.latlng.lat, ev.latlng.lng] ], { color: "#00FF00" }); resultLayer.addLayer(polyLine); // 地图上画的线 var line1 = turf.lineString([[latLngTemp.lng, latLngTemp.lat], [ev.latlng.lng, ev.latlng.lat]]); var pt1 = crs.project(latLngTemp); var pt2 = crs.project(ev.latlng); var polyLineTemp = L.polyline([ //与上一点连线 [pt1.y, pt1.x], [pt2.y, pt2.x] ]); var dataSourceName = CONST_VALUES.GX_DataSourceName; var dataSetName = CONST_VALUES.GX_DataSetName; // 查询管线两端点对应的数据信息 var geometryParam = new SuperMap.GetFeaturesByGeometryParameters({ datasetNames: [dataSourceName + ":" + dataSetName], geometry: polyLineTemp, spatialQueryMode: "INTERSECT" }); L.supermap .featureService(dataUrl) .getFeaturesByGeometry(geometryParam, function (serviceResult) { // 坐标系转换 var result = L.Util.transform(serviceResult.result.features, crs, L.CRS.EPSG4326); L.geoJSON(result, { style:{color: "red"}, onEachFeature: function (feature, layer) { let attributes = ""; let lyrs = CONST_VALUES.GX_Datas; for (var index = 0; index < lyrs.length; index++) { var lyr = lyrs[index]; if(dataSourceName == lyr.dataSourceName && dataSetName == lyr.dataSetName){ var showCols = lyr.cols; if(showCols != undefined && showCols != ""){ var colsArr = showCols.split(","); for(var i = 0; i < colsArr.length; i++){ var colArr = colsArr[i].split(":"); let attValue = feature.properties[colArr[0]]; let attr = colArr[1] + ":" + attValue + "
"; attributes += attr; } } break; } } layer.bindPopup(attributes); } }).addTo(resultLayer); if(result.features.length>0){ dmfxProcess(line1,result); } }); } } }); map.on("mousemove", function(ev) { if(latLngTemp == null){ return } TempLayer.clearLayers(); var TempLine = L.polyline([ //虚线临时线段 [latLngTemp.lat, latLngTemp.lng], [ev.latlng.lat, ev.latlng.lng] ], { color: "red", dashArray: "5,5" }); TempLayer.addLayer(TempLine); }); } function dmfxProcess(drawLint,result){ var pts = ''; for(var i = 0; i < result.features.length; i++) { var feature = result.features[i]; var coordinates = feature.geometry.coordinates; var QSDH = feature.properties["QSDH"]; // 起始点号 var ZDDH = feature.properties["ZDDH"]; // 终点点号 if(i < result.features.length-1){ pts += "'" + QSDH + "','" + ZDDH + "',"; } else{ pts += "'" + QSDH + "','" + ZDDH + "'"; } } var sqlTemp = "BSM in (" + pts + ")"; var sqlParam = new SuperMap.GetFeaturesBySQLParameters({ queryParameter: { name: CONST_VALUES.JD_DataSetName + "@" + CONST_VALUES.JD_DataSourceName, attributeFilter: sqlTemp }, datasetNames: [CONST_VALUES.JD_DataSourceName + ":" + CONST_VALUES.JD_DataSetName] }); L.supermap.featureService(dataUrl).getFeaturesBySQL(sqlParam, function (serviceResult) { if(serviceResult.result.features.features.length > 0){ var resultData = L.Util.transform(serviceResult.result.features, crs, L.CRS.EPSG4326); var allData = new Array(); var allMaxGC = 0, allMinGC = 0; var preX = undefined; var preY = undefined; for(var i = 0; i < result.features.length; i++){ var feature = result.features[i]; var coordinates = feature.geometry.coordinates; var gdbh = feature.properties["BSM"]; // 管段编号 var QSDH = feature.properties["QSDH"]; // 起始点号 var ZDDH = feature.properties["ZDDH"]; // 终点点号 var gj = feature.properties["GJ"]; // 管径 var smid = feature.properties["SMID"]; // 地图上划线查询到的管线 var line2 = turf.lineString([[coordinates[0][0], coordinates[0][1]], [coordinates[1][0], coordinates[1][1]]]); // 交叉点 var intersects = turf.lineIntersect(drawLint, line2); var pt1Data = undefined; var pt2Data = undefined; for(var j = 0; j < resultData.features.length; j++){ var bsm = resultData.features[j].properties["BSM"]; if(bsm == QSDH){ pt1Data = resultData.features[j]; } else if(bsm == ZDDH){ pt2Data = resultData.features[j]; } if(pt1Data != undefined && pt2Data != undefined){ break; } } if(pt1Data == undefined || pt2Data == undefined){ continue; } var dmgcPT1 = pt1Data.properties["DMGC"] * 1; // 地面高程 var msPT1 = pt1Data.properties["MS"] * 1; // 埋深 var xPT1 = pt1Data.geometry.coordinates[0]; // x坐标 var yPT1 = pt1Data.geometry.coordinates[1]; // y坐标 var dmgcPT2 = pt2Data.properties["DMGC"] * 1; // 地面高程 var msPT2 = pt2Data.properties["MS"] * 1; // 埋深 var xPT2 = pt2Data.geometry.coordinates[0]; // x坐标 var yPT2 = pt2Data.geometry.coordinates[1]; // y坐标 var xPtTmp = intersects.features[0].geometry.coordinates[0]; var yPtTmp = intersects.features[0].geometry.coordinates[1] var dmgc = undefined; // 地面高程 var ms = undefined; // 埋深 var gxgc = undefined; // 管线高程 var maxGC = undefined,minGC = undefined,jl=0; if(dmgcPT1 == dmgcPT2){ dmgc = dmgcPT1; maxGC = dmgc + 1; } else if (dmgcPT1 > dmgcPT2){ maxGC = dmgcPT1 + 1; dmgc = dmgcPT2 + (dmgcPT1 - dmgcPT2) * (Math.sqrt(Math.pow((xPtTmp - xPT2), 2) + Math.pow((yPtTmp - yPT2), 2))) / (Math.sqrt(Math.pow((xPT1 - xPT2), 2) + Math.pow((yPT1 - yPT2), 2))); } else { maxGC = dmgcPT2 + 1; dmgc = dmgcPT1 + (dmgcPT2 - dmgcPT1) * (Math.sqrt(Math.pow((xPtTmp - xPT1), 2) + Math.pow((yPtTmp - yPT1), 2))) / (Math.sqrt(Math.pow((xPT2 - xPT1), 2) + Math.pow((yPT2 - yPT1), 2))); } if(msPT1 == msPT2){ ms = msPT1; } else if(msPT1 > msPT2){ ms = msPT2 + (msPT1 - msPT2) * (Math.sqrt(Math.pow((xPtTmp - xPT2), 2) + Math.pow((yPtTmp - yPT2), 2))) / (Math.sqrt(Math.pow((xPT1 - xPT2), 2) + Math.pow((yPT1 - yPT2), 2))); } else{ ms = msPT1 + (msPT2 - msPT1) * (Math.sqrt(Math.pow((xPtTmp - xPT1), 2) + Math.pow((yPtTmp - yPT1), 2))) / (Math.sqrt(Math.pow((xPT2 - xPT1), 2) + Math.pow((yPT2 - yPT1), 2))); } gxgc = dmgc.toFixed(2) - ms.toFixed(2); minGC = gxgc - 1; var markerTemp = L.marker([yPtTmp, xPtTmp]).addTo(resultLayer); var content = "地面高程(M):" + dmgc.toFixed(2) + "
管线高程(M):" + gxgc.toFixed(2) + "
埋深(M):" + ms.toFixed(2) + "
管径(MM):" + gj; markerTemp.bindPopup(content).openPopup(markerTemp.getLatLng()); //drawDmfx(dmgc.toFixed(2),gxgc.toFixed(2),ms.toFixed(2),gj,jl,maxGC.toFixed(2),minGC.toFixed(2),i); if(allMaxGC < maxGC){ allMaxGC = maxGC.toFixed(2); } if(allMinGC == 0 || allMinGC > minGC){ allMinGC = minGC.toFixed(2); } if(preX != undefined && preY != undefined){ var from = turf.point([preX, preY]); var to = turf.point([xPtTmp, yPtTmp]); var options = {units: 'kilometers'}; jl = turf.distance(from, to, options) * 1000; } preX = xPtTmp; preY = yPtTmp; var entityData = {}; entityData.smid = smid; entityData.gdbh = gdbh; entityData.dmgc = dmgc.toFixed(2); entityData.dmgc = dmgc.toFixed(2); entityData.gxgc = gxgc.toFixed(2); entityData.ms = ms.toFixed(2); entityData.gj = gj; entityData.jl = jl.toFixed(2); entityData.maxGC = maxGC.toFixed(2); entityData.minGC = minGC.toFixed(2); allData.push(entityData); } drawDmfx(allData,allMaxGC,allMinGC); } }); } // 断面分析图 function drawDmfx(allData,allMaxGC,allMinGC){ let lyrsSelect = '
管线横断面图
'; lyrsSelect += ''; lyrsSelect += '
管线纵刨面图
'; lyrsSelect += '
'; for(var i = 0; i < allData.length; i++){ lyrsSelect += '
' + allData[i].gdbh + '
'; } lyrsSelect += '
'; layui.use('layer', function() { let layer = layui.layer; layer.open({ id: "panel-drawDmfx", type: 1, area: ["802px", "750px"], title: "城市地下管线断面分析", skin: 'layui-ext-coolskin', content: lyrsSelect, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响 cancel: function (index, layero) { layer.close(index); } }); var canvas = document.getElementById('tutorial'); drawCanvas(canvas,allData,allMaxGC,allMinGC); layui.use(['form'], function() { let form = layui.form; form.render(); }); }); } // 管线纵刨面图 function drawZpm(smid){ let lyrsSelect = ''; layui.use('layer', function() { let layer = layui.layer; layer.open({ id: "panel-drawZpm", type: 1, area: ["802px", "750px"], title: "城市地下管线纵刨面图", skin: 'layui-ext-coolskin', content: lyrsSelect, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响 cancel: function (index, layero) { layer.close(index); } }); var canvas = document.getElementById('tutorialZpm'); drawCanvasZpm(canvas,smid); layui.use(['form'], function() { let form = layui.form; form.render(); }); }); } // 横断面 function drawCanvas(canvas,allData,allMaxGC,allMinGC){ // dmgc,gxgc,ms,gj,jl,maxGC,minGC if(!canvas.getContext) return; var ctx = canvas.getContext("2d"); var start = 600; // 绘制下方表格 drawTable(ctx,20,start,30, 0); // 绘制刻度线 var rs = drawScale(ctx,allMaxGC,allMinGC); // 绘制管线及数据dmgc,gxgc,gxms,gj,jl,xyRs,maxGC,minGC drawGXData(ctx, rs, allData, allMaxGC,allMinGC); } // 纵剖面 function drawCanvasZpm(canvas,smid){ if(!canvas.getContext) return; var sqlParam = new SuperMap.GetFeaturesBySQLParameters({ queryParameter: { name: CONST_VALUES.GX_DataSetName + "@" + CONST_VALUES.GX_DataSourceName, attributeFilter: "SMID = " + smid }, datasetNames: [CONST_VALUES.GX_DataSourceName + ":" + CONST_VALUES.GX_DataSetName] }); L.supermap.featureService(dataUrl).getFeaturesBySQL(sqlParam, function (serviceResult) { if (serviceResult.result.features.features.length > 0) { var feature = serviceResult.result.features.features[0]; var QSDH = feature.properties["QSDH"]; // 起始点号 var ZDDH = feature.properties["ZDDH"]; // 终点点号 var gj = feature.properties["GJ"]; // 管径 var cd = (feature.properties["CD"] * 1).toFixed(2); // 长度 var sqlTemp = "BSM in ('" + QSDH + "','" + ZDDH + "')"; var sqlParamPt = new SuperMap.GetFeaturesBySQLParameters({ queryParameter: { name: CONST_VALUES.JD_DataSetName + "@" + CONST_VALUES.JD_DataSourceName, attributeFilter: sqlTemp }, datasetNames: [ CONST_VALUES.JD_DataSourceName + ":" + CONST_VALUES.JD_DataSetName] }); L.supermap.featureService(dataUrl).getFeaturesBySQL(sqlParamPt, function (serviceResult) { if (serviceResult.result.features.features.length > 1) { var feature0 = serviceResult.result.features.features[0]; var feature1 = serviceResult.result.features.features[1]; var featureQ,featureZ; if(QSDH == feature0.properties["BSM"]){ featureQ = feature0; featureZ = feature1; } else{ featureQ = feature1; featureZ = feature0; } var dmgcQ = (featureQ.properties["DMGC"] * 1).toFixed(2); // 起点地面高程 var gxmsQ = (featureQ.properties["MS"] * 1).toFixed(2); // 起点埋深 var dmgcZ = (featureZ.properties["DMGC"] * 1).toFixed(2); // 终点地面高程 var gxmsZ = (featureZ.properties["MS"] * 1).toFixed(2); // 终点埋深 var gdgcQ = (dmgcQ-gxmsQ).toFixed(2); // 起点管顶高程 var gdgcZ = (dmgcZ-gxmsZ).toFixed(2); // 终点管顶高程 var maxGC = 0,minGC = 0; if(dmgcQ >= dmgcZ){ maxGC = (dmgcQ * 1 + 1).toFixed(2); } else{ maxGC = (dmgcZ * 1 + 1).toFixed(2); } if(gdgcQ >= gdgcZ){ minGC = (gdgcZ * 1 - 1).toFixed(2); } else{ minGC = (gdgcQ * 1 - 1).toFixed(2); } var ctx = canvas.getContext("2d"); var start = 600; // 绘制下方表格 drawTable(ctx,20,start,30, 1); // 绘制刻度线 var xyRs = drawScale(ctx,maxGC,minGC); drawGXZpmData(ctx,dmgcQ,gxmsQ,gdgcQ,dmgcZ,gxmsZ,gdgcZ,gj,cd,xyRs,maxGC,minGC); } }); } }); } // 绘制下方表格 function drawTable(ctx,startX,startY,rowHight,type){ for(var i = 0; i<5;i++) { var y = startY - (i + 1 ) * rowHight; ctx.beginPath(); //新建一条path ctx.moveTo(startX, y); //把画笔移动到指定的坐标 ctx.lineTo(780, y); //绘制一条从当前位置到指定坐标的直线. ctx.strokeStyle = "white"; //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做 ctx.closePath(); ctx.stroke(); //绘制路径。 ctx.font = "18px Arial"; ctx.fillStyle ="white"; var content = ""; switch(i){ case 4: content = "地面高程(M)"; break; case 3: content = "管线高程(M)"; break; case 2: content = "管线埋深(M)"; break; case 1: content = "管 径(MM)"; break; case 0: if(type==0){ content = "距 离(M)"; }else{ content = "长 度(M)"; } break; } ctx.fillText(content, startX + 10 , y+(rowHight*4/5)); } ctx.beginPath(); //新建一条path ctx.moveTo(startX, 450); //把画笔移动到指定的坐标 ctx.lineTo(startX, 800); //绘制一条从当前位置到指定坐标的直线. //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做 ctx.closePath(); ctx.stroke(); //绘制路径。 ctx.beginPath(); //新建一条path ctx.moveTo(780, 450); //把画笔移动到指定的坐标 ctx.lineTo(780, 800); //绘制一条从当前位置到指定坐标的直线. //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做 ctx.closePath(); ctx.stroke(); //绘制路径。 } // 绘制刻度线 function drawScale(ctx,maxGC,minGC){ ctx.beginPath(); //新建一条path ctx.moveTo(150, 20); //把画笔移动到指定的坐标 ctx.lineTo(150, 800); //绘制一条从当前位置到指定坐标的直线. //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做 ctx.closePath(); ctx.stroke(); //绘制路径。 var rs = []; for(var i = 0; i<5;i++){ var y = 70 + i*70; ctx.beginPath(); //新建一条path ctx.moveTo(150, y); //把画笔移动到指定的坐标 ctx.lineTo(150-10, y); //绘制一条从当前位置到指定坐标的直线. //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做 ctx.closePath(); ctx.stroke(); //绘制路径。 if(i==0 || i == 4){ rs.push(y); } ctx.font = "18px Arial" var content = maxGC - i*(maxGC-minGC)/4; ctx.fillText(content.toFixed(2), 150 - 60 , y+20); } return rs; } // 绘制管线及数据 function drawGXData(ctx, xyRs, allData, maxGC, minGC){ var dataNum = allData.length; for(var i = 0; i < dataNum; i++){ var entityData = allData[i]; var x = 150 + (800 - 150 - 20) / (dataNum + 1) * (i+1); var gdbh = entityData.gdbh; var dmgc = entityData.dmgc; var gxgc = entityData.gxgc; var gxms = entityData.ms; var gj = entityData.gj; var jl = entityData.jl; var y = xyRs[1] - (gxgc-minGC)*(xyRs[1]-xyRs[0])/(maxGC-minGC); var pyl = gj / 10 / 2; ctx.beginPath(); ctx.arc(x,y+pyl,pyl,0,2*Math.PI); ctx.setLineDash([10, 0]); // [实线长度, 间隙长度] ctx.strokeStyle = "#ed1941"; ctx.stroke(); ctx.beginPath(); //新建一条path ctx.moveTo(x, y+pyl*2); //把画笔移动到指定的坐标 ctx.lineTo(x, 800); //绘制一条从当前位置到指定坐标的直线. ctx.setLineDash([10, 5]); // [实线长度, 间隙长度] ctx.strokeStyle = "#2AC2FC"; //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做 ctx.closePath(); ctx.stroke(); //绘制路径。 ctx.fillText(gdbh, x, y - 5); ctx.fillText(dmgc, x + 5, 450+25); ctx.fillText(gxgc, x + 5, 450+55); ctx.fillText(gxms, x + 5, 450+85); ctx.fillText(gj, x + 5, 450+115); ctx.fillText(jl == 0 ? "" : jl, x + 5 , 450+145); } } // 绘制管线纵剖面图及数据 function drawGXZpmData(ctx,dmgcQ,gxmsQ,gdgcQ,dmgcZ,gxmsZ,gdgcZ,gj,cd,xyRs,maxGC,minGC){ var xQ = 200,xZ = 730; var yGDQ = xyRs[1] - (gdgcQ-minGC)*(xyRs[1]-xyRs[0])/(maxGC-minGC); var yGDZ = xyRs[1] - (gdgcZ-minGC)*(xyRs[1]-xyRs[0])/(maxGC-minGC); var yDMQ = xyRs[1] - (dmgcQ-minGC)*(xyRs[1]-xyRs[0])/(maxGC-minGC); var yDMZ = xyRs[1] - (dmgcZ-minGC)*(xyRs[1]-xyRs[0])/(maxGC-minGC); var pyl = gj / 10; // 画管线上沿 ctx.beginPath(); //新建一条path ctx.moveTo(xQ, yGDQ); //把画笔移动到指定的坐标 ctx.lineTo(xZ, yGDZ); //绘制一条从当前位置到指定坐标的直线. //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做 ctx.closePath(); ctx.stroke(); //绘制路径。 // 画管线下沿 ctx.beginPath(); //新建一条path ctx.moveTo(xQ, yGDQ + pyl); //把画笔移动到指定的坐标 ctx.lineTo(xZ, yGDZ + pyl); //绘制一条从当前位置到指定坐标的直线. //ctx.strokeStyle = "#009ad6"; //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做 ctx.closePath(); ctx.stroke(); //绘制路径。 // 画地面线 ctx.beginPath(); //新建一条path ctx.moveTo(xQ, yDMQ); //把画笔移动到指定的坐标 ctx.lineTo(xZ, yDMZ); //绘制一条从当前位置到指定坐标的直线. ctx.strokeStyle = "#2AC2FC"; //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做 ctx.closePath(); ctx.stroke(); //绘制路径。 // 画起点竖线 ctx.beginPath(); //新建一条path ctx.moveTo(xQ, yDMQ); //把画笔移动到指定的坐标 ctx.lineTo(xQ, yGDQ + pyl); //绘制一条从当前位置到指定坐标的直线. ctx.strokeStyle = "#2AC2FC"; //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做 ctx.closePath(); ctx.stroke(); //绘制路径。 // 画终点竖线 ctx.beginPath(); //新建一条path ctx.moveTo(xZ, yDMZ); //把画笔移动到指定的坐标 ctx.lineTo(xZ, yGDZ + pyl); //绘制一条从当前位置到指定坐标的直线. ctx.strokeStyle = "#2AC2FC"; //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做 ctx.closePath(); ctx.stroke(); //绘制路径。 // 起点 ctx.fillText(dmgcQ, xQ , 450+25); ctx.fillText(gdgcQ, xQ , 450+55); ctx.fillText(gxmsQ, xQ , 450+85); // 终点 ctx.fillText(dmgcZ, xZ - 40 , 450+25); ctx.fillText(gdgcZ, xZ - 40 , 450+55); ctx.fillText(gxmsZ, xZ - 40 , 450+85); ctx.fillText(gj, 460 , 450+115); ctx.fillText(cd == 0 ? "" : cd, 460 , 450+145); } // 碰撞分析(包括垂直净距和水平净距分析) function pzfx(){ map.on('click', function (evt) { var infoX = evt.containerPoint.x; var infoY = evt.containerPoint.y; var winX = evt.target._size.x; var winY = evt.target._size.y; var pt = crs.project(evt.latlng); var _Point = L.marker([pt.y, pt.x]); var dataSourceName = CONST_VALUES.GX_DataSourceName; var dataSetName = CONST_VALUES.GX_DataSetName; var bufferParam = new SuperMap.GetFeaturesByBufferParameters({ datasetNames: [dataSourceName + ":" + dataSetName], bufferDistance: CONST_VALUES.QUERY_BufferDistance, geometry: _Point }); // 判断点击的点是否在管线上 L.supermap .featureService(dataUrl) .getFeaturesByBuffer(bufferParam, function (result) { if(result.result.features.features.length > 0){ // 坐标系转换 var result = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326); L.geoJSON(result, { style:{color: "#ef5b9c"}, onEachFeature: function (feature, layer) { let attributes = ""; let lyrs = CONST_VALUES.GX_Datas; for (var index = 0; index < lyrs.length; index++) { var lyr = lyrs[index]; if(dataSourceName == lyr.dataSourceName && dataSetName == lyr.dataSetName){ var showCols = lyr.cols; if(showCols != undefined && showCols != ""){ var colsArr = showCols.split(","); for(var i = 0; i < colsArr.length; i++){ var colArr = colsArr[i].split(":"); let attValue = feature.properties[colArr[0]]; let attr = colArr[1] + ":" + attValue + "
"; attributes += attr; } } break; } } layer.bindPopup(attributes); } }).addTo(resultLayer); var feature = result.features[0]; var sourceCoordinates = feature.geometry.coordinates; var QSDH = feature.properties["QSDH"]; // 起始点号 var ZDDH = feature.properties["ZDDH"]; // 终点点号 var gj = feature.properties["GJ"]; // 管径 var gxSmid = feature.properties["SMID"]; var bsm = feature.properties["BSM"]; var fldm = feature.properties["FLDM"]; var sqlTemp = "BSM in ('" + QSDH + "','" + ZDDH + "')"; var sqlParamPt = new SuperMap.GetFeaturesBySQLParameters({ queryParameter: { name: CONST_VALUES.JD_DataSetName + "@" + CONST_VALUES.JD_DataSourceName, attributeFilter: sqlTemp }, datasetNames: [ CONST_VALUES.JD_DataSourceName + ":" + CONST_VALUES.JD_DataSetName] }); L.supermap.featureService(dataUrl).getFeaturesBySQL(sqlParamPt, function (serviceResult) { if (serviceResult.result.features.features.length > 1) { var feature0 = serviceResult.result.features.features[0]; var feature1 = serviceResult.result.features.features[1]; var featureQ, featureZ; if (QSDH == feature0.properties["BSM"]) { featureQ = feature0; featureZ = feature1; } else { featureQ = feature1; featureZ = feature0; } var xQ = featureQ.properties["X"]; // X坐标 var yQ = featureQ.properties["Y"]; // Y坐标 var dmgcQ = (featureQ.properties["DMGC"] * 1).toFixed(2); // 起点地面高程 var gxmsQ = (featureQ.properties["MS"] * 1).toFixed(2); // 起点埋深 var xZ = featureZ.properties["X"]; // X坐标 var yZ = featureZ.properties["Y"]; // Y坐标 var dmgcZ = (featureZ.properties["DMGC"] * 1).toFixed(2); // 终点地面高程 var gxmsZ = (featureZ.properties["MS"] * 1).toFixed(2); // 终点埋深 let lyrsSelect = '
'; lyrsSelect += ''; lyrsSelect += ''; lyrsSelect += ''; lyrsSelect += '
'; lyrsSelect += '
'; lyrsSelect += "
管线类型:" + fldm + "
"; lyrsSelect += "
起点X坐标值:" + xQ + "
"; lyrsSelect += "
起点Y坐标值:" + yQ + "
"; lyrsSelect += "
起点高程值:" + (dmgcQ-gxmsQ) + "
"; lyrsSelect += "
终点X坐标值:" + xZ + "
"; lyrsSelect += "
终点Y坐标值:" + yZ + "
"; lyrsSelect += "
终点高程值:" + (dmgcZ - gxmsZ) + "
"; lyrsSelect += "
管径(MM):" + gj + "
"; lyrsSelect += '
'; lyrsSelect += '
'; lyrsSelect += "分析半径(M):"; lyrsSelect += '
'; layui.use('layer', function() { let layer = layui.layer; layer.open({ id: "panel-layerSelect", type: 1, area: ["500px", "400px"], btn: ['确定','取消'], title: "管线净距分析", skin: 'layui-ext-coolskin', content: lyrsSelect, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响 cancel: function (index, layero) { layer.close(index); }, yes: function(index, layero){ var radius = $("#radius").val(); let fxType = $('input[name="fxType"]:checked')[0].value; // 0碰撞;1水平;2垂直 //按钮【按钮一】的回调 var dsBufferAnalystService = L.supermap.spatialAnalystService(spatialanalystUrl); var dsBufferAnalystParameters = new SuperMap.DatasetBufferAnalystParameters({ dataset: CONST_VALUES.GX_DataSetName + "@" + CONST_VALUES.GX_DataSourceName, filterQueryParameter: new SuperMap.FilterParameter({ attributeFilter: "SMID=" + gxSmid }), bufferSetting: new SuperMap.BufferSetting({ endType: SuperMap.BufferEndType.ROUND, leftDistance: {value: radius}, rightDistance: {value: radius}, semicircleLineSegment: 10 }) }); dsBufferAnalystService.bufferAnalysis(dsBufferAnalystParameters, function (serviceResult) { var ptArrayTemp = serviceResult.result.recordset.features.features[0].geometry.coordinates[0][0]; var ptArray = Array(); for(var i = 0; i < ptArrayTemp.length; i++) { var tempArr = ptArrayTemp[i]; var ptTemp = Array(); ptTemp.push(tempArr[1]); ptTemp.push(tempArr[0]); ptArray.push(ptTemp); } var dataSourceName = CONST_VALUES.GX_DataSourceName; var dataSetName = CONST_VALUES.GX_DataSetName; var boundsParam = new SuperMap.GetFeaturesByBoundsParameters({ datasetNames: [dataSourceName + ":" + dataSetName], fromIndex: 0, toIndex: 100000, maxFeatures: 100000, bounds: L.polygon(ptArray).getBounds() }); // 查询范围内的所有管线 L.supermap.featureService(dataUrl) .getFeaturesByBounds(boundsParam, function (result) { if (result.result.features.features.length > 0) { // 坐标系转换 var result = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326); L.geoJSON(result, { style:{color: "#ef5b9c"}, onEachFeature: function (feature, layer) { let attributes = ""; let lyrs = CONST_VALUES.GX_Datas; for (var index = 0; index < lyrs.length; index++) { var lyr = lyrs[index]; if(dataSourceName == lyr.dataSourceName && dataSetName == lyr.dataSetName){ var showCols = lyr.cols; if(showCols != undefined && showCols != ""){ var colsArr = showCols.split(","); for(var i = 0; i < colsArr.length; i++){ var colArr = colsArr[i].split(":"); let attValue = feature.properties[colArr[0]]; let attr = colArr[1] + ":" + attValue + "
"; attributes += attr; } } break; } } layer.bindPopup(attributes); } }).addTo(resultLayer); pzfxProcess(sourceCoordinates,result,fxType,QSDH,ZDDH,bsm,fldm); } }); // 坐标系转换 var result = L.Util.transform(serviceResult.result.recordset.features, crs, L.CRS.EPSG4326); //var result = serviceResult.result; L.geoJSON(result, {color: "#00FF00"}).addTo(resultLayer); }); }, btn2: function(index, layero){ layer.close(index); } }); layui.use(['form'], function() { let form = layui.form; form.render(); }); }); } }); } }) }); } function pzfxProcess(sourceCoordinates,result,fxType,QSDHSel,ZDDHSel,bsmSel,fldmSel){ var pts = ''; for(var i = 0; i < result.features.length; i++) { var feature = result.features[i]; var QSDH = feature.properties["QSDH"]; // 起始点号 var ZDDH = feature.properties["ZDDH"]; // 终点点号 if(i < result.features.length-1){ pts += "'" + QSDH + "','" + ZDDH + "',"; } else{ pts += "'" + QSDH + "','" + ZDDH + "'"; } } var sqlTemp = "BSM in (" + pts + ")"; var sqlParam = new SuperMap.GetFeaturesBySQLParameters({ queryParameter: { name: CONST_VALUES.JD_DataSetName + "@" + CONST_VALUES.JD_DataSourceName, attributeFilter: sqlTemp }, datasetNames: [CONST_VALUES.JD_DataSourceName + ":" + CONST_VALUES.JD_DataSetName] }); L.supermap.featureService(dataUrl).getFeaturesBySQL(sqlParam, function (serviceResult) { if(serviceResult.result.features.features.length > 0){ var resultData = L.Util.transform(serviceResult.result.features, crs, L.CRS.EPSG4326); var rsList = new Array(); // 选择的管线 var line1 = turf.lineString([[sourceCoordinates[0][0], sourceCoordinates[0][1]], [sourceCoordinates[1][0], sourceCoordinates[1][1]]]); // 计算每条管线与选择管线的垂直和水平净距 两条线相交只要垂直净距,否则只有水平净距 for(var i = 0; i < result.features.length; i++){ var feature = result.features[i]; var coordinates = feature.geometry.coordinates; var QSDHTemp = feature.properties["QSDH"]; // 起始点号 var ZDDHTemp = feature.properties["ZDDH"]; // 终点点号 var bsmTemp = feature.properties["BSM"]; var fldmTemp = feature.properties["FLDM"]; // 与选择管线连接的管线排除掉 if(QSDHTemp == QSDHSel || QSDHTemp == ZDDHSel || ZDDHTemp == QSDHSel || ZDDHTemp == ZDDHSel){ continue; } // 地图上划线查询到的管线 var line2 = turf.lineString([[coordinates[0][0], coordinates[0][1]], [coordinates[1][0], coordinates[1][1]]]); // 交叉点 var intersects = turf.lineIntersect(line1, line2); // 水平净距分析时如果有交叉点,则没有水平净距 if(fxType == 1 && intersects.features.length > 0){ continue; } // 垂直净距分析时如果没有交叉点,则没有垂直净距 if(fxType == 2 && intersects.features.length == 0){ continue; } var entityData = {}; entityData.bsm = bsmSel; entityData.fldm = fldmSel; entityData.bsmTemp = bsmTemp; entityData.fldmTemp = fldmTemp; entityData.spjjMin = CONST_VALUES.SP_Min; entityData.czjjMin = CONST_VALUES.CZ_Min; // 有交叉点,则计算垂直净距 if(fxType != 1 && intersects.features.length > 0) { var pt1Data = undefined; var pt2Data = undefined; var pt1DataSel = undefined; var pt2DataSel = undefined; for(var j = 0; j < resultData.features.length; j++){ var bsm = resultData.features[j].properties["BSM"]; if(bsm == QSDHTemp){ pt1Data = resultData.features[j]; } else if(bsm == ZDDHTemp){ pt2Data = resultData.features[j]; } if(bsm == QSDHSel){ pt1DataSel = resultData.features[j]; } else if(bsm == ZDDHSel){ pt2DataSel = resultData.features[j]; } if(pt1Data != undefined && pt2Data != undefined && pt1DataSel != undefined && pt2DataSel != undefined){ break; } } if(pt1Data == undefined || pt2Data == undefined || pt1DataSel == undefined || pt2DataSel == undefined){ continue; } var dmgcPT1 = pt1Data.properties["DMGC"] * 1; // 地面高程 var msPT1 = pt1Data.properties["MS"] * 1; // 埋深 var xPT1 = pt1Data.geometry.coordinates[0]; // x坐标 var yPT1 = pt1Data.geometry.coordinates[1]; // y坐标 var dmgcPT2 = pt2Data.properties["DMGC"] * 1; // 地面高程 var msPT2 = pt2Data.properties["MS"] * 1; // 埋深 var xPT2 = pt2Data.geometry.coordinates[0]; // x坐标 var yPT2 = pt2Data.geometry.coordinates[1]; // y坐标 var dmgcPT1Sel = pt1DataSel.properties["DMGC"] * 1; // 地面高程 var msPT1Sel = pt1DataSel.properties["MS"] * 1; // 埋深 var xPT1Sel = pt1DataSel.geometry.coordinates[0]; // x坐标 var yPT1Sel = pt1DataSel.geometry.coordinates[1]; // y坐标 var dmgcPT2Sel = pt2DataSel.properties["DMGC"] * 1; // 地面高程 var msPT2Sel = pt2DataSel.properties["MS"] * 1; // 埋深 var xPT2Sel = pt2DataSel.geometry.coordinates[0]; // x坐标 var yPT2Sel = pt2DataSel.geometry.coordinates[1]; // y坐标 var xPtTmp = intersects.features[0].geometry.coordinates[0]; var yPtTmp = intersects.features[0].geometry.coordinates[1]; var dmgc = undefined; // 地面高程 var ms = undefined; // 埋深 var gxgc = undefined; // 管线高程 if(dmgcPT1 == dmgcPT2){ dmgc = dmgcPT1; } else if (dmgcPT1 > dmgcPT2){ dmgc = dmgcPT2 + (dmgcPT1 - dmgcPT2) * (Math.sqrt(Math.pow((xPtTmp - xPT2), 2) + Math.pow((yPtTmp - yPT2), 2))) / (Math.sqrt(Math.pow((xPT1 - xPT2), 2) + Math.pow((yPT1 - yPT2), 2))); } else { dmgc = dmgcPT1 + (dmgcPT2 - dmgcPT1) * (Math.sqrt(Math.pow((xPtTmp - xPT1), 2) + Math.pow((yPtTmp - yPT1), 2))) / (Math.sqrt(Math.pow((xPT2 - xPT1), 2) + Math.pow((yPT2 - yPT1), 2))); } if(msPT1 == msPT2){ ms = msPT1; } else if(msPT1 > msPT2){ ms = msPT2 + (msPT1 - msPT2) * (Math.sqrt(Math.pow((xPtTmp - xPT2), 2) + Math.pow((yPtTmp - yPT2), 2))) / (Math.sqrt(Math.pow((xPT1 - xPT2), 2) + Math.pow((yPT1 - yPT2), 2))); } else{ ms = msPT1 + (msPT2 - msPT1) * (Math.sqrt(Math.pow((xPtTmp - xPT1), 2) + Math.pow((yPtTmp - yPT1), 2))) / (Math.sqrt(Math.pow((xPT2 - xPT1), 2) + Math.pow((yPT2 - yPT1), 2))); } gxgc = dmgc - ms; var dmgcSel = undefined; // 地面高程 var msSel = undefined; // 埋深 var gxgcSel = undefined; // 管线高程 if(dmgcPT1Sel == dmgcPT2Sel){ dmgcSel = dmgcPT1Sel; } else if (dmgcPT1Sel > dmgcPT2Sel){ dmgcSel = dmgcPT2Sel + (dmgcPT1Sel - dmgcPT2Sel) * (Math.sqrt(Math.pow((xPtTmp - xPT2Sel), 2) + Math.pow((yPtTmp - yPT2Sel), 2))) / (Math.sqrt(Math.pow((xPT1Sel - xPT2Sel), 2) + Math.pow((yPT1Sel - yPT2Sel), 2))); } else { dmgcSel = dmgcPT1Sel + (dmgcPT2Sel - dmgcPT1Sel) * (Math.sqrt(Math.pow((xPtTmp - xPT1Sel), 2) + Math.pow((yPtTmp - yPT1Sel), 2))) / (Math.sqrt(Math.pow((xPT2Sel - xPT1Sel), 2) + Math.pow((yPT2Sel - yPT1Sel), 2))); } if(msPT1Sel == msPT2Sel){ msSel = msPT1Sel; } else if(msPT1Sel > msPT2Sel){ msSel = msPT2Sel + (msPT1Sel - msPT2Sel) * (Math.sqrt(Math.pow((xPtTmp - xPT2Sel), 2) + Math.pow((yPtTmp - yPT2Sel), 2))) / (Math.sqrt(Math.pow((xPT1Sel - xPT2Sel), 2) + Math.pow((yPT1Sel - yPT2Sel), 2))); } else{ msSel = msPT1Sel + (msPT2Sel - msPT1Sel) * (Math.sqrt(Math.pow((xPtTmp - xPT1Sel), 2) + Math.pow((yPtTmp - yPT1Sel), 2))) / (Math.sqrt(Math.pow((xPT2Sel - xPT1Sel), 2) + Math.pow((yPT2Sel - yPT1Sel), 2))); } gxgcSel = dmgcSel - msSel; var distance = Math.abs(gxgcSel-gxgc).toFixed(2); entityData.spjj = "--"; entityData.czjj = distance; if(distance < CONST_VALUES.CZ_Min){ rsList.push(entityData); } } // 没有交叉点,则计算水平净距 if(fxType != 2 && intersects.features.length == 0) { var pt1 = turf.point([sourceCoordinates[0][0], sourceCoordinates[0][1]]); var pt2 = turf.point([sourceCoordinates[1][0], sourceCoordinates[1][1]]); var pt3 = turf.point([coordinates[0][0], coordinates[0][1]]); var pt4 = turf.point([coordinates[1][0], coordinates[1][1]]); var distance1 = turf.pointToLineDistance(pt1, line2, {units: 'kilometers'}); var distance2 = turf.pointToLineDistance(pt2, line2, {units: 'kilometers'}); var distance3 = turf.pointToLineDistance(pt3, line1, {units: 'kilometers'}); var distance4 = turf.pointToLineDistance(pt4, line1, {units: 'kilometers'}); var distance = distance1; if(distance > distance1){ distance = distance1; } if(distance > distance2){ distance = distance2; } if(distance > distance3){ distance = distance3; } if(distance > distance4){ distance = distance4; } distance = distance * 1000; entityData.spjj = distance.toFixed(2); entityData.czjj = "--"; if(distance < CONST_VALUES.SP_Min){ rsList.push(entityData); } } } let tableNew = "
"; const tableNewID = utils.guid(); while (tableNew.indexOf('THETABLEID') > -1) tableNew = tableNew.replace('THETABLEID', tableNewID); layui.use('layer', function() { if (rsList.length == 0) { layui.layer.msg('分析结果中没法发现不符合标准的管线。'); return -1; } var layer = layui.layer; layer.open({ id: "panel-pzfx", type: 1, area: ["800px", "550px"], title: "碰撞分析结果", skin: 'layui-ext-coolskin', content: tableNew, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响 cancel: function (index, layero) { layer.close(index); } }); }); let cols = []; cols.push({ field: "bsm", title: "选中管线编号", sort: false, width: 120 }); cols.push({ field: "fldm", title: "选中管线类型", sort: false, width: 120 }); cols.push({ field: "bsmTemp", title: "分析管线编号", sort: false, width: 120 }); cols.push({ field: "fldmTemp", title: "分析管线类型", sort: false, width: 120 }); if(fxType != 2){ cols.push({ field: "spjj", title: "水平净距", sort: false, width: 120 }); cols.push({ field: "spjjMin", title: "标准水平净距", sort: false, width: 120 }); } if(fxType != 1){ cols.push({ field: "czjj", title: "垂直净距", sort: false, width: 120 }); cols.push({ field: "czjjMin", title: "标准垂直净距", sort: false, width: 120 }); } layui.use('table', function() { let table = layui.table; table.render({ elem: '#' + tableNewID, data: rsList, "lay-size": 'sm', cols: [cols] }); }); } }) } function ftfx(){ drawType = "FTFX"; setDefualtStyle(); drawMapControl.handler.disable(); drawMapControl.handler.libID = 0; drawMapControl.handler.code = 32; drawMapControl.handler.serverUrl = serverUrl; drawMapControl.handler.enable(); } function ftfxProcess(drawLayer){ var rectangleTemp = L.Util.transform(drawLayer._bounds, L.CRS.EPSG4326, crs); var ptArrayTemp = rectangleTemp.geometry.coordinates[0]; var ptArray = Array(); for(var i = 0; i < ptArrayTemp.length; i++) { var tempArr = ptArrayTemp[i]; var ptTemp = Array(); ptTemp.push(tempArr[1]); ptTemp.push(tempArr[0]); ptArray.push(ptTemp); } var dataSourceName = CONST_VALUES.GX_DataSourceName; var dataSetName = CONST_VALUES.GX_DataSetName; var boundsParam = new SuperMap.GetFeaturesByBoundsParameters({ datasetNames: [dataSourceName + ":" + dataSetName], fromIndex: 0, toIndex: 100000, maxFeatures: 100000, bounds: L.polygon(ptArray).getBounds() }); L.supermap .featureService(dataUrl) .getFeaturesByBounds(boundsParam, function (serviceResult) { // 坐标系转换 var result = L.Util.transform(serviceResult.result.features, crs, L.CRS.EPSG4326); L.geoJSON(result, { style:{color: "red"}, onEachFeature: function (feature, layer) { let attributes = ""; let lyrs = CONST_VALUES.GX_Datas; for (var index = 0; index < lyrs.length; index++) { var lyr = lyrs[index]; if(dataSourceName == lyr.dataSourceName && dataSetName == lyr.dataSetName){ var showCols = lyr.cols; if(showCols != undefined && showCols != ""){ var colsArr = showCols.split(","); for(var i = 0; i < colsArr.length; i++){ var colArr = colsArr[i].split(":"); let attValue = feature.properties[colArr[0]]; let attr = colArr[1] + ":" + attValue + "
"; attributes += attr; } } break; } } layer.bindPopup(attributes); } }).addTo(resultLayer); let tableNew = "
"; const tableNewID = utils.guid(); while (tableNew.indexOf('THETABLEID') > -1) tableNew = tableNew.replace('THETABLEID', tableNewID); layui.use('layer', function() { var layer = layui.layer; layer.open({ id: "panel-pzfx", type: 1, area: ["800px", "550px"], title: "覆土分析", skin: 'layui-ext-coolskin', content: tableNew, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响 cancel: function (index, layero) { layer.close(index); } }); }); let cols = []; cols.push({ field: "SMID", title: "实体编码", sort: false, width: 100 }); cols.push({ field: "fxRs", title: "分析结果", sort: false, width: 120 }); cols.push({ field: "msMin", title: "标准埋深", sort: false, width: 100 }); cols.push({ field: "QDMS", title: "起点埋深", sort: false, width: 100 }); cols.push({ field: "ZDMS", title: "终点埋深", sort: false, width: 100 }); cols.push({ field: "CZ", title: "材质", sort: false, width: 80 }); cols.push({ field: "GJ", title: "管径", sort: false, width: 80 }); cols.push({ field: "BSM", title: "管段编号", sort: false, width: 100 }); cols.push({ field: "QSDH", title: "起始点号", sort: false, width: 100 }); cols.push({ field: "ZDDH", title: "终点点号", sort: false, width: 100 }); cols.push({ field: "MSFS", title: "埋设方式", sort: false, width: 100 }); let datas = []; for (let i in result.features) { var entity = result.features[i].properties; var czTemp = entity["CZ"]; var qdmsTemp = entity["QDMS"]; var zdmsTemp = entity["ZDMS"]; var msMin = FTFX_Mins.get(czTemp); entity["msMin"] = msMin; if(msMin <= qdmsTemp && msMin <= zdmsTemp){ entity["fxRs"] = "符合标准"; } else{ entity["fxRs"] = "不符合标准"; } datas.push(entity); } layui.use('table', function() { let table = layui.table; table.render({ elem: '#' + tableNewID, data: datas, "lay-size": 'sm', cols: [cols] }); }); }); } // 连通分析 function ltfx(){ map.off('click'); var isFirstPoint = true; //判断是否是起始点 var latLngTemp = null;//存储上一点击点临时变量 map.on('click', function(ev) { TempLayer.clearLayers(); $("#tips").css('display', 'none'); var pt = crs.project(ev.latlng); var _Point = L.marker([pt.y, pt.x]); var dataSourceName = CONST_VALUES.GX_DataSourceName; var dataSetName = CONST_VALUES.GX_DataSetName; var bufferParam = new SuperMap.GetFeaturesByBufferParameters({ datasetNames: [dataSourceName + ":" + dataSetName], bufferDistance: CONST_VALUES.QUERY_BufferDistance, geometry: _Point }); // 判断点击的点是否在管线上 L.supermap .featureService(dataUrl) .getFeaturesByBuffer(bufferParam, function (result) { if(result.result.features.features.length > 0){ var texticon = L.divIcon({ //定义图标 className: "leaflet-div-icon-new" }); L.marker([ev.latlng.lat, ev.latlng.lng], { icon: texticon }).addTo(resultLayer); //marker实现文本框显示 if(isFirstPoint) { latLngTemp = ev.latlng; //存储上一点击点 isFirstPoint = false; } else { if(!latLngTemp.equals(ev.latlng)) { //避免出现结束双击,导致距离为0 map.off('click'); var findPathService = L.supermap.networkAnalystService(transportationAnalystUrl); //创建最佳路径分析参数实例 var resultSetting = new SuperMap.TransportationAnalystResultSetting({ returnEdgeFeatures: true, returnEdgeGeometry: true, returnEdgeIDs: true, returnNodeFeatures: true, returnNodeGeometry: true, returnNodeIDs: true, returnPathGuides: true, returnRoutes: true }); var analystParameter = new SuperMap.TransportationAnalystParameter({ resultSetting: resultSetting, //weightFieldName: "length" }); var pt1 = L.point(pt.x, pt.y); var ptTemp = crs.project(latLngTemp); var pt2 = L.point(ptTemp.x, ptTemp.y); var findPathParameter = new SuperMap.FindPathParameters({ isAnalyzeById: false, nodes: [pt1, pt2], parameter: analystParameter }); //进行查找 findPathService.findPath(findPathParameter, function (serviceResult) { if(serviceResult.type != "processFailed" && serviceResult.result.pathList[0].edgeFeatures.features.length > 0){ var result = L.Util.transform(serviceResult.result.pathList[0].edgeFeatures, crs, L.CRS.EPSG4326); L.geoJSON(result, { style:{color: "red"}, onEachFeature: function (feature, layer) { let attributes = ""; let lyrs = CONST_VALUES.GX_Datas; for (var index = 0; index < lyrs.length; index++) { var lyr = lyrs[index]; if(dataSourceName == lyr.dataSourceName && dataSetName == lyr.dataSetName){ var showCols = lyr.cols; if(showCols != undefined && showCols != ""){ var colsArr = showCols.split(","); for(var i = 0; i < colsArr.length; i++){ var colArr = colsArr[i].split(":"); let attValue = feature.properties[colArr[0]]; let attr = colArr[1] + ":" + attValue + "
"; attributes += attr; } } break; } } layer.bindPopup(attributes); } }).addTo(resultLayer); let tableNew = "
"; const tableNewID = utils.guid(); while (tableNew.indexOf('THETABLEID') > -1) tableNew = tableNew.replace('THETABLEID', tableNewID); layui.use('layer', function() { var layer = layui.layer; layer.open({ id: "panel-ltfx", type: 1, area: ["800px", "550px"], title: "连通分析", skin: 'layui-ext-coolskin', content: tableNew, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响 cancel: function (index, layero) { layer.close(index); } }); }); let cols = []; let lyrs = CONST_VALUES.GX_Datas; for (var index = 0; index < lyrs.length; index++) { var lyr = lyrs[index]; if(dataSourceName == lyr.dataSourceName && dataSetName == lyr.dataSetName){ var showCols = lyr.cols; if(showCols != undefined && showCols != ""){ var colsArr = showCols.split(","); for(var i = 0; i < colsArr.length; i++){ var colArr = colsArr[i].split(":"); cols.push({ field: colArr[0], title: colArr[1], sort: true, width: 100 }); } } break; } } let datas = []; for (let i in result.features) { datas.push(result.features[i].properties); } layui.use('table', function() { let table = layui.table; table.render({ elem: '#' + tableNewID, data: datas, "lay-size": 'sm', cols: [cols] }); }); } else { layui.layer.msg('所选位置不连通!'); return -1; } }); } } } }); }); } /** * 编辑管网 */ function layerEdit() { map.off('click'); map.off('contextmenu'); let lyrsSelect = '
'; lyrsSelect += ""; lyrsSelect += ""; lyrsSelect += ""; lyrsSelect += '
'; let lyrs = CONST_VALUES.GX_Datas; lyrsSelect += '
'; let listStr = ""; for (let index = 0; index < lyrs.length; index++) { const lyr = lyrs[index]; let dom = listStr.replace('THETITLE', lyr.name); dom = dom.replace('THEID', lyr.id); dom = dom.replace('THEWS', lyr.dataSourceName); dom = dom.replace('THEDATASETNAME', lyr.dataSetName); dom = dom.replace('THETYPE', lyr.dataType); lyrsSelect += dom; } lyrsSelect += '
'; layui.use('layer', function() { let layer = layui.layer; layer.open({ id: "panel-editTypes", type: 1, area: ["500px", "300px"], btn: ['确定'], title: "请选择编辑类型", skin: 'layui-ext-coolskin', content: lyrsSelect, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响 cancel: function(index, layero) { layer.close(index); }, yes: function(e) { let editType = $('input[name="editType"]:checked').val(); if (editType == undefined) { layer.msg('请选择编辑类型!', { icon: 7 }); return; } let editLayer = $('input[name="editLayer"]:checked').val(); if (editLayer == undefined) { layer.msg('请选择编辑图层!', { icon: 7 }); return; } layer.close(e); var editTypeVal = $('input[name="editType"]:checked')[0].attributes.value.value; var dataSourceName = $('input[name="editLayer"]:checked')[0].attributes.dataSourceName.value; var dataSetName = $('input[name="editLayer"]:checked')[0].attributes.dataSetName.value; var dataType = $('input[name="editLayer"]:checked')[0].attributes.dataType.value; var editTypeMap if(editTypeVal==0){ editTypeMap = SuperMap.EditType.ADD; } else if(editTypeVal == 1){ editTypeMap = SuperMap.EditType.UPDATE; } else if(editTypeVal == 2){ editTypeMap = SuperMap.EditType.DELETE; } map.on('contextmenu', function(evt){ map.off('click'); map.off('contextmenu'); }); // 新增 if(editTypeVal == 0){ // 添加管线 if(dataType == "line"){ var startPt;// 开始点击坐标 var endPt; // 结束点击坐标 var startGd;// 查询到开始管点 var endGd;// 查询到结束管点 var isFirst = true; map.on('click', function (evt) { var pt = crs.project(evt.latlng); var _Point = L.marker([pt.y, pt.x]); Q.queryByGeometry("",undefined,CONST_VALUES.JD_DataSetName, CONST_VALUES.JD_DataSourceName, _Point, function(result) { if (result.result == undefined || result.result.features.features.length == 0) { layui.layer.msg('附件没有发现管点信息,请重新选择!'); return; } var rs = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326); if(isFirst){ isFirst = false; startPt = evt.latlng; startGd = rs.features[0]; } else{ endPt = evt.latlng; endGd = rs.features[0]; if(!startPt.equals(endPt)){ var newLine = L.polyline([ //与上一点连线 [startGd.geometry.coordinates[1], startGd.geometry.coordinates[0]], [endGd.geometry.coordinates[1], endGd.geometry.coordinates[0]] ], { color: "#070af3" }); newLine.addTo(map); var from = turf.point([startGd.geometry.coordinates[0], startGd.geometry.coordinates[1]]); var to = turf.point([endGd.geometry.coordinates[0], endGd.geometry.coordinates[1]]); var options = {units: 'kilometers'}; var distance = (turf.distance(from, to, options) * 1000).toFixed(2); var aa = newLine.toGeoJSON(); var bb = L.Util.transform(aa, L.CRS.EPSG4326, crs); $.ajax({ url: '/static/maps/bs/create-line.html', success: function(htmlContext) { layui.use('layer', function(){ var layer = layui.layer,laydate = layui.laydate,form = layui.form; layer.open({ type: 1 //此处以iframe举例 ,area: ["400px", "550px"] ,title: "添加管线信息" ,skin: 'layui-ext-coolskin' //,shade: 0.8 ,maxmin: true ,content: htmlContext ,zIndex: layer.zIndex ,cancel: function (index, layero) { layer.close(index); map.removeLayer(newLine); } ,success: function(layero, index){ $("#QSDH").val(startGd.properties["BSM"]); $("#ZDDH").val(endGd.properties["BSM"]); $("#QDMS").val(startGd.properties["MS"]); $("#ZDMS").val(endGd.properties["MS"]); $("#CD").val(distance); var nowTime = new Date().Format("yyyyMMddhhmmssS"); $("#BSM").val(nowTime); //日期 laydate.render({ elem: '#LRRQ', }); laydate.render({ elem: '#MSRQ', }); } ,btn: ['保存', '关闭'] ,yes: function(){ var data = form.val('createLine'); bb.properties = data; var featuresParameters = new SuperMap.EditFeaturesParameters({ dataSourceName: dataSourceName, dataSetName: dataSetName, features: [bb], editType: editTypeMap, returnContent: true }); L.supermap.featureService(dataUrl) .editFeatures(featuresParameters,function(result){ console.log(result); }); layer.closeAll(); } ,btn2: function(){ layer.closeAll(); map.removeLayer(newLine); } }); }) }, error: function() { layui.layer.msg('功能未实现!', { icon: 7 }); } }); isFirst = true; } } }); }); } else{ map.on('click', function (evt) { var pt = crs.project(evt.latlng); var aaaaa = L.circleMarker(evt.latlng, {color: '#953716', radius: 3, fill: true, fillColor: 'green'}).addTo(map); var _Point = L.marker([pt.y, pt.x]); var aa = _Point.toGeoJSON(); $.ajax({ url: '/static/maps/bs/create-point.html', success: function(htmlContext) { layui.use('layer', function(){ var layer = layui.layer,laydate = layui.laydate,form = layui.form; layer.open({ type: 1 //此处以iframe举例 ,area: ["390px", "550px"] ,title: "添加管点信息" ,skin: 'layui-ext-coolskin' //,shade: 0.8 ,maxmin: true ,content: htmlContext ,zIndex: layer.zIndex ,cancel: function (index, layero) { layer.close(index); map.removeLayer(aaaaa); } ,success: function(layero, index){ $("#X").val(aa.geometry.coordinates[0]); $("#Y").val(aa.geometry.coordinates[1]); var nowTime = new Date().Format("yyyyMMddhhmmssS"); $("#BSM").val(nowTime); $("#WTH").val(nowTime); //日期 laydate.render({ elem: '#LRRQ', }); laydate.render({ elem: '#MSRQ', }); } ,btn: ['保存', '关闭'] ,yes: function(){ var data = form.val('createPoint'); aa.properties = data; var featuresParameters = new SuperMap.EditFeaturesParameters({ dataSourceName: dataSourceName, dataSetName: dataSetName, features: [aa], editType: editTypeMap, returnContent: true }); L.supermap.featureService(dataUrl) .editFeatures(featuresParameters,function(result){ console.log(result); }); layer.closeAll(); } ,btn2: function(){ layer.closeAll(); map.removeLayer(aaaaa); } }); }) }, error: function() { layui.layer.msg('功能未实现!', { icon: 7 }); } }); }); } } // 修改操作 else if(editTypeVal == 1){ map.on('click', function (evt) { var pt = crs.project(evt.latlng); var _Point = L.marker([pt.y, pt.x]); Q.queryByGeometry("",undefined,dataSetName, dataSourceName, _Point, function(result) { if (result.result == undefined || result.result.features.features.length < 1) return; // 坐标系转换 //var result = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326); var editFeature = result.result.features.features[0]; var rsVal = editFeature.properties; if(dataType == "line"){ $.ajax({ url: '/static/maps/bs/create-line.html', success: function(htmlContext) { layui.use('layer', function(){ var layer = layui.layer,laydate = layui.laydate,form = layui.form; layer.open({ type: 1 //此处以iframe举例 ,area: ["400px", "550px"] ,title: "编辑管线信息" ,skin: 'layui-ext-coolskin' //,shade: 0.8 ,maxmin: true ,content: htmlContext ,zIndex: layer.zIndex ,cancel: function (index, layero) { layer.close(index); } ,success: function(layero, index){ form.val('createLine', rsVal); //日期 laydate.render({ elem: '#LRRQ', }); laydate.render({ elem: '#MSRQ', }); } ,btn: ['保存', '关闭'] ,yes: function(){ var data = form.val('createLine'); editFeature.properties = data; var featuresParameters = new SuperMap.EditFeaturesParameters({ dataSourceName: dataSourceName, dataSetName: dataSetName, features: [editFeature], editType: editTypeMap, returnContent: true }); L.supermap.featureService(dataUrl) .editFeatures(featuresParameters,function(result){ console.log(result); }); layer.closeAll(); } ,btn2: function(){ layer.closeAll(); } }); }) }, error: function() { layui.layer.msg('功能未实现!', { icon: 7 }); } }); } else{ $.ajax({ url: '/static/maps/bs/create-point.html', success: function(htmlContext) { layui.use('layer', function(){ var layer = layui.layer,laydate = layui.laydate,form = layui.form; layer.open({ type: 1 //此处以iframe举例 ,area: ["390px", "550px"] ,title: "编辑管点信息" ,skin: 'layui-ext-coolskin' //,shade: 0.8 ,maxmin: true ,content: htmlContext ,zIndex: layer.zIndex ,cancel: function (index, layero) { layer.close(index); } ,success: function(layero, index){ form.val('createPoint', rsVal); //日期 laydate.render({ elem: '#LRRQ', }); laydate.render({ elem: '#MSRQ', }); } ,btn: ['保存', '关闭'] ,yes: function(){ var data = form.val('createPoint'); editFeature.properties = data; var featuresParameters = new SuperMap.EditFeaturesParameters({ dataSourceName: dataSourceName, dataSetName: dataSetName, features: [editFeature], editType: editTypeMap, returnContent: true }); L.supermap.featureService(dataUrl) .editFeatures(featuresParameters,function(result){ console.log(result); }); layer.closeAll(); } ,btn2: function(){ layer.closeAll(); } }); }) }, error: function() { layui.layer.msg('功能未实现!', { icon: 7 }); } }); } L.geoJSON(result, { style:{color: "#ef5b9c"}, onEachFeature: function (feature, layer) { let attributes = ""; let lyrs = CONST_VALUES.GX_Datas; for (var index = 0; index < lyrs.length; index++) { var lyr = lyrs[index]; if(ws == lyr.dataSourceName && dataSetName == lyr.dataSetName){ var showCols = lyr.cols; if(showCols != undefined && showCols != ""){ var colsArr = showCols.split(","); for(var i = 0; i < colsArr.length; i++){ var colArr = colsArr[i].split(":"); let attValue = feature.properties[colArr[0]]; let attr = colArr[1] + ":" + attValue + "
"; attributes += attr; } } break; } } layer.bindPopup(attributes); } }).addTo(resultLayer); }); }); } // 删除操作 else if(editTypeVal == 2){ drawType = "deletefeature"; // 创建绘制控件,并启用 var handler = new L.Draw.Polygon(map); handler.enable(); map.on(L.Draw.Event.CREATED,function (e) { if(drawType != "deletefeature"){ return; } var type = e.layerType, layer = e.layer; if (type === 'marker') { layer.bindPopup('A popup!'); } //将图形信息传给下一步,进行查询功能 var locationArray = e.layer.getLatLngs()[0]; var polygonArray = Array(); var midArray = Array(); var polygonArrayTmp = Array(); var midArrayTmp = Array(); var firstX = locationArray[0].lat; var firstY = locationArray[0].lng; for(var i =0;i 0){ layui.use('layer', function(){ let lyrsTmp = '

您确定要删除选择的管网元素信息吗!
'; var layer = layui.layer; layer.open({ type: 1 //此处以iframe举例 ,area: ["350px", "250px"] ,title: "提示" ,skin: 'layui-ext-coolskin' ,content: lyrsTmp ,zIndex: layer.zIndex ,cancel: function (index, layero) { layer.close(index); } ,btn: ['确定', '取消'] ,yes: function(){ var featuresParameters = new SuperMap.EditFeaturesParameters({ dataSourceName: dataSourceName, dataSetName: dataSetName, editType: editTypeMap, returnContent: true, IDs: ids }); L.supermap.featureService(dataUrl) .editFeatures(featuresParameters,function(result){ clearLays(); }); layer.closeAll(); } ,btn2: function(){ layer.closeAll(); clearLays(); } }); }) } else { layui.layer.msg('选择的区域没有数据信息!', { icon: 7 }); } }); }); } } }); layui.use(['form'], function() { let form = layui.form; form.render(); }); }); } Date.prototype.Format = function (fmt) { // author: meizz var o = { "M+": this.getMonth() + 1, // 月份 "d+": this.getDate(), // 日 "h+": this.getHours(), // 小时 "m+": this.getMinutes(), // 分 "s+": this.getSeconds(), // 秒 "q+": Math.floor((this.getMonth() + 3) / 3), // 季度 "S": this.getMilliseconds() // 毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; }