mapsTest.js 162 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527
  1. window.maps = {};
  2. window.panels = {};
  3. window.utils = {};
  4. window.Q = {};
  5. var allLayers = new Map();
  6. var map, crs, resultLayer, TempLayer;
  7. var mapLayer = null,lableLayer = null, subLayers , plotting, plottingLayer, drawMapControl, drawLayer;
  8. var url = URL_CONFIG.GX_Map_BaseUrl, dataUrl = URL_CONFIG.GX_Datas_BaseUrl, serverUrl = URL_CONFIG.GX_Plot_BaseUrl,
  9. spatialanalystUrl = URL_CONFIG.GX_Spatialanalyst_BaseUrl, drawType = "",
  10. transportationAnalystUrl = URL_CONFIG.GX_TransportationAnalyst_BaseUrl;
  11. $(document).ready(function() {
  12. layui.use(['layer'], function() {
  13. let layer = layui.layer;
  14. layer.config({
  15. extend: 'cool/cool.css'
  16. });
  17. });
  18. onload();
  19. $('#tool-clickQuery').click(function() {
  20. clearLays();
  21. clickQuery();
  22. });
  23. $('#tool-dis').click(function() {
  24. clearLays();
  25. measureDistance();
  26. });
  27. $('#tool-area').click(function() {
  28. clearLays();
  29. measureArea();
  30. });
  31. $('#tool-clear').click(function() {
  32. clearLays();
  33. });
  34. $('#tool-CircleQuery').click(function() {
  35. clearLays();
  36. drawCircle();
  37. });
  38. $('#tool-SquarenessQuery').click(function() {
  39. clearLays();
  40. drawRectangle();
  41. });
  42. $('#tool-ScopeQuery').click(function() {
  43. clearLays();
  44. drawPolygon();
  45. });
  46. $('#tool-layerCtrl').click(function(e) {
  47. clearLays();
  48. panels.openLayerTreePanel();
  49. });
  50. $('#tool-fullscreen').click(function() {
  51. toggleFullScreen();
  52. });
  53. $('#tool-dmfx').click(function() {
  54. clearLays();
  55. dmfx();
  56. });
  57. $('#tool-kwLine').click(function(e) {
  58. clearLays();
  59. pzfx();
  60. });
  61. $('#tool-ftfx').click(function(e) {
  62. clearLays();
  63. ftfx();
  64. });
  65. $('#tool-ltfx').click(function(e) {
  66. clearLays();
  67. ltfx();
  68. });
  69. $('#tool-layerEdit').click(function(e) {
  70. clearLays();
  71. layerEdit();
  72. });
  73. });
  74. function onload() {
  75. layui.use('element', function() {});
  76. panels.regEvents();
  77. panels.setDateTime();
  78. loadLayerTrees();
  79. $("#load_bg").remove(); //关闭加载动画
  80. $(".load_box").remove();
  81. }
  82. panels.setDateTime = function() {
  83. setInterval(() => {
  84. let dt = new Date();
  85. let yyyymmdd = dt.getFullYear() + " " + (dt.getMonth() + 1) + " " + dt.getDate();
  86. let sec = dt.getSeconds();
  87. sec = sec < 10 ? "0" + sec : sec + "";
  88. let time = (dt.getHours() < 12 ? "上午" : "下午") + " " + dt.getHours() + ":" + dt.getMinutes() + ":" + sec;
  89. $('.datetime .time').html(time);
  90. $('.datetime .date').html(yyyymmdd);
  91. }, 1000);
  92. }
  93. panels.menuLevel = {};
  94. panels.regEvents = function() {
  95. $('.query-type-enum div').click(function(e) {
  96. $('.query-type-enum div').removeClass("query-type-enum-select");
  97. $(this).addClass("query-type-enum-select");
  98. $("#queryType-subType").html('');
  99. if (panels.lastResultPanelIndex != undefined) {
  100. layui.layer.close(panels.lastResultPanelIndex);
  101. layui.layer.closeAll();
  102. }
  103. panels.menuLevel[panels.menuLevel.L1] = this;
  104. let id = $(this).find('span').attr('qs-name');
  105. if (id == undefined) return;
  106. $("#queryType-subType").html($(this).find('span').html());
  107. let htmlUrl = "/pipeline/bs/" + id + ".html";
  108. $.ajax({
  109. url: htmlUrl,
  110. success: function(htmlContext) {
  111. $('.queryConditionsContainer').html('');
  112. $('.queryConditionsContainer').html(htmlContext);
  113. layui.use(['form'], function() {
  114. let form = layui.form;
  115. form.render();
  116. });
  117. },
  118. error: function() {
  119. $('.queryConditionsContainer').html('');
  120. layui.layer.msg('功能未实现!', {
  121. icon: 7
  122. });
  123. }
  124. });
  125. });
  126. $('.head-menus span').click(function(e) {
  127. if (panels.lastResultPanelIndex != undefined) {
  128. layui.layer.close(panels.lastResultPanelIndex);
  129. layui.layer.closeAll();
  130. }
  131. $("#queryType-subType").html('未选择类型');
  132. $(".query-type-enum div").removeClass('query-type-enum-select ');
  133. let selected = $(this).hasClass('head-menus-menu-select');
  134. $('.head-menus span').removeClass('head-menus-menu-select');
  135. if (!selected) {
  136. $(this).addClass('head-menus-menu-select');
  137. $('.q-s-icon').removeClass('qs-hidden');
  138. } else {
  139. $('.q-s-icon').addClass('qs-hidden');
  140. $('.q-s-type').addClass('qs-hidden');
  141. }
  142. let qureyOrStatics = $(this).hasClass('qs-q');
  143. //点击了查询按钮
  144. if (qureyOrStatics) {
  145. panels.menuLevel.L1 = 2;
  146. $('.qs-q').removeClass('qs-hidden');
  147. $('.qs-s').addClass('qs-hidden');
  148. } else {
  149. panels.menuLevel.L1 = 1;
  150. $('.qs-s').removeClass('qs-hidden');
  151. $('.qs-q').addClass('qs-hidden');
  152. }
  153. if (panels.menuLevel[panels.menuLevel.L1] != undefined) {
  154. $(panels.menuLevel[panels.menuLevel.L1]).trigger('click');
  155. }
  156. $('.queryConditionsContainer').html('');
  157. });
  158. $("#cdts-ctrl").click(function(e) {
  159. var notDisplayCdts = $(this).find('img').eq(0).hasClass('qs-hidden');
  160. if (notDisplayCdts) {
  161. $(this).find('img').eq(0).removeClass('qs-hidden');
  162. $(this).find('img').eq(1).addClass('qs-hidden');
  163. $('.q-s-type').addClass('qs-hidden');
  164. } else {
  165. $(this).find('img').eq(1).removeClass('qs-hidden');
  166. $(this).find('img').eq(0).addClass('qs-hidden');
  167. $('.q-s-type').removeClass('qs-hidden');
  168. }
  169. });
  170. }
  171. function loadLayerTrees () {
  172. 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");
  173. // crs = L.Proj.CRS("EPSG:4549",{
  174. // bounds: L.bounds([384751.09,3977225.45], [558877.26,4071961.92]),
  175. // origin:[384751.09,4071961.92],
  176. // });
  177. // var pt = crs.unproject(L.point(395917.83 , 4060264.75));
  178. // map = L.map('cesiumContainer', {
  179. // preferCanvas: true,
  180. // crs: crs,
  181. // center:[pt.lat,pt.lng],
  182. // zoom: 5,
  183. // logoControl: false,
  184. // attributionControl: false
  185. // });
  186. // mapLayer = L.supermap.tiledMapLayer(url, {noWrap: true});
  187. // map.addLayer(mapLayer);
  188. // 添加地图服务
  189. crs = L.Proj.CRS("EPSG:4549");
  190. map = L.map('cesiumContainer', {
  191. preferCanvas: true,
  192. center: [45.507908,124.290565],
  193. zoom: 14,
  194. crs: L.CRS.TianDiTu_WGS84
  195. });
  196. mapLayer = L.supermap.tiandituTileLayer({
  197. key: "1d109683f4d84198e37a38c442d68311"
  198. });
  199. map.addLayer(mapLayer);
  200. lableLayer = L.supermap.tiandituTileLayer({
  201. isLabel: true,
  202. key: "1d109683f4d84198e37a38c442d68311"
  203. });
  204. map.addLayer(lableLayer);
  205. var thisLayer = {};
  206. thisLayer.layer = mapLayer;
  207. thisLayer.isShow = true;
  208. allLayers.set("baseMap",thisLayer)
  209. var lyrs = CONST_VALUES.GX_Datas;
  210. for (var index = 0; index < lyrs.length; index++) {
  211. var lyr = lyrs[index];
  212. var lyrid = lyr.id;
  213. var dataSourceName = lyr.dataSourceName;
  214. var dataSetName = lyr.dataSetName;
  215. addLayerData(dataSourceName,dataSetName,lyrid,"");
  216. }
  217. // 添加鹰眼
  218. var osm2 = L.supermap.tiandituTileLayer({
  219. key: "1d109683f4d84198e37a38c442d68311"
  220. });
  221. // var osm2 = L.supermap.tiledMapLayer(url, {minZoom: 0, maxZoom: 13,noWrap: true});
  222. L.control.minimap(osm2, {mapOptions:{ logoControl: false},toggleDisplay: true}).addTo(map);
  223. // 添加比例尺
  224. L.control.scale().addTo(map);
  225. // 启动绘制功能
  226. InitDraw();
  227. map.on('zoomend', function(e) {
  228. var nowZoom = e.target.getZoom();
  229. var lyrs = CONST_VALUES.GX_Datas;
  230. for (var index = 0; index < lyrs.length; index++) {
  231. var lyr = lyrs[index];
  232. var layId = lyr.id;
  233. var showZoom = lyr.showZoom;
  234. if(showZoom == undefined || showZoom == 0){
  235. continue;
  236. }
  237. var thisLayer = allLayers.get(layId);
  238. var isShow = thisLayer.isShow;
  239. var layTmp = thisLayer.layer;
  240. if(nowZoom >= showZoom){
  241. if(isShow && !map.hasLayer(layTmp)){
  242. map.addLayer(layTmp);
  243. }
  244. }
  245. else{
  246. if(isShow && map.hasLayer(layTmp)){
  247. map.removeLayer(layTmp);
  248. }
  249. }
  250. }
  251. });
  252. resultLayer = L.featureGroup().addTo(map);
  253. TempLayer = L.featureGroup().addTo(map);
  254. $('body').append("<div id='layerTree' ></div>");
  255. let openThePanel = function() {
  256. if ($("#layerTree").html().length > 0) {
  257. panels.loadLayerTreePanelByDom('layerTree');
  258. return;
  259. }
  260. panels.loadLayerTreePanelByDom('layerTree', function() {
  261. var allLayersTemp = [];
  262. for (var index = 0; index < lyrs.length; index++) {
  263. var lyr = lyrs[index];
  264. var nodeLayerInScene = {
  265. title: lyr.name,
  266. id: lyr.id,
  267. layer: lyr,
  268. checked: true
  269. };
  270. allLayersTemp.push(nodeLayerInScene);
  271. }
  272. var nodeLayerInScene = {
  273. title: "地图服务",
  274. id: "baseMap",
  275. layer: mapLayer,
  276. checked: true
  277. };
  278. allLayersTemp.push(nodeLayerInScene);
  279. layui.use('tree', function() {
  280. const tree = layui.tree;
  281. tree.render({
  282. elem: '#layerTree',
  283. data: allLayersTemp,
  284. showCheckbox: true,
  285. showLine: true,
  286. oncheck: function(obj) {
  287. var layId = obj.data.id;
  288. var thisLayer = allLayers.get(layId);
  289. var layTmp = thisLayer.layer;
  290. if(obj.checked){
  291. if(!map.hasLayer(layTmp)){
  292. map.addLayer(layTmp);
  293. thisLayer.isShow = true;
  294. allLayers.set(layId,thisLayer);
  295. if(layId == "baseMap" && lableLayer != null){
  296. map.addLayer(lableLayer);
  297. }
  298. }
  299. }
  300. else{
  301. if(map.hasLayer(layTmp)){
  302. map.removeLayer(layTmp);
  303. thisLayer.isShow = false;
  304. allLayers.set(layId,thisLayer);
  305. if(layId == "baseMap" && lableLayer != null){
  306. map.removeLayer(lableLayer);
  307. }
  308. }
  309. }
  310. // 重新指定一下中心点,解决不刷新图层的问题
  311. map.panTo(map.getCenter());
  312. }
  313. });
  314. });
  315. });
  316. }
  317. panels.openLayerTreePanel = openThePanel;
  318. }
  319. function addLayerData(dataSourceName,dataSetName,lyrid,showCss) {
  320. Q.queryBySql(dataSetName, dataSourceName, "SmID > 0", 0, 2000000, "", function(rs) {
  321. if (rs.result == undefined) return;
  322. var result = L.Util.transform(rs.result.features, crs, L.CRS.EPSG4326);
  323. var rsLayer;
  324. var thisLayer = {};
  325. if(lyrid == "waterLine"){
  326. rsLayer = L.geoJSON(result,{style:{color: "#070af3"}});
  327. map.addLayer(rsLayer);
  328. }
  329. else{
  330. var circleStyle = layerStyles.get(lyrid);
  331. var graphics = [];
  332. //设置每个点的经纬度和传入样式
  333. for(var i = 0; i < result.features.length; i++)
  334. {
  335. var feature = result.features[i];
  336. var coordinates = feature.geometry.coordinates;
  337. var pointVector = L.supermap.graphic({
  338. latLng: L.latLng(coordinates[1], coordinates[0]),
  339. style: circleStyle.getStyle()
  340. });
  341. graphics.push(pointVector)
  342. }
  343. //将管点要素画在地图上
  344. rsLayer = L.supermap.graphicLayer(graphics, {render: "canvas"});
  345. }
  346. thisLayer.layer = rsLayer;
  347. thisLayer.isShow = true;
  348. allLayers.set(lyrid,thisLayer);
  349. });
  350. }
  351. panels.loadLayerTreePanelByDom = function(domID, callback) {
  352. layui.use('layer', function() {
  353. const layer = layui.layer;
  354. panels.layerTreePanelIndex = layer.open({
  355. anim: 3,
  356. id: 'layerTreePanel',
  357. area: "280px",
  358. skin: 'layui-ext-coolskin',
  359. title: ["全部图层", 'font-size:14px;'],
  360. offset: ['65px', panels.SideWidth() + 5 + "px"],
  361. shade: 0,
  362. type: 1,
  363. content: $('#' + domID), //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响
  364. cancel: function() {},
  365. success: function(layero, index) {}
  366. });
  367. if (callback != undefined) {
  368. callback();
  369. }
  370. });
  371. }
  372. panels.SideWidth = function() {
  373. return $(".layui-side").width();
  374. }
  375. /**
  376. * 点选查询
  377. */
  378. function clickQuery() {
  379. let lyrs = CONST_VALUES.GX_Datas;
  380. let lyrsSelect = '<div id="layers" class="layui-form queryConditionsContainer" lay-filter="lyrsSelectDiv"><div class="layui-form-item"><div class="layui-input-block" style="margin-left:30px">';
  381. let listStr = "<input type=\'checkbox\' name=\'THENAME\' title=\'THETITLE\' id=\'THEID\' lay-skin=\'primary\' dataSetName=\'THEDATASETNAME\' dataSourceName=\'THEWS\'>";
  382. for (let index = 0; index < lyrs.length; index++) {
  383. const lyr = lyrs[index];
  384. let dom = listStr.replace('THENAME', lyr.name);
  385. dom = dom.replace('THETITLE', lyr.name);
  386. dom = dom.replace('THEID', lyr.id);
  387. dom = dom.replace('THEWS', lyr.dataSourceName);
  388. dom = dom.replace('THEDATASETNAME', lyr.dataSetName);
  389. lyrsSelect += dom;
  390. }
  391. lyrsSelect += '</div></div></div>';
  392. layui.use('layer', function() {
  393. let layer = layui.layer;
  394. layer.open({
  395. id: "panel-layerSelect",
  396. type: 1,
  397. area: ["300px", "220px"],
  398. btn: ['确定'],
  399. title: "请选择图层",
  400. skin: 'layui-ext-coolskin',
  401. content: lyrsSelect, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响
  402. cancel: function(index, layero) {
  403. layer.close(index);
  404. },
  405. yes: function(e) {
  406. var layers = $("#layers input:checked");
  407. if (layers.length == 0) {
  408. layer.msg('请至少选择一个图层!', {icon: 7});
  409. return;
  410. }
  411. layer.close(e);
  412. map.on('click', function (evt) {
  413. var pt = crs.project(evt.latlng);
  414. var _Point = L.marker([pt.y, pt.x]);
  415. for (var index = 0; index < layers.length; index++) {
  416. if(index == layers.length-1){
  417. map.off("click");
  418. }
  419. let checked = layers[index].checked;
  420. if (!checked)
  421. continue;
  422. var ws = layers[index].attributes.dataSourceName.value;
  423. var dataSetName = layers[index].attributes.dataSetName.value;
  424. var thatsubtitleP = layers[index].title;
  425. clicQueryProcess(thatsubtitleP, dataSetName, ws, _Point);
  426. }
  427. });
  428. }
  429. });
  430. layui.use(['form'], function() {
  431. let form = layui.form;
  432. form.render();
  433. });
  434. });
  435. }
  436. function clicQueryProcess(subtitle, dataSetName, ws, _Point) {
  437. Q.queryByGeometry(subtitle,undefined,dataSetName, ws, _Point, function(result) {
  438. if (result.result == undefined) return;
  439. panels.createResultPanelWithDataGrid({
  440. subTitle: subtitle,
  441. features: result.result.features.features,
  442. title: "点击查询结果",
  443. //count: count,
  444. dataSetName: dataSetName,
  445. dataSourceName: ws
  446. }, function() {
  447. });
  448. // 坐标系转换
  449. var result = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326);
  450. L.geoJSON(result, {
  451. style:{color: "#ef5b9c"},
  452. onEachFeature: function (feature, layer) {
  453. let attributes = "";
  454. let lyrs = CONST_VALUES.GX_Datas;
  455. for (var index = 0; index < lyrs.length; index++) {
  456. var lyr = lyrs[index];
  457. if(ws == lyr.dataSourceName && dataSetName == lyr.dataSetName){
  458. var showCols = lyr.cols;
  459. if(showCols != undefined && showCols != ""){
  460. var colsArr = showCols.split(",");
  461. for(var i = 0; i < colsArr.length; i++){
  462. var colArr = colsArr[i].split(":");
  463. let attValue = feature.properties[colArr[0]];
  464. let attr = colArr[1] + ":" + attValue + "<br>";
  465. attributes += attr;
  466. }
  467. }
  468. break;
  469. }
  470. }
  471. layer.bindPopup(attributes);
  472. }
  473. }).addTo(resultLayer);
  474. });
  475. }
  476. /*距离测量*/
  477. function measureDistance() {
  478. map.off('click');
  479. map.off('dblclick');
  480. $("#tips").css('display', 'block');
  481. var isFirstPoint = true; //判断是否是起始点
  482. var latLngTemp = null;//存储上一点击点临时变量
  483. var resultDis = 0; //总距
  484. map.on('click', function(ev) {
  485. TempLayer.clearLayers();
  486. $("#tips").css('display', 'none');
  487. var polyLine;
  488. if(isFirstPoint) {
  489. L.marker([ev.latlng.lat, ev.latlng.lng]).addTo(resultLayer); //起始点
  490. var texticon = L.divIcon({ //定义图标
  491. html: "起点",
  492. iconSize: [30, 20],
  493. iconAnchor: [15, 0]
  494. });
  495. L.marker([ev.latlng.lat, ev.latlng.lng], {
  496. icon: texticon
  497. }).addTo(resultLayer); //marker实现文本框显示
  498. latLngTemp = ev.latlng; //存储上一点击点
  499. isFirstPoint = false;
  500. } else {
  501. if(!latLngTemp.equals(ev.latlng)) { //避免出现结束双击,导致距离为0
  502. polyLine = L.polyline([ //与上一点连线
  503. [latLngTemp.lat, latLngTemp.lng],
  504. [ev.latlng.lat, ev.latlng.lng]
  505. ], {
  506. color: "red"
  507. });
  508. resultLayer.addLayer(polyLine);
  509. L.marker([ev.latlng.lat, ev.latlng.lng]).addTo(resultLayer); // 最后点击点经纬度
  510. var from = turf.point([latLngTemp.lng, latLngTemp.lat]);
  511. var to = turf.point([ev.latlng.lng, ev.latlng.lat]);
  512. var options = {units: 'kilometers'};
  513. var jl11 = turf.distance(from, to, options) * 1000;
  514. latLngTemp = ev.latlng; //更新临时变量为新点
  515. resultDis += jl11;
  516. // 距离根据地图单位进行换算成米或者千米
  517. var content = "距上点:" + Number(jl11).toFixed(2) + "米" + "<br>总距:" + Number(resultDis).toFixed(2) + "米";
  518. var texticon = L.divIcon({
  519. html: content,
  520. iconSize: [110, 40],
  521. iconAnchor: [55, -5] //设置标签偏移避免遮盖
  522. });
  523. L.marker([ev.latlng.lat, ev.latlng.lng], {
  524. icon: texticon
  525. }).addTo(resultLayer);
  526. TempLayer.clearLayers();
  527. }
  528. }
  529. map.on("mousemove", function(ev) {
  530. TempLayer.clearLayers();
  531. var TempLine = L.polyline([ //虚线临时线段
  532. [latLngTemp.lat, latLngTemp.lng],
  533. [ev.latlng.lat, ev.latlng.lng]
  534. ], {
  535. color: "red",
  536. dashArray: "5,5"
  537. });
  538. TempLayer.addLayer(TempLine);
  539. // 对坐标系进行转换
  540. var pt1 = crs.project(latLngTemp);
  541. var pt2 = crs.project(ev.latlng);
  542. var TempLineDis = L.polyline([ //与上一点连线
  543. [pt1.y, pt1.x],
  544. [pt2.y, pt2.x]
  545. ]);
  546. var from = turf.point([latLngTemp.lng, latLngTemp.lat]);
  547. var to = turf.point([ev.latlng.lng, ev.latlng.lat]);
  548. var options = {units: 'kilometers'};
  549. var jl11 = turf.distance(from, to, options) * 1000;
  550. var texticon = L.divIcon({
  551. html: Number(jl11).toFixed(2) + "米",
  552. iconSize: 90,
  553. className: 'my-div-icon',
  554. iconAnchor: [45, -5]
  555. });
  556. L.marker([ev.latlng.lat, ev.latlng.lng], {
  557. icon: texticon
  558. }).addTo(TempLayer);
  559. });
  560. });
  561. map.on('dblclick', function(ev) {
  562. map.off('click');
  563. map.off('dblclick');
  564. map.off('mousemove');
  565. });
  566. }
  567. /*面积测量*/
  568. function measureArea() {
  569. drawType = "measureArea";
  570. // 创建绘制控件,并启用
  571. var handler = new L.Draw.Polygon(map);
  572. handler.enable();
  573. map.on(L.Draw.Event.CREATED,function (e) {
  574. if(drawType != "measureArea"){
  575. return;
  576. }
  577. var type = e.layerType,
  578. layer = e.layer;
  579. if (type === 'marker') {
  580. layer.bindPopup('A popup!');
  581. }
  582. //将图形信息传给下一步,进行查询功能
  583. var locationArray = e.layer.getLatLngs()[0];
  584. var polygonArray = Array();
  585. var turfPolygonArray = Array();
  586. var midArray = Array();
  587. var turfMidArray = Array();
  588. var firstX = locationArray[0].lat;
  589. var firstY = locationArray[0].lng;
  590. for(var i =0;i<locationArray.length;i++){
  591. var x = locationArray[i].lat;
  592. var y = locationArray[i].lng;
  593. midArray.push(x);
  594. midArray.push(y);
  595. turfMidArray.push(y);
  596. turfMidArray.push(x);
  597. polygonArray.push(midArray);
  598. turfPolygonArray.push(turfMidArray);
  599. midArray = Array();
  600. turfMidArray = Array();
  601. }
  602. midArray.push(firstX);
  603. midArray.push(firstY);
  604. turfMidArray.push(firstY);
  605. turfMidArray.push(firstX);
  606. polygonArray.push(midArray);
  607. turfPolygonArray.push(turfMidArray);
  608. var polygon = L.polygon(polygonArray, {color: "#00FF00"});
  609. var polygonTurf = turf.polygon([turfPolygonArray]);
  610. var area = turf.area(polygonTurf);
  611. resultLayer.addLayer(polygon);
  612. var content = "面积:" + Number(area).toFixed(2) + "平方米";
  613. polygon.bindPopup(content).openPopup(polygon.getCenter());
  614. });
  615. }
  616. /**
  617. * 清除量算
  618. */
  619. function clearLays() {
  620. resultLayer.clearLayers();
  621. TempLayer.clearLayers();
  622. plottingLayer.removeFeatures(drawLayer);
  623. }
  624. panels.createResultPanelWithDataGrid = function(params, callback) {
  625. layui.use('layer', function() {
  626. if (params.features.length == 0) {
  627. layui.layer.msg(params.title + "下" + params.subTitle + '查询无结果。<br>请重新设置查询条件!');
  628. return -1;
  629. }
  630. var layer = layui.layer;
  631. panels.createPanelBase(layer,params.title);
  632. panels.createPagesByFeatures(params);
  633. if (callback != undefined) {
  634. callback();
  635. }
  636. });
  637. }
  638. panels.createPanelBase = function(layer,title, resizeCb) {
  639. //兼容两个页面
  640. let pc = $("#panel-condition");
  641. let theTarget;
  642. if (pc.length > 0) {
  643. theTarget = pc.parent();
  644. } else {
  645. theTarget = $(".q-s-type");
  646. }
  647. const conditionLeft = parseInt(theTarget.css("left").replace('px', ''));
  648. const conditionWidth = parseInt(theTarget.width());
  649. const conditionHeight = parseInt(theTarget.height());
  650. const conditionTop = parseInt(theTarget.css("top").replace('px', ''));
  651. let x = conditionLeft + conditionWidth + 5 + "px";
  652. let y = conditionTop + conditionHeight + 10 + "px";
  653. let offset = ['65px'];
  654. if (pc.length === 0) {
  655. x = conditionLeft + "px";
  656. offset = [y, x]
  657. }
  658. panels.lastResultPanelIndex = layer.open({
  659. id: "panel-result",
  660. anim: 3,
  661. area: ['412px', '400px'],
  662. title: "<span class='q-title-in-Sub-img'></span><span class='q-title-in-Sub-title'>" + title + "</span>",
  663. skin: 'layui-ext-coolskin',
  664. offset: offset,
  665. shade: 0,
  666. type: 1,
  667. maxmin: true,
  668. resizing: function(layero) {
  669. if (resizeCb)
  670. resizeCb(layero);
  671. },
  672. full:function(layero){
  673. if (resizeCb)
  674. resizeCb(layero);
  675. },
  676. restore:function(layero){
  677. if (resizeCb)
  678. resizeCb(layero);
  679. },
  680. success: function(layero, index) {}
  681. });
  682. }
  683. panels.createPagesByFeatures = function(params) {
  684. panels.createMonitor();
  685. let subTitle = params.subTitle;
  686. let features = params.features;
  687. let dataSourceName = params.dataSourceName;
  688. let dataSetName = params.dataSetName;
  689. if (features.length == 0) return;
  690. let tableNew = "<table id='THETABLEID' lay-filter='THETABLEID'></table>";
  691. const tableNewID = utils.guid();
  692. while (tableNew.indexOf('THETABLEID') > -1)
  693. tableNew = tableNew.replace('THETABLEID', tableNewID);
  694. let cols = [];
  695. var showZoom = 10;
  696. let lyrs = CONST_VALUES.GX_Datas;
  697. for (var index = 0; index < lyrs.length; index++) {
  698. var lyr = lyrs[index];
  699. if(dataSourceName == lyr.dataSourceName && dataSetName == lyr.dataSetName){
  700. var showCols = lyr.cols;
  701. showZoom = lyr.showZoom;
  702. if(showCols != undefined && showCols != ""){
  703. var colsArr = showCols.split(",");
  704. for(var i = 0; i < colsArr.length; i++){
  705. var colArr = colsArr[i].split(":");
  706. cols.push({ field: colArr[0], title: colArr[1], sort: true, width: 80 });
  707. }
  708. }
  709. break;
  710. }
  711. }
  712. if(cols.length == 0){
  713. for (const property in features[0].properties) {
  714. let tmpProperty = property.toUpperCase();
  715. if (tmpProperty.startsWith("SM") && tmpProperty != "SMID")
  716. continue;
  717. if (tmpProperty.startsWith("SS"))
  718. continue;
  719. cols.push({ field: property, title: property, sort: true });
  720. }
  721. }
  722. let datas = [];
  723. for (let i in features) {
  724. datas.push(features[i].properties);
  725. }
  726. let tabControl = "<div class='layui-tab' lay-filter='resultTabControl' id='THETABCONTROLID'>" +
  727. "<ul class='layui-tab-title'></ul>" +
  728. "<div class='layui-tab-content'></div></div>";
  729. let tabControlID = utils.guid();
  730. tabControl = tabControl.replace('THETABCONTROLID', tabControlID);
  731. if ($('div[lay-filter="resultTabControl"]').length == 0) {
  732. $(tabControl).appendTo($("#panel-result"));
  733. }
  734. layui.use('element', function() {
  735. let element = layui.element;
  736. element.render();
  737. let tabID = utils.guid();
  738. element.tabAdd('resultTabControl', {
  739. title: subTitle,
  740. content: tableNew //支持传入html
  741. ,
  742. id: tabID
  743. });
  744. layui.use('table', function() {
  745. let table = layui.table;
  746. table.render({
  747. elem: '#' + tableNewID,
  748. data: datas,
  749. page: true,
  750. "lay-size": 'sm',
  751. limit: 6,
  752. done:function (res, curr, count){
  753. $("table").css("width", "100%");
  754. },
  755. cols: [cols],
  756. // toolbar: true,
  757. // totalrow: true,
  758. // title: '导出结果'
  759. });
  760. table.on('row(' + tableNewID + ')', function(obj) {
  761. Q.queryBySql(dataSetName, dataSourceName, "SMID = " + obj.data.SMID, 0, 10, "", function(result) {
  762. if (result.result == undefined) return;
  763. // 坐标系转换
  764. var result = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326);
  765. L.geoJSON(result, {
  766. style:{color: "#f80202"},
  767. onEachFeature: function (feature, layer) {
  768. if(feature.geometry.type == 'Point'){
  769. map.flyTo(layer._latlng, showZoom);
  770. }
  771. else{
  772. map.flyToBounds(layer._bounds);
  773. }
  774. let attributes = "";
  775. let lyrs = CONST_VALUES.GX_Datas;
  776. for (var index = 0; index < lyrs.length; index++) {
  777. var lyr = lyrs[index];
  778. if(dataSourceName == lyr.dataSourceName && dataSetName == lyr.dataSetName){
  779. var showCols = lyr.cols;
  780. if(showCols != undefined && showCols != ""){
  781. var colsArr = showCols.split(",");
  782. for(var i = 0; i < colsArr.length; i++){
  783. var colArr = colsArr[i].split(":");
  784. let attValue = feature.properties[colArr[0]];
  785. let attr = colArr[1] + ":" + attValue + "<br>";
  786. attributes += attr;
  787. }
  788. }
  789. break;
  790. }
  791. }
  792. layer.bindPopup(attributes);
  793. }
  794. }).addTo(resultLayer);
  795. });
  796. });
  797. });
  798. element.tabChange('resultTabControl', tabID);
  799. const thisTitle = $('.layui-layer-title');
  800. thisTitle.addClass("layui-layer-title-transparent");
  801. });
  802. }
  803. panels.createMonitor = function() {
  804. if (panels.createMonitor.created == true) return;
  805. panels.createMonitor.created = true;
  806. function imitateClick(oElement, iClientX, iClientY) {
  807. var oEvent;
  808. if (document.createEventObject) { //For IE
  809. oEvent = document.createEventObject();
  810. oEvent.clientX = iClientX;
  811. oEvent.clientY = iClientY;
  812. oElement.fireEvent("onclick", oEvent);
  813. } else {
  814. oEvent = document.createEvent("MouseEvents");
  815. oEvent.initMouseEvent("click", true, true, window, 0, 0, 0, iClientX, iClientY);
  816. oElement.dispatchEvent(oEvent);
  817. }
  818. }
  819. panels.createMonitor.moniter = imitateClick;
  820. }
  821. utils.guid = function() {
  822. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  823. let r = Math.random() * 16 | 0,
  824. v = c == 'x' ? r : (r & 0x3 | 0x8);
  825. return v.toString(16);
  826. });
  827. }
  828. Q.queryBySql = function(datasetName, wsName, sql, fromIndex, toIndex, aggregations, callback) {
  829. let sqlParam = new SuperMap.GetFeaturesBySQLParameters({
  830. queryParameter: {
  831. name: datasetName + "@" + wsName,
  832. attributeFilter: sql
  833. },
  834. datasetNames: [wsName + ":" + datasetName],
  835. fromIndex: fromIndex,
  836. toIndex: toIndex,
  837. maxFeatures: toIndex
  838. });
  839. L.supermap.featureService(dataUrl).getFeaturesBySQL(sqlParam,
  840. function(serviceResult) {
  841. if (callback != undefined) {
  842. callback(serviceResult)
  843. }
  844. });
  845. }
  846. Q.queryByBounds = function(title,datasetName, wsName, bounds, callback) {
  847. var paramsTmp = {};
  848. paramsTmp.title = title;
  849. paramsTmp.dataSetName = datasetName;
  850. paramsTmp.dataSourceName = wsName;
  851. var geometryParam = new SuperMap.GetFeaturesByGeometryParameters({
  852. datasetNames: [wsName + ":" + datasetName],
  853. geometry: bounds,
  854. spatialQueryMode: "INTERSECT"
  855. });
  856. L.supermap
  857. .featureService(dataUrl)
  858. .getFeaturesByGeometry(geometryParam, function (serviceResult) {
  859. if (callback != undefined) {
  860. callback(serviceResult,paramsTmp)
  861. }
  862. });
  863. }
  864. Q.queryByGeometry = function(title,distanceTmp,datasetName, wsName, geometry, callback) {
  865. var paramsTmp = {};
  866. paramsTmp.title = title;
  867. paramsTmp.dataSetName = datasetName;
  868. paramsTmp.dataSourceName = wsName;
  869. if(distanceTmp == undefined){
  870. distanceTmp = CONST_VALUES.QUERY_BufferDistance;
  871. }
  872. var bufferParam = new SuperMap.GetFeaturesByBufferParameters({
  873. datasetNames: [wsName + ":" + datasetName],
  874. bufferDistance: distanceTmp,
  875. geometry: geometry
  876. });
  877. L.supermap
  878. .featureService(dataUrl)
  879. .getFeaturesByBuffer(bufferParam, function (serviceResult) {
  880. if (callback != undefined) {
  881. callback(serviceResult,paramsTmp)
  882. }
  883. });
  884. }
  885. function InitDraw() {
  886. // 创建一个名为“plottingLayer”的标绘图层。
  887. plottingLayer = L.supermap.plotting.plottingLayer("plot", serverUrl);
  888. // 向map中添加标绘图层
  889. plottingLayer.addTo(map);
  890. // 标绘控件
  891. drawMapControl = L.supermap.plotting.drawControl(plottingLayer);
  892. drawMapControl.addTo(map);
  893. plotting = L.supermap.plotting.getControl(map, serverUrl);
  894. drawMapControl.on(SuperMap.Plot.Event.featureadded, function (event) {
  895. drawLayer = event.feature;
  896. var symbolType = drawLayer.symbolType;
  897. if (symbolType === SuperMap.Plot.SymbolType.ARBITRARYPOLYGONSYMBOL) {
  898. }
  899. else if (symbolType === SuperMap.Plot.SymbolType.CIRCLESYMBOL) {
  900. var latLngs = drawLayer.getLatLngs();
  901. var pt = crs.project(latLngs[0]);
  902. var _Point = L.marker([pt.y, pt.x]);
  903. var dataSourceName = CONST_VALUES.GX_DataSourceName;
  904. var dataSetName = CONST_VALUES.GX_DataSetName;
  905. var bufferParam = new SuperMap.GetFeaturesByBufferParameters({
  906. datasetNames: [dataSourceName + ":" + dataSetName],
  907. bufferDistance: CONST_VALUES.QUERY_BufferDistance,
  908. geometry: _Point
  909. });
  910. // 判断点击的点是否在管线上
  911. L.supermap
  912. .featureService(dataUrl)
  913. .getFeaturesByBuffer(bufferParam, function (result) {});
  914. }
  915. else if (symbolType === SuperMap.Plot.SymbolType.RECTANGLESYMBOL) {
  916. }
  917. // 覆土分析
  918. if(drawType == "FTFX"){
  919. ftfxProcess(drawLayer);
  920. }
  921. else{
  922. let lyrs = CONST_VALUES.GX_Datas;
  923. let lyrsSelect = '<div id="layers" class="layui-form queryConditionsContainer" lay-filter="lyrsSelectDiv"><div class="layui-form-item"><div class="layui-input-block" style="margin-left:30px">';
  924. let listStr = "<input type=\'checkbox\' name=\'THENAME\' title=\'THETITLE\' id=\'THEID\' lay-skin=\'primary\' dataSetName=\'THEDATASETNAME\' dataSourceName=\'THEWS\'>";
  925. for (let index = 0; index < lyrs.length; index++) {
  926. const lyr = lyrs[index];
  927. let dom = listStr.replace('THENAME', lyr.name);
  928. dom = dom.replace('THETITLE', lyr.name);
  929. dom = dom.replace('THEID', lyr.id);
  930. dom = dom.replace('THEWS', lyr.dataSourceName);
  931. dom = dom.replace('THEDATASETNAME', lyr.dataSetName);
  932. lyrsSelect += dom;
  933. }
  934. lyrsSelect += '</div></div></div>';
  935. layui.use('layer', function() {
  936. let layer = layui.layer;
  937. layer.open({
  938. id: "panel-layerSelect",
  939. type: 1,
  940. area: ["300px", "220px"],
  941. btn: ['确定'],
  942. title: "请选择图层",
  943. skin: 'layui-ext-coolskin',
  944. content: lyrsSelect, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响
  945. cancel: function(index, layero) {
  946. layer.close(index);
  947. },
  948. yes: function(e) {
  949. var layers = $("#layers input:checked");
  950. if (layers.length == 0) {
  951. layer.msg('请至少选择一个图层!', {
  952. icon: 7
  953. });
  954. return;
  955. }
  956. layer.close(e);
  957. // 矩形查询
  958. if (symbolType === SuperMap.Plot.SymbolType.RECTANGLESYMBOL) {
  959. var rectangleTemp = L.Util.transform(drawLayer._bounds, L.CRS.EPSG4326, crs);
  960. var ptArrayTemp = rectangleTemp.geometry.coordinates[0];
  961. var ptArray = Array();
  962. for(var i = 0; i < ptArrayTemp.length; i++) {
  963. var tempArr = ptArrayTemp[i];
  964. var ptTemp = Array();
  965. ptTemp.push(tempArr[1]);
  966. ptTemp.push(tempArr[0]);
  967. ptArray.push(ptTemp);
  968. }
  969. var polygonTmp = L.polygon(ptArray);
  970. for (var index = 0; index < layers.length; index++) {
  971. let checked = layers[index].checked;
  972. if (!checked)
  973. continue;
  974. var ws = layers[index].attributes.dataSourceName.value;
  975. var dataSetName = layers[index].attributes.dataSetName.value;
  976. var thatsubtitleP = layers[index].title;
  977. Q.queryByBounds(thatsubtitleP, dataSetName, ws, polygonTmp, function(result,titleTmp) {
  978. if (result.result == undefined) return;
  979. panels.createResultPanelWithDataGrid({
  980. subTitle: titleTmp.title,
  981. features: result.result.features.features,
  982. title: "范围查询结果",
  983. //count: count,
  984. dataSetName: titleTmp.dataSetName,
  985. dataSourceName: titleTmp.dataSourceName
  986. }, function() {
  987. //debugger;
  988. });
  989. // 坐标系转换
  990. // var result = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326);
  991. //
  992. // L.geoJSON(result, {
  993. // style:{color: "red"},
  994. // onEachFeature: function (feature, layer) {
  995. // let attributes = "";
  996. // let lyrs = CONST_VALUES.GX_Datas;
  997. // for (var index = 0; index < lyrs.length; index++) {
  998. // var lyr = lyrs[index];
  999. // if(ws == lyr.dataSourceName && dataSetName == lyr.dataSetName){
  1000. // var showCols = lyr.cols;
  1001. // if(showCols != undefined && showCols != ""){
  1002. // var colsArr = showCols.split(",");
  1003. // for(var i = 0; i < colsArr.length; i++){
  1004. // var colArr = colsArr[i].split(":");
  1005. // let attValue = feature.properties[colArr[0]];
  1006. // let attr = colArr[1] + ":" + attValue + "<br>";
  1007. // attributes += attr;
  1008. // }
  1009. // }
  1010. // break;
  1011. // }
  1012. // }
  1013. // layer.bindPopup(attributes);
  1014. // }
  1015. // }).addTo(resultLayer);
  1016. });
  1017. }
  1018. }
  1019. else if (symbolType === SuperMap.Plot.SymbolType.CIRCLESYMBOL) {
  1020. var latLngs = drawLayer.getLatLngs();
  1021. var from = turf.point([latLngs[0].lng, latLngs[0].lat]);
  1022. var to = turf.point([latLngs[1].lng, latLngs[1].lat]);
  1023. var options = {units: 'kilometers'};
  1024. var jl11 = turf.distance(from, to, options) * 1000;
  1025. var pt = crs.project(latLngs[0]);
  1026. var _Point = L.marker([pt.y, pt.x]);
  1027. var radius = Math.sqrt(Math.pow((latLngs[1].lng - latLngs[0].lng)*1000, 2) + Math.pow((latLngs[1].lat - latLngs[0].lat)*1000, 2));
  1028. for (var index = 0; index < layers.length; index++) {
  1029. let checked = layers[index].checked;
  1030. if (!checked)
  1031. continue;
  1032. var ws = layers[index].attributes.dataSourceName.value;
  1033. var dataSetName = layers[index].attributes.dataSetName.value;
  1034. var thatsubtitleP = layers[index].title;
  1035. var bufferParam = new SuperMap.GetFeaturesByBufferParameters({
  1036. datasetNames: [ws + ":" + dataSetName],
  1037. bufferDistance: jl11,
  1038. geometry: _Point
  1039. });
  1040. Q.queryByGeometry(thatsubtitleP, jl11, dataSetName, ws, _Point, function(result,titleTmp) {
  1041. if (result.result == undefined) return;
  1042. panels.createResultPanelWithDataGrid({
  1043. subTitle: titleTmp.title,
  1044. features: result.result.features.features,
  1045. title: "范围查询结果",
  1046. //count: count,
  1047. dataSetName: titleTmp.dataSetName,
  1048. dataSourceName: titleTmp.dataSourceName
  1049. }, function() {
  1050. });
  1051. // 坐标系转换
  1052. // var result = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326);
  1053. //
  1054. // L.geoJSON(result, {
  1055. // style:{color: "red"},
  1056. // onEachFeature: function (feature, layer) {
  1057. // let attributes = "";
  1058. // let lyrs = CONST_VALUES.GX_Datas;
  1059. // for (var index = 0; index < lyrs.length; index++) {
  1060. // var lyr = lyrs[index];
  1061. // if(ws == lyr.dataSourceName && dataSetName == lyr.dataSetName){
  1062. // var showCols = lyr.cols;
  1063. // if(showCols != undefined && showCols != ""){
  1064. // var colsArr = showCols.split(",");
  1065. // for(var i = 0; i < colsArr.length; i++){
  1066. // var colArr = colsArr[i].split(":");
  1067. // let attValue = feature.properties[colArr[0]];
  1068. // let attr = colArr[1] + ":" + attValue + "<br>";
  1069. // attributes += attr;
  1070. // }
  1071. // }
  1072. // break;
  1073. // }
  1074. // }
  1075. // layer.bindPopup(attributes);
  1076. // }
  1077. // }).addTo(resultLayer);
  1078. })
  1079. }
  1080. }
  1081. }
  1082. });
  1083. layui.use(['form'], function() {
  1084. let form = layui.form;
  1085. form.render();
  1086. });
  1087. });
  1088. }
  1089. drawMapControl.handler.disable();
  1090. });
  1091. }
  1092. function polygonQueryProcess(subtitle, dataSetName, ws, bounds) {
  1093. Q.queryByBounds(subtitle, dataSetName, ws, bounds, function(result,titleTmp) {
  1094. if (result.result == undefined) return;
  1095. panels.createResultPanelWithDataGrid({
  1096. subTitle: titleTmp.title,
  1097. features: result.result.features.features,
  1098. title: "范围查询结果",
  1099. //count: count,
  1100. dataSetName: titleTmp.dataSetName,
  1101. dataSourceName: titleTmp.dataSourceName
  1102. }, function() {
  1103. });
  1104. // 坐标系转换
  1105. var result = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326);
  1106. L.geoJSON(result, {
  1107. style:{color: "red"},
  1108. onEachFeature: function (feature, layer) {
  1109. let attributes = "";
  1110. let lyrs = CONST_VALUES.GX_Datas;
  1111. for (var index = 0; index < lyrs.length; index++) {
  1112. var lyr = lyrs[index];
  1113. if(ws == lyr.dataSourceName && dataSetName == lyr.dataSetName){
  1114. var showCols = lyr.cols;
  1115. if(showCols != undefined && showCols != ""){
  1116. var colsArr = showCols.split(",");
  1117. for(var i = 0; i < colsArr.length; i++){
  1118. var colArr = colsArr[i].split(":");
  1119. let attValue = feature.properties[colArr[0]];
  1120. let attr = colArr[1] + ":" + attValue + "<br>";
  1121. attributes += attr;
  1122. }
  1123. }
  1124. break;
  1125. }
  1126. }
  1127. layer.bindPopup(attributes);
  1128. }
  1129. }).addTo(resultLayer);
  1130. });
  1131. }
  1132. // 范围查询
  1133. function drawPolygon() {
  1134. drawType = "drawPolygon";
  1135. var handler = new L.Draw.Polygon(map);
  1136. handler.enable();
  1137. map.on(L.Draw.Event.CREATED,function (e) {
  1138. if (drawType != "drawPolygon") {
  1139. return;
  1140. }
  1141. //将图形信息传给下一步,进行查询功能
  1142. var locationArray = e.layer.getLatLngs()[0];
  1143. var polygonArray = Array();
  1144. var midArray = Array();
  1145. var polygonArrayTmp = Array();
  1146. var midArrayTmp = Array();
  1147. var firstX = locationArray[0].lat;
  1148. var firstY = locationArray[0].lng;
  1149. for (var i = 0; i < locationArray.length; i++) {
  1150. var pt2 = crs.project(locationArray[i]);
  1151. var x = locationArray[i].lat;
  1152. var y = locationArray[i].lng;
  1153. midArray.push(x);
  1154. midArray.push(y);
  1155. polygonArray.push(midArray);
  1156. midArray = Array();
  1157. midArrayTmp.push(pt2.y);
  1158. midArrayTmp.push(pt2.x);
  1159. polygonArrayTmp.push(midArrayTmp);
  1160. midArrayTmp = Array();
  1161. }
  1162. midArray.push(firstX);
  1163. midArray.push(firstY);
  1164. polygonArray.push(midArray);
  1165. var pt2 = crs.project(locationArray[0]);
  1166. midArrayTmp.push(pt2.y);
  1167. midArrayTmp.push(pt2.x);
  1168. polygonArrayTmp.push(midArrayTmp);
  1169. var polygonTmp = L.polygon(polygonArrayTmp);
  1170. var polygon = L.polygon(polygonArray, {color: "#00FF00"});
  1171. resultLayer.addLayer(polygon);
  1172. let lyrs = CONST_VALUES.GX_Datas;
  1173. //debugger;
  1174. let lyrsSelect = '<div id="layers" class="layui-form queryConditionsContainer" lay-filter="lyrsSelectDiv"><div class="layui-form-item"><div class="layui-input-block" style="margin-left:30px">';
  1175. let listStr = "<input type=\'checkbox\' name=\'THENAME\' title=\'THETITLE\' id=\'THEID\' lay-skin=\'primary\' dataSetName=\'THEDATASETNAME\' dataSourceName=\'THEWS\'>";
  1176. for (let index = 0; index < lyrs.length; index++) {
  1177. const lyr = lyrs[index];
  1178. let dom = listStr.replace('THENAME', lyr.name);
  1179. dom = dom.replace('THETITLE', lyr.name);
  1180. dom = dom.replace('THEID', lyr.id);
  1181. dom = dom.replace('THEWS', lyr.dataSourceName);
  1182. dom = dom.replace('THEDATASETNAME', lyr.dataSetName);
  1183. lyrsSelect += dom;
  1184. }
  1185. lyrsSelect += '</div></div></div>';
  1186. layui.use('layer', function() {
  1187. let layer = layui.layer;
  1188. layer.open({
  1189. id: "panel-layerSelect",
  1190. type: 1,
  1191. area: ["300px", "220px"],
  1192. btn: ['确定'],
  1193. title: "请选择图层",
  1194. skin: 'layui-ext-coolskin',
  1195. content: lyrsSelect, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响
  1196. cancel: function(index, layero) {
  1197. layer.close(index);
  1198. },
  1199. yes: function(e) {
  1200. var layers = $("#layers input:checked");
  1201. if (layers.length == 0) {
  1202. layer.msg('请至少选择一个图层!', {
  1203. icon: 7
  1204. });
  1205. return;
  1206. }
  1207. layer.close(e);
  1208. for (var index = 0; index < layers.length; index++) {
  1209. let checked = layers[index].checked;
  1210. if (!checked)
  1211. continue;
  1212. var ws = layers[index].attributes.dataSourceName.value;
  1213. var dataSetName = layers[index].attributes.dataSetName.value;
  1214. var thatsubtitleP = layers[index].title;
  1215. Q.queryByBounds(thatsubtitleP,dataSetName, ws, polygonTmp, function(result,titleTmp) {
  1216. if (result.result == undefined) return;
  1217. panels.createResultPanelWithDataGrid({
  1218. subTitle: titleTmp.title,
  1219. features: result.result.features.features,
  1220. title: "范围查询结果",
  1221. //count: count,
  1222. dataSetName: titleTmp.dataSetName,
  1223. dataSourceName: titleTmp.dataSourceName
  1224. }, function() {
  1225. //debugger;
  1226. });
  1227. // 坐标系转换
  1228. // var result = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326);
  1229. //
  1230. // L.geoJSON(result, {
  1231. // style:{color: "red"},
  1232. // onEachFeature: function (feature, layer) {
  1233. // let attributes = "";
  1234. // let lyrs = CONST_VALUES.GX_Datas;
  1235. // for (var index = 0; index < lyrs.length; index++) {
  1236. // var lyr = lyrs[index];
  1237. // if(ws == lyr.dataSourceName && dataSetName == lyr.dataSetName){
  1238. // var showCols = lyr.cols;
  1239. // if(showCols != undefined && showCols != ""){
  1240. // var colsArr = showCols.split(",");
  1241. // for(var i = 0; i < colsArr.length; i++){
  1242. // var colArr = colsArr[i].split(":");
  1243. // let attValue = feature.properties[colArr[0]];
  1244. // let attr = colArr[1] + ":" + attValue + "<br>";
  1245. // attributes += attr;
  1246. // }
  1247. // }
  1248. // break;
  1249. // }
  1250. // }
  1251. // layer.bindPopup(attributes);
  1252. // }
  1253. // }).addTo(resultLayer);
  1254. });
  1255. }
  1256. }
  1257. });
  1258. layui.use(['form'], function() {
  1259. let form = layui.form;
  1260. form.render();
  1261. });
  1262. });
  1263. });
  1264. }
  1265. function drawCircle() {
  1266. drawType = "";
  1267. setDefualtStyle();
  1268. drawMapControl.handler.disable();
  1269. drawMapControl.handler.libID = 0;
  1270. drawMapControl.handler.code = 29;
  1271. drawMapControl.handler.serverUrl = serverUrl;
  1272. drawMapControl.handler.enable();
  1273. }
  1274. function drawRectangle() {
  1275. drawType = "";
  1276. setDefualtStyle();
  1277. drawMapControl.handler.disable();
  1278. drawMapControl.handler.libID = 0;
  1279. drawMapControl.handler.code = 26;
  1280. drawMapControl.handler.serverUrl = serverUrl;
  1281. drawMapControl.handler.enable();
  1282. }
  1283. //设置选择区域的线色
  1284. function setDefualtStyle() {
  1285. var defualtStyle = plotting.getDefaultStyle();
  1286. defualtStyle.defaultFlag = true;
  1287. defualtStyle.lineColor = "#00FF00";
  1288. defualtStyle.fillSymbolID = 0;
  1289. defualtStyle.fillColor = "#00FF00";
  1290. }
  1291. function processCompleted(result,selectTitle,gx) {
  1292. var gxArr = gx.split(":");
  1293. panels.createResultPanelWithDataGrid({
  1294. subTitle: selectTitle,
  1295. features: result.features,
  1296. title: "按范围查询结果",
  1297. count: result.features.length,
  1298. dataSetName: gxArr[1],
  1299. dataSourceName: gxArr[0]
  1300. }, function() {
  1301. });
  1302. }
  1303. function toggleFullScreen() {
  1304. var el = document.body;
  1305. var isFullscreen = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen;
  1306. if (!isFullscreen) { //进入全屏,多重短路表达式
  1307. (el.requestFullscreen && el.requestFullscreen()) ||
  1308. (el.mozRequestFullScreen && el.mozRequestFullScreen()) ||
  1309. (el.webkitRequestFullscreen && el.webkitRequestFullscreen()) || (el.msRequestFullscreen && el.msRequestFullscreen());
  1310. }
  1311. else { //退出全屏,三目运算符
  1312. document.exitFullscreen ? document.exitFullscreen() :
  1313. document.mozCancelFullScreen ? document.mozCancelFullScreen() :
  1314. document.webkitExitFullscreen ? document.webkitExitFullscreen() : '';
  1315. }
  1316. }
  1317. panels.createResultPanelWithChart = function(xAxis, groupBy, data, title, subTitle, xTypeName, yTypeName, typeOfECharts, callback) {
  1318. layui.use('layer', function() {
  1319. let chart;
  1320. let resizeCb = function(layerno) {
  1321. if (chart == undefined) return;
  1322. var autoHeight = $("#panel-result").height() - 100;
  1323. chart.getDom().style.height = autoHeight + "px";
  1324. chart.getDom().childNodes[0].style.height = autoHeight + "px";
  1325. chart.getDom().childNodes[0].childNodes[0].setAttribute("height",autoHeight);
  1326. chart.getDom().childNodes[0].childNodes[0].style.height = autoHeight + "px";
  1327. var autoWidth = $("#panel-result").width();
  1328. chart.getDom().style.width = autoWidth + "px";
  1329. chart.getDom().childNodes[0].style.width = autoWidth + "px";
  1330. chart.getDom().childNodes[0].childNodes[0].setAttribute("width",autoWidth);
  1331. chart.getDom().childNodes[0].childNodes[0].style.width = autoWidth + "px";
  1332. chart.resize();
  1333. }
  1334. var layer = layui.layer;
  1335. panels.createPanelBase(layer,title, resizeCb);
  1336. chart = panels.createChart(xAxis, groupBy,data, title, subTitle, xTypeName, yTypeName, typeOfECharts);
  1337. panels.createChartPages(xAxis, groupBy, data);
  1338. if (callback != undefined) {
  1339. callback();
  1340. }
  1341. });
  1342. }
  1343. panels.createChart = function(xAxis, groupBy, data, title, subTitle, xTypeName, yTypeName, typeOfECharts) {
  1344. if (data.length == 0) return;
  1345. let xAxisData = [];
  1346. for (let val in data) {
  1347. xAxisData.push(data[val][groupBy])
  1348. }
  1349. let seriesData = [];
  1350. for (let i = 0; i < xAxis.length; i++) {
  1351. let series = {};
  1352. series.name = xAxis[i];
  1353. series.type = typeOfECharts;
  1354. series.data = [];
  1355. for (let j = 0; j < data.length; j++) {
  1356. series.data.push(parseFloat(data[j][xAxis[i]]));
  1357. }
  1358. seriesData.push(series);
  1359. }
  1360. const chartDivID = "statistics-Chart";
  1361. const chartDom = "<div id='" + chartDivID + "'></div>";
  1362. let tabControl = "<div class='layui-tab' lay-filter='resultTabControl' id='THETABCONTROLID'>" +
  1363. "<ul class='layui-tab-title'></ul>" +
  1364. "<div class='layui-tab-content'></div></div>";
  1365. let tabControlID = utils.guid();
  1366. tabControl = tabControl.replace('THETABCONTROLID', tabControlID);
  1367. if ($('div[lay-filter="resultTabControl"]').length == 0) {
  1368. $(tabControl).appendTo($("#panel-result"));
  1369. }
  1370. layui.use('element', function() {
  1371. let element = layui.element;
  1372. element.render();
  1373. let tabID = utils.guid();
  1374. element.tabAdd('resultTabControl', {
  1375. title: "统计图",
  1376. content: chartDom //支持传入html
  1377. ,
  1378. id: tabID
  1379. });
  1380. });
  1381. const myChart = echarts.init(document.getElementById("statistics-Chart"), null);
  1382. // 指定图表的配置项和数据
  1383. const option = {
  1384. tooltip: {},
  1385. legend: {
  1386. bottom: '0',
  1387. left: 'right',
  1388. data: xAxis,
  1389. textStyle: {
  1390. color: "#fffffb"
  1391. }
  1392. },
  1393. toolbox: {
  1394. feature: {
  1395. magicType: {
  1396. type: ['line', 'bar']
  1397. },
  1398. saveAsImage: { pixelRatio: 2 }
  1399. },
  1400. iconStyle: {
  1401. color: "#fffffb"
  1402. }
  1403. },
  1404. xAxis: {
  1405. data: xAxisData,
  1406. name: xTypeName,
  1407. axisLabel: {
  1408. interval: 0,
  1409. rotate: 30,
  1410. color: "#fffffb",
  1411. formatter: function(value, index) {
  1412. return value /* + 'mm'*/ ;
  1413. }
  1414. }
  1415. },
  1416. yAxis: {
  1417. axisLine: {
  1418. onZero: false,
  1419. lineStyle: {
  1420. color: "#fffffb"
  1421. }
  1422. },
  1423. name: yTypeName
  1424. },
  1425. series: seriesData
  1426. };
  1427. // 使用刚指定的配置项和数据显示图表。
  1428. myChart.setOption(option);
  1429. var autoHeight = $("#panel-result").height() - 100;
  1430. myChart.getDom().style.height = autoHeight + "px";
  1431. myChart.getDom().childNodes[0].style.height = autoHeight + "px";
  1432. myChart.getDom().childNodes[0].childNodes[0].setAttribute("height",autoHeight);
  1433. myChart.getDom().childNodes[0].childNodes[0].style.height = autoHeight + "px";
  1434. var autoWidth = $("#panel-result").width();
  1435. myChart.getDom().style.width = autoWidth + "px";
  1436. myChart.getDom().childNodes[0].style.width = autoWidth + "px";
  1437. myChart.getDom().childNodes[0].childNodes[0].setAttribute("width",autoWidth);
  1438. myChart.getDom().childNodes[0].childNodes[0].style.width = autoWidth + "px";
  1439. myChart.resize();
  1440. const thisTitle = $('.layui-layer-title');
  1441. thisTitle.addClass("layui-layer-title-transparent");
  1442. return myChart;
  1443. }
  1444. panels.createChartPages = function(xAxis, groupBy, data) {
  1445. if (data.length == 0) return;
  1446. let tableNew = "<table id='THETABLEID' lay-filter='THETABLEID'></table>";
  1447. const tableNewID = utils.guid();
  1448. while (tableNew.indexOf('THETABLEID') > -1)
  1449. tableNew = tableNew.replace('THETABLEID', tableNewID);
  1450. let cols = [{ field: groupBy, title: groupBy, sort: true }];
  1451. for (let i = 0; i < xAxis.length; i++) {
  1452. cols.push({ field: xAxis[i], title: xAxis[i], sort: true });
  1453. }
  1454. let datas = data;
  1455. let tabControl = "<div class='layui-tab' lay-filter='resultTabControl' id='THETABCONTROLID'>" +
  1456. "<ul class='layui-tab-title'></ul>" +
  1457. "<div class='layui-tab-content'></div></div>";
  1458. let tabControlID = utils.guid();
  1459. tabControl = tabControl.replace('THETABCONTROLID', tabControlID);
  1460. if ($('div[lay-filter="resultTabControl"]').length == 0) {
  1461. $(tabControl).appendTo($("#panel-result"));
  1462. }
  1463. layui.use('element', function() {
  1464. let element = layui.element;
  1465. element.render();
  1466. let tabID = utils.guid();
  1467. element.tabAdd('resultTabControl', {
  1468. title: "统计报表",
  1469. content: tableNew //支持传入html
  1470. ,
  1471. id: tabID
  1472. });
  1473. layui.use('table', function() {
  1474. let table = layui.table;
  1475. table.render({
  1476. elem: '#' + tableNewID,
  1477. data: datas,
  1478. page: true,
  1479. "lay-size": 'sm',
  1480. limit: 6,
  1481. done: function (res, curr, count){
  1482. $("table").css("width", "100%");
  1483. },
  1484. cols: [cols]
  1485. });
  1486. });
  1487. element.tabChange('resultTabControl', tabID);
  1488. const thisTitle = $('.layui-layer-title');
  1489. thisTitle.addClass("layui-layer-title-transparent");
  1490. });
  1491. }
  1492. function dmfx(){
  1493. map.off('click');
  1494. //map.off('dblclick');
  1495. $("#tips").css('display', 'block');
  1496. var isFirstPoint = true; //判断是否是起始点
  1497. var latLngTemp = null;//存储上一点击点临时变量
  1498. var resultDis = 0; //总距
  1499. map.on('click', function(ev) {
  1500. TempLayer.clearLayers();
  1501. $("#tips").css('display', 'none');
  1502. var polyLine;
  1503. if(isFirstPoint) {
  1504. L.marker([ev.latlng.lat, ev.latlng.lng]).addTo(resultLayer); //起始点
  1505. latLngTemp = ev.latlng; //存储上一点击点
  1506. isFirstPoint = false;
  1507. } else {
  1508. if(!latLngTemp.equals(ev.latlng)) { //避免出现结束双击,导致距离为0
  1509. L.marker([ev.latlng.lat, ev.latlng.lng]).addTo(resultLayer); //终点
  1510. map.off('click');
  1511. map.off('mousemove');
  1512. polyLine = L.polyline([ //与上一点连线
  1513. [latLngTemp.lat, latLngTemp.lng],
  1514. [ev.latlng.lat, ev.latlng.lng]
  1515. ], {
  1516. color: "#00FF00"
  1517. });
  1518. resultLayer.addLayer(polyLine);
  1519. // 地图上画的线
  1520. var line1 = turf.lineString([[latLngTemp.lng, latLngTemp.lat], [ev.latlng.lng, ev.latlng.lat]]);
  1521. var pt1 = crs.project(latLngTemp);
  1522. var pt2 = crs.project(ev.latlng);
  1523. var polyLineTemp = L.polyline([ //与上一点连线
  1524. [pt1.y, pt1.x],
  1525. [pt2.y, pt2.x]
  1526. ]);
  1527. var dataSourceName = CONST_VALUES.GX_DataSourceName;
  1528. var dataSetName = CONST_VALUES.GX_DataSetName;
  1529. // 查询管线两端点对应的数据信息
  1530. var geometryParam = new SuperMap.GetFeaturesByGeometryParameters({
  1531. datasetNames: [dataSourceName + ":" + dataSetName],
  1532. geometry: polyLineTemp,
  1533. spatialQueryMode: "INTERSECT"
  1534. });
  1535. L.supermap
  1536. .featureService(dataUrl)
  1537. .getFeaturesByGeometry(geometryParam, function (serviceResult) {
  1538. // 坐标系转换
  1539. var result = L.Util.transform(serviceResult.result.features, crs, L.CRS.EPSG4326);
  1540. L.geoJSON(result, {
  1541. style:{color: "red"},
  1542. onEachFeature: function (feature, layer) {
  1543. let attributes = "";
  1544. let lyrs = CONST_VALUES.GX_Datas;
  1545. for (var index = 0; index < lyrs.length; index++) {
  1546. var lyr = lyrs[index];
  1547. if(dataSourceName == lyr.dataSourceName && dataSetName == lyr.dataSetName){
  1548. var showCols = lyr.cols;
  1549. if(showCols != undefined && showCols != ""){
  1550. var colsArr = showCols.split(",");
  1551. for(var i = 0; i < colsArr.length; i++){
  1552. var colArr = colsArr[i].split(":");
  1553. let attValue = feature.properties[colArr[0]];
  1554. let attr = colArr[1] + ":" + attValue + "<br>";
  1555. attributes += attr;
  1556. }
  1557. }
  1558. break;
  1559. }
  1560. }
  1561. layer.bindPopup(attributes);
  1562. }
  1563. }).addTo(resultLayer);
  1564. if(result.features.length>0){
  1565. dmfxProcess(line1,result);
  1566. }
  1567. });
  1568. }
  1569. }
  1570. });
  1571. map.on("mousemove", function(ev) {
  1572. if(latLngTemp == null){ return }
  1573. TempLayer.clearLayers();
  1574. var TempLine = L.polyline([ //虚线临时线段
  1575. [latLngTemp.lat, latLngTemp.lng],
  1576. [ev.latlng.lat, ev.latlng.lng]
  1577. ], {
  1578. color: "red",
  1579. dashArray: "5,5"
  1580. });
  1581. TempLayer.addLayer(TempLine);
  1582. });
  1583. }
  1584. function dmfxProcess(drawLint,result){
  1585. var pts = '';
  1586. for(var i = 0; i < result.features.length; i++)
  1587. {
  1588. var feature = result.features[i];
  1589. var coordinates = feature.geometry.coordinates;
  1590. var QSDH = feature.properties["QSDH"]; // 起始点号
  1591. var ZDDH = feature.properties["ZDDH"]; // 终点点号
  1592. if(i < result.features.length-1){
  1593. pts += "'" + QSDH + "','" + ZDDH + "',";
  1594. }
  1595. else{
  1596. pts += "'" + QSDH + "','" + ZDDH + "'";
  1597. }
  1598. }
  1599. var sqlTemp = "BSM in (" + pts + ")";
  1600. var sqlParam = new SuperMap.GetFeaturesBySQLParameters({
  1601. queryParameter: {
  1602. name: CONST_VALUES.JD_DataSetName + "@" + CONST_VALUES.JD_DataSourceName,
  1603. attributeFilter: sqlTemp
  1604. },
  1605. datasetNames: [CONST_VALUES.JD_DataSourceName + ":" + CONST_VALUES.JD_DataSetName]
  1606. });
  1607. L.supermap.featureService(dataUrl).getFeaturesBySQL(sqlParam, function (serviceResult) {
  1608. if(serviceResult.result.features.features.length > 0){
  1609. var resultData = L.Util.transform(serviceResult.result.features, crs, L.CRS.EPSG4326);
  1610. var allData = new Array();
  1611. var allMaxGC = 0, allMinGC = 0;
  1612. var preX = undefined;
  1613. var preY = undefined;
  1614. for(var i = 0; i < result.features.length; i++){
  1615. var feature = result.features[i];
  1616. var coordinates = feature.geometry.coordinates;
  1617. var gdbh = feature.properties["BSM"]; // 管段编号
  1618. var QSDH = feature.properties["QSDH"]; // 起始点号
  1619. var ZDDH = feature.properties["ZDDH"]; // 终点点号
  1620. var gj = feature.properties["GJ"]; // 管径
  1621. var smid = feature.properties["SMID"];
  1622. // 地图上划线查询到的管线
  1623. var line2 = turf.lineString([[coordinates[0][0], coordinates[0][1]], [coordinates[1][0], coordinates[1][1]]]);
  1624. // 交叉点
  1625. var intersects = turf.lineIntersect(drawLint, line2);
  1626. var pt1Data = undefined;
  1627. var pt2Data = undefined;
  1628. for(var j = 0; j < resultData.features.length; j++){
  1629. var bsm = resultData.features[j].properties["BSM"];
  1630. if(bsm == QSDH){
  1631. pt1Data = resultData.features[j];
  1632. }
  1633. else if(bsm == ZDDH){
  1634. pt2Data = resultData.features[j];
  1635. }
  1636. if(pt1Data != undefined && pt2Data != undefined){
  1637. break;
  1638. }
  1639. }
  1640. if(pt1Data == undefined || pt2Data == undefined){
  1641. continue;
  1642. }
  1643. var dmgcPT1 = pt1Data.properties["DMGC"] * 1; // 地面高程
  1644. var msPT1 = pt1Data.properties["MS"] * 1; // 埋深
  1645. var xPT1 = pt1Data.geometry.coordinates[0]; // x坐标
  1646. var yPT1 = pt1Data.geometry.coordinates[1]; // y坐标
  1647. var dmgcPT2 = pt2Data.properties["DMGC"] * 1; // 地面高程
  1648. var msPT2 = pt2Data.properties["MS"] * 1; // 埋深
  1649. var xPT2 = pt2Data.geometry.coordinates[0]; // x坐标
  1650. var yPT2 = pt2Data.geometry.coordinates[1]; // y坐标
  1651. var xPtTmp = intersects.features[0].geometry.coordinates[0];
  1652. var yPtTmp = intersects.features[0].geometry.coordinates[1]
  1653. var dmgc = undefined; // 地面高程
  1654. var ms = undefined; // 埋深
  1655. var gxgc = undefined; // 管线高程
  1656. var maxGC = undefined,minGC = undefined,jl=0;
  1657. if(dmgcPT1 == dmgcPT2){
  1658. dmgc = dmgcPT1;
  1659. maxGC = dmgc + 1;
  1660. }
  1661. else if (dmgcPT1 > dmgcPT2){
  1662. maxGC = dmgcPT1 + 1;
  1663. 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)));
  1664. }
  1665. else {
  1666. maxGC = dmgcPT2 + 1;
  1667. 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)));
  1668. }
  1669. if(msPT1 == msPT2){
  1670. ms = msPT1;
  1671. }
  1672. else if(msPT1 > msPT2){
  1673. 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)));
  1674. }
  1675. else{
  1676. 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)));
  1677. }
  1678. gxgc = dmgc.toFixed(2) - ms.toFixed(2);
  1679. minGC = gxgc - 1;
  1680. var markerTemp = L.marker([yPtTmp, xPtTmp]).addTo(resultLayer);
  1681. var content = "地面高程(M):" + dmgc.toFixed(2) + "<br>管线高程(M):" + gxgc.toFixed(2) + "<br>埋深(M):" + ms.toFixed(2) + "<br>管径(MM):" + gj;
  1682. markerTemp.bindPopup(content).openPopup(markerTemp.getLatLng());
  1683. //drawDmfx(dmgc.toFixed(2),gxgc.toFixed(2),ms.toFixed(2),gj,jl,maxGC.toFixed(2),minGC.toFixed(2),i);
  1684. if(allMaxGC < maxGC){
  1685. allMaxGC = maxGC.toFixed(2);
  1686. }
  1687. if(allMinGC == 0 || allMinGC > minGC){
  1688. allMinGC = minGC.toFixed(2);
  1689. }
  1690. if(preX != undefined && preY != undefined){
  1691. var from = turf.point([preX, preY]);
  1692. var to = turf.point([xPtTmp, yPtTmp]);
  1693. var options = {units: 'kilometers'};
  1694. jl = turf.distance(from, to, options) * 1000;
  1695. }
  1696. preX = xPtTmp;
  1697. preY = yPtTmp;
  1698. var entityData = {};
  1699. entityData.smid = smid;
  1700. entityData.gdbh = gdbh;
  1701. entityData.dmgc = dmgc.toFixed(2);
  1702. entityData.dmgc = dmgc.toFixed(2);
  1703. entityData.gxgc = gxgc.toFixed(2);
  1704. entityData.ms = ms.toFixed(2);
  1705. entityData.gj = gj;
  1706. entityData.jl = jl.toFixed(2);
  1707. entityData.maxGC = maxGC.toFixed(2);
  1708. entityData.minGC = minGC.toFixed(2);
  1709. allData.push(entityData);
  1710. }
  1711. drawDmfx(allData,allMaxGC,allMinGC);
  1712. }
  1713. });
  1714. }
  1715. // 断面分析图
  1716. function drawDmfx(allData,allMaxGC,allMinGC){
  1717. let lyrsSelect = '<div class="q-title-in-Sub" style="margin-top: 5px;margin-bottom: 5px;"><span class="q-title-in-Sub-img"></span><span class="qs-q">管线横断面图</span></div>';
  1718. lyrsSelect += '<canvas id="tutorial" width="800" height="600" style="border: 1px solid white;margin:0 auto;"></canvas>';
  1719. lyrsSelect += '<div class="q-title-in-Sub" style="margin-top: 10px;"><span class="q-title-in-Sub-img"></span><span class="qs-q">管线纵刨面图</span></div>';
  1720. lyrsSelect += '<div id="gxlb" class="query-type-enum">';
  1721. for(var i = 0; i < allData.length; i++){
  1722. lyrsSelect += '<div style="margin-left:18px" onclick="drawZpm(\'' + allData[i].smid +'\')"><span>' + allData[i].gdbh + '</span></div>';
  1723. }
  1724. lyrsSelect += '</div>';
  1725. layui.use('layer', function() {
  1726. let layer = layui.layer;
  1727. layer.open({
  1728. id: "panel-drawDmfx",
  1729. type: 1,
  1730. area: ["802px", "750px"],
  1731. title: "城市地下管线断面分析",
  1732. skin: 'layui-ext-coolskin',
  1733. content: lyrsSelect, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响
  1734. cancel: function (index, layero) {
  1735. layer.close(index);
  1736. }
  1737. });
  1738. var canvas = document.getElementById('tutorial');
  1739. drawCanvas(canvas,allData,allMaxGC,allMinGC);
  1740. layui.use(['form'], function() {
  1741. let form = layui.form;
  1742. form.render();
  1743. });
  1744. });
  1745. }
  1746. // 管线纵刨面图
  1747. function drawZpm(smid){
  1748. let lyrsSelect = '<canvas id="tutorialZpm" width="800" height="600" style="border: 1px solid white;margin:0 auto;"></canvas>';
  1749. layui.use('layer', function() {
  1750. let layer = layui.layer;
  1751. layer.open({
  1752. id: "panel-drawZpm",
  1753. type: 1,
  1754. area: ["802px", "750px"],
  1755. title: "城市地下管线纵刨面图",
  1756. skin: 'layui-ext-coolskin',
  1757. content: lyrsSelect, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响
  1758. cancel: function (index, layero) {
  1759. layer.close(index);
  1760. }
  1761. });
  1762. var canvas = document.getElementById('tutorialZpm');
  1763. drawCanvasZpm(canvas,smid);
  1764. layui.use(['form'], function() {
  1765. let form = layui.form;
  1766. form.render();
  1767. });
  1768. });
  1769. }
  1770. // 横断面
  1771. function drawCanvas(canvas,allData,allMaxGC,allMinGC){
  1772. // dmgc,gxgc,ms,gj,jl,maxGC,minGC
  1773. if(!canvas.getContext) return;
  1774. var ctx = canvas.getContext("2d");
  1775. var start = 600;
  1776. // 绘制下方表格
  1777. drawTable(ctx,20,start,30, 0);
  1778. // 绘制刻度线
  1779. var rs = drawScale(ctx,allMaxGC,allMinGC);
  1780. // 绘制管线及数据dmgc,gxgc,gxms,gj,jl,xyRs,maxGC,minGC
  1781. drawGXData(ctx, rs, allData, allMaxGC,allMinGC);
  1782. }
  1783. // 纵剖面
  1784. function drawCanvasZpm(canvas,smid){
  1785. if(!canvas.getContext) return;
  1786. var sqlParam = new SuperMap.GetFeaturesBySQLParameters({
  1787. queryParameter: {
  1788. name: CONST_VALUES.GX_DataSetName + "@" + CONST_VALUES.GX_DataSourceName,
  1789. attributeFilter: "SMID = " + smid
  1790. },
  1791. datasetNames: [CONST_VALUES.GX_DataSourceName + ":" + CONST_VALUES.GX_DataSetName]
  1792. });
  1793. L.supermap.featureService(dataUrl).getFeaturesBySQL(sqlParam, function (serviceResult) {
  1794. if (serviceResult.result.features.features.length > 0) {
  1795. var feature = serviceResult.result.features.features[0];
  1796. var QSDH = feature.properties["QSDH"]; // 起始点号
  1797. var ZDDH = feature.properties["ZDDH"]; // 终点点号
  1798. var gj = feature.properties["GJ"]; // 管径
  1799. var cd = (feature.properties["CD"] * 1).toFixed(2); // 长度
  1800. var sqlTemp = "BSM in ('" + QSDH + "','" + ZDDH + "')";
  1801. var sqlParamPt = new SuperMap.GetFeaturesBySQLParameters({
  1802. queryParameter: {
  1803. name: CONST_VALUES.JD_DataSetName + "@" + CONST_VALUES.JD_DataSourceName,
  1804. attributeFilter: sqlTemp
  1805. },
  1806. datasetNames: [ CONST_VALUES.JD_DataSourceName + ":" + CONST_VALUES.JD_DataSetName]
  1807. });
  1808. L.supermap.featureService(dataUrl).getFeaturesBySQL(sqlParamPt, function (serviceResult) {
  1809. if (serviceResult.result.features.features.length > 1) {
  1810. var feature0 = serviceResult.result.features.features[0];
  1811. var feature1 = serviceResult.result.features.features[1];
  1812. var featureQ,featureZ;
  1813. if(QSDH == feature0.properties["BSM"]){
  1814. featureQ = feature0;
  1815. featureZ = feature1;
  1816. }
  1817. else{
  1818. featureQ = feature1;
  1819. featureZ = feature0;
  1820. }
  1821. var dmgcQ = (featureQ.properties["DMGC"] * 1).toFixed(2); // 起点地面高程
  1822. var gxmsQ = (featureQ.properties["MS"] * 1).toFixed(2); // 起点埋深
  1823. var dmgcZ = (featureZ.properties["DMGC"] * 1).toFixed(2); // 终点地面高程
  1824. var gxmsZ = (featureZ.properties["MS"] * 1).toFixed(2); // 终点埋深
  1825. var gdgcQ = (dmgcQ-gxmsQ).toFixed(2); // 起点管顶高程
  1826. var gdgcZ = (dmgcZ-gxmsZ).toFixed(2); // 终点管顶高程
  1827. var maxGC = 0,minGC = 0;
  1828. if(dmgcQ >= dmgcZ){
  1829. maxGC = (dmgcQ * 1 + 1).toFixed(2);
  1830. }
  1831. else{
  1832. maxGC = (dmgcZ * 1 + 1).toFixed(2);
  1833. }
  1834. if(gdgcQ >= gdgcZ){
  1835. minGC = (gdgcZ * 1 - 1).toFixed(2);
  1836. }
  1837. else{
  1838. minGC = (gdgcQ * 1 - 1).toFixed(2);
  1839. }
  1840. var ctx = canvas.getContext("2d");
  1841. var start = 600;
  1842. // 绘制下方表格
  1843. drawTable(ctx,20,start,30, 1);
  1844. // 绘制刻度线
  1845. var xyRs = drawScale(ctx,maxGC,minGC);
  1846. drawGXZpmData(ctx,dmgcQ,gxmsQ,gdgcQ,dmgcZ,gxmsZ,gdgcZ,gj,cd,xyRs,maxGC,minGC);
  1847. }
  1848. });
  1849. }
  1850. });
  1851. }
  1852. // 绘制下方表格
  1853. function drawTable(ctx,startX,startY,rowHight,type){
  1854. for(var i = 0; i<5;i++) {
  1855. var y = startY - (i + 1 ) * rowHight;
  1856. ctx.beginPath(); //新建一条path
  1857. ctx.moveTo(startX, y); //把画笔移动到指定的坐标
  1858. ctx.lineTo(780, y); //绘制一条从当前位置到指定坐标的直线.
  1859. ctx.strokeStyle = "white";
  1860. //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做
  1861. ctx.closePath();
  1862. ctx.stroke(); //绘制路径。
  1863. ctx.font = "18px Arial";
  1864. ctx.fillStyle ="white";
  1865. var content = "";
  1866. switch(i){
  1867. case 4:
  1868. content = "地面高程(M)";
  1869. break;
  1870. case 3:
  1871. content = "管线高程(M)";
  1872. break;
  1873. case 2:
  1874. content = "管线埋深(M)";
  1875. break;
  1876. case 1:
  1877. content = "管 径(MM)";
  1878. break;
  1879. case 0:
  1880. if(type==0){
  1881. content = "距 离(M)";
  1882. }else{
  1883. content = "长 度(M)";
  1884. }
  1885. break;
  1886. }
  1887. ctx.fillText(content, startX + 10 , y+(rowHight*4/5));
  1888. }
  1889. ctx.beginPath(); //新建一条path
  1890. ctx.moveTo(startX, 450); //把画笔移动到指定的坐标
  1891. ctx.lineTo(startX, 800); //绘制一条从当前位置到指定坐标的直线.
  1892. //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做
  1893. ctx.closePath();
  1894. ctx.stroke(); //绘制路径。
  1895. ctx.beginPath(); //新建一条path
  1896. ctx.moveTo(780, 450); //把画笔移动到指定的坐标
  1897. ctx.lineTo(780, 800); //绘制一条从当前位置到指定坐标的直线.
  1898. //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做
  1899. ctx.closePath();
  1900. ctx.stroke(); //绘制路径。
  1901. }
  1902. // 绘制刻度线
  1903. function drawScale(ctx,maxGC,minGC){
  1904. ctx.beginPath(); //新建一条path
  1905. ctx.moveTo(150, 20); //把画笔移动到指定的坐标
  1906. ctx.lineTo(150, 800); //绘制一条从当前位置到指定坐标的直线.
  1907. //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做
  1908. ctx.closePath();
  1909. ctx.stroke(); //绘制路径。
  1910. var rs = [];
  1911. for(var i = 0; i<5;i++){
  1912. var y = 70 + i*70;
  1913. ctx.beginPath(); //新建一条path
  1914. ctx.moveTo(150, y); //把画笔移动到指定的坐标
  1915. ctx.lineTo(150-10, y); //绘制一条从当前位置到指定坐标的直线.
  1916. //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做
  1917. ctx.closePath();
  1918. ctx.stroke(); //绘制路径。
  1919. if(i==0 || i == 4){
  1920. rs.push(y);
  1921. }
  1922. ctx.font = "18px Arial"
  1923. var content = maxGC - i*(maxGC-minGC)/4;
  1924. ctx.fillText(content.toFixed(2), 150 - 60 , y+20);
  1925. }
  1926. return rs;
  1927. }
  1928. // 绘制管线及数据
  1929. function drawGXData(ctx, xyRs, allData, maxGC, minGC){
  1930. var dataNum = allData.length;
  1931. for(var i = 0; i < dataNum; i++){
  1932. var entityData = allData[i];
  1933. var x = 150 + (800 - 150 - 20) / (dataNum + 1) * (i+1);
  1934. var gdbh = entityData.gdbh;
  1935. var dmgc = entityData.dmgc;
  1936. var gxgc = entityData.gxgc;
  1937. var gxms = entityData.ms;
  1938. var gj = entityData.gj;
  1939. var jl = entityData.jl;
  1940. var y = xyRs[1] - (gxgc-minGC)*(xyRs[1]-xyRs[0])/(maxGC-minGC);
  1941. var pyl = gj / 10 / 2;
  1942. ctx.beginPath();
  1943. ctx.arc(x,y+pyl,pyl,0,2*Math.PI);
  1944. ctx.setLineDash([10, 0]); // [实线长度, 间隙长度]
  1945. ctx.strokeStyle = "#ed1941";
  1946. ctx.stroke();
  1947. ctx.beginPath(); //新建一条path
  1948. ctx.moveTo(x, y+pyl*2); //把画笔移动到指定的坐标
  1949. ctx.lineTo(x, 800); //绘制一条从当前位置到指定坐标的直线.
  1950. ctx.setLineDash([10, 5]); // [实线长度, 间隙长度]
  1951. ctx.strokeStyle = "#2AC2FC";
  1952. //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做
  1953. ctx.closePath();
  1954. ctx.stroke(); //绘制路径。
  1955. ctx.fillText(gdbh, x, y - 5);
  1956. ctx.fillText(dmgc, x + 5, 450+25);
  1957. ctx.fillText(gxgc, x + 5, 450+55);
  1958. ctx.fillText(gxms, x + 5, 450+85);
  1959. ctx.fillText(gj, x + 5, 450+115);
  1960. ctx.fillText(jl == 0 ? "" : jl, x + 5 , 450+145);
  1961. }
  1962. }
  1963. // 绘制管线纵剖面图及数据
  1964. function drawGXZpmData(ctx,dmgcQ,gxmsQ,gdgcQ,dmgcZ,gxmsZ,gdgcZ,gj,cd,xyRs,maxGC,minGC){
  1965. var xQ = 200,xZ = 730;
  1966. var yGDQ = xyRs[1] - (gdgcQ-minGC)*(xyRs[1]-xyRs[0])/(maxGC-minGC);
  1967. var yGDZ = xyRs[1] - (gdgcZ-minGC)*(xyRs[1]-xyRs[0])/(maxGC-minGC);
  1968. var yDMQ = xyRs[1] - (dmgcQ-minGC)*(xyRs[1]-xyRs[0])/(maxGC-minGC);
  1969. var yDMZ = xyRs[1] - (dmgcZ-minGC)*(xyRs[1]-xyRs[0])/(maxGC-minGC);
  1970. var pyl = gj / 10;
  1971. // 画管线上沿
  1972. ctx.beginPath(); //新建一条path
  1973. ctx.moveTo(xQ, yGDQ); //把画笔移动到指定的坐标
  1974. ctx.lineTo(xZ, yGDZ); //绘制一条从当前位置到指定坐标的直线.
  1975. //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做
  1976. ctx.closePath();
  1977. ctx.stroke(); //绘制路径。
  1978. // 画管线下沿
  1979. ctx.beginPath(); //新建一条path
  1980. ctx.moveTo(xQ, yGDQ + pyl); //把画笔移动到指定的坐标
  1981. ctx.lineTo(xZ, yGDZ + pyl); //绘制一条从当前位置到指定坐标的直线.
  1982. //ctx.strokeStyle = "#009ad6";
  1983. //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做
  1984. ctx.closePath();
  1985. ctx.stroke(); //绘制路径。
  1986. // 画地面线
  1987. ctx.beginPath(); //新建一条path
  1988. ctx.moveTo(xQ, yDMQ); //把画笔移动到指定的坐标
  1989. ctx.lineTo(xZ, yDMZ); //绘制一条从当前位置到指定坐标的直线.
  1990. ctx.strokeStyle = "#2AC2FC";
  1991. //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做
  1992. ctx.closePath();
  1993. ctx.stroke(); //绘制路径。
  1994. // 画起点竖线
  1995. ctx.beginPath(); //新建一条path
  1996. ctx.moveTo(xQ, yDMQ); //把画笔移动到指定的坐标
  1997. ctx.lineTo(xQ, yGDQ + pyl); //绘制一条从当前位置到指定坐标的直线.
  1998. ctx.strokeStyle = "#2AC2FC";
  1999. //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做
  2000. ctx.closePath();
  2001. ctx.stroke(); //绘制路径。
  2002. // 画终点竖线
  2003. ctx.beginPath(); //新建一条path
  2004. ctx.moveTo(xZ, yDMZ); //把画笔移动到指定的坐标
  2005. ctx.lineTo(xZ, yGDZ + pyl); //绘制一条从当前位置到指定坐标的直线.
  2006. ctx.strokeStyle = "#2AC2FC";
  2007. //闭合路径。会拉一条从当前点到path起始点的直线。如果当前点与起始点重合,则什么都不做
  2008. ctx.closePath();
  2009. ctx.stroke(); //绘制路径。
  2010. // 起点
  2011. ctx.fillText(dmgcQ, xQ , 450+25);
  2012. ctx.fillText(gdgcQ, xQ , 450+55);
  2013. ctx.fillText(gxmsQ, xQ , 450+85);
  2014. // 终点
  2015. ctx.fillText(dmgcZ, xZ - 40 , 450+25);
  2016. ctx.fillText(gdgcZ, xZ - 40 , 450+55);
  2017. ctx.fillText(gxmsZ, xZ - 40 , 450+85);
  2018. ctx.fillText(gj, 460 , 450+115);
  2019. ctx.fillText(cd == 0 ? "" : cd, 460 , 450+145);
  2020. }
  2021. // 碰撞分析(包括垂直净距和水平净距分析)
  2022. function pzfx(){
  2023. map.on('click', function (evt) {
  2024. var infoX = evt.containerPoint.x;
  2025. var infoY = evt.containerPoint.y;
  2026. var winX = evt.target._size.x;
  2027. var winY = evt.target._size.y;
  2028. var pt = crs.project(evt.latlng);
  2029. var _Point = L.marker([pt.y, pt.x]);
  2030. var dataSourceName = CONST_VALUES.GX_DataSourceName;
  2031. var dataSetName = CONST_VALUES.GX_DataSetName;
  2032. var bufferParam = new SuperMap.GetFeaturesByBufferParameters({
  2033. datasetNames: [dataSourceName + ":" + dataSetName],
  2034. bufferDistance: CONST_VALUES.QUERY_BufferDistance,
  2035. geometry: _Point
  2036. });
  2037. // 判断点击的点是否在管线上
  2038. L.supermap
  2039. .featureService(dataUrl)
  2040. .getFeaturesByBuffer(bufferParam, function (result) {
  2041. if(result.result.features.features.length > 0){
  2042. // 坐标系转换
  2043. var result = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326);
  2044. L.geoJSON(result, {
  2045. style:{color: "#ef5b9c"},
  2046. onEachFeature: function (feature, layer) {
  2047. let attributes = "";
  2048. let lyrs = CONST_VALUES.GX_Datas;
  2049. for (var index = 0; index < lyrs.length; index++) {
  2050. var lyr = lyrs[index];
  2051. if(dataSourceName == lyr.dataSourceName && dataSetName == lyr.dataSetName){
  2052. var showCols = lyr.cols;
  2053. if(showCols != undefined && showCols != ""){
  2054. var colsArr = showCols.split(",");
  2055. for(var i = 0; i < colsArr.length; i++){
  2056. var colArr = colsArr[i].split(":");
  2057. let attValue = feature.properties[colArr[0]];
  2058. let attr = colArr[1] + ":" + attValue + "<br>";
  2059. attributes += attr;
  2060. }
  2061. }
  2062. break;
  2063. }
  2064. }
  2065. layer.bindPopup(attributes);
  2066. }
  2067. }).addTo(resultLayer);
  2068. var feature = result.features[0];
  2069. var sourceCoordinates = feature.geometry.coordinates;
  2070. var QSDH = feature.properties["QSDH"]; // 起始点号
  2071. var ZDDH = feature.properties["ZDDH"]; // 终点点号
  2072. var gj = feature.properties["GJ"]; // 管径
  2073. var gxSmid = feature.properties["SMID"];
  2074. var bsm = feature.properties["BSM"];
  2075. var fldm = feature.properties["FLDM"];
  2076. var sqlTemp = "BSM in ('" + QSDH + "','" + ZDDH + "')";
  2077. var sqlParamPt = new SuperMap.GetFeaturesBySQLParameters({
  2078. queryParameter: {
  2079. name: CONST_VALUES.JD_DataSetName + "@" + CONST_VALUES.JD_DataSourceName,
  2080. attributeFilter: sqlTemp
  2081. },
  2082. datasetNames: [ CONST_VALUES.JD_DataSourceName + ":" + CONST_VALUES.JD_DataSetName]
  2083. });
  2084. L.supermap.featureService(dataUrl).getFeaturesBySQL(sqlParamPt, function (serviceResult) {
  2085. if (serviceResult.result.features.features.length > 1) {
  2086. var feature0 = serviceResult.result.features.features[0];
  2087. var feature1 = serviceResult.result.features.features[1];
  2088. var featureQ, featureZ;
  2089. if (QSDH == feature0.properties["BSM"]) {
  2090. featureQ = feature0;
  2091. featureZ = feature1;
  2092. } else {
  2093. featureQ = feature1;
  2094. featureZ = feature0;
  2095. }
  2096. var xQ = featureQ.properties["X"]; // X坐标
  2097. var yQ = featureQ.properties["Y"]; // Y坐标
  2098. var dmgcQ = (featureQ.properties["DMGC"] * 1).toFixed(2); // 起点地面高程
  2099. var gxmsQ = (featureQ.properties["MS"] * 1).toFixed(2); // 起点埋深
  2100. var xZ = featureZ.properties["X"]; // X坐标
  2101. var yZ = featureZ.properties["Y"]; // Y坐标
  2102. var dmgcZ = (featureZ.properties["DMGC"] * 1).toFixed(2); // 终点地面高程
  2103. var gxmsZ = (featureZ.properties["MS"] * 1).toFixed(2); // 终点埋深
  2104. let lyrsSelect = '<div class="layui-form" lay-filter="lyrsSelectDiv"><div class="layui-form-item"><div class="layui-input-block" style="margin-left:20px;">';
  2105. lyrsSelect += '<input type="radio" checked name="fxType" value="0" title="碰撞分析" />';
  2106. lyrsSelect += '<input type="radio" name="fxType" value="1" title="水平净距分析" />';
  2107. lyrsSelect += '<input type="radio" name="fxType" value="2" title="垂直净距分析" />';
  2108. lyrsSelect += '</div></div></div>';
  2109. lyrsSelect += '<div style="margin-left:30px;color: #ffffff;">';
  2110. lyrsSelect += "<div style='margin-bottom: 5px;'>管线类型:" + fldm + "</div>";
  2111. lyrsSelect += "<div style='margin-bottom: 5px;'>起点X坐标值:" + xQ + "</div>";
  2112. lyrsSelect += "<div style='margin-bottom: 5px;'>起点Y坐标值:" + yQ + "</div>";
  2113. lyrsSelect += "<div style='margin-bottom: 5px;'>起点高程值:" + (dmgcQ-gxmsQ) + "</div>";
  2114. lyrsSelect += "<div style='margin-bottom: 5px;'>终点X坐标值:" + xZ + "</div>";
  2115. lyrsSelect += "<div style='margin-bottom: 5px;'>终点Y坐标值:" + yZ + "</div>";
  2116. lyrsSelect += "<div style='margin-bottom: 5px;'>终点高程值:" + (dmgcZ - gxmsZ) + "</div>";
  2117. lyrsSelect += "<div style='margin-bottom: 5px;'>管径(MM):" + gj + "</div>";
  2118. lyrsSelect += '</div>';
  2119. lyrsSelect += '<div style="margin-left:30px;margin-top:25px;color: #2ac2fc;">';
  2120. lyrsSelect += "分析半径(M):<input id='radius' type='text' value='2'/>";
  2121. lyrsSelect += '</div>';
  2122. layui.use('layer', function() {
  2123. let layer = layui.layer;
  2124. layer.open({
  2125. id: "panel-layerSelect",
  2126. type: 1,
  2127. area: ["500px", "400px"],
  2128. btn: ['确定','取消'],
  2129. title: "管线净距分析",
  2130. skin: 'layui-ext-coolskin',
  2131. content: lyrsSelect, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响
  2132. cancel: function (index, layero) {
  2133. layer.close(index);
  2134. },
  2135. yes: function(index, layero){
  2136. var radius = $("#radius").val();
  2137. let fxType = $('input[name="fxType"]:checked')[0].value; // 0碰撞;1水平;2垂直
  2138. //按钮【按钮一】的回调
  2139. var dsBufferAnalystService = L.supermap.spatialAnalystService(spatialanalystUrl);
  2140. var dsBufferAnalystParameters = new SuperMap.DatasetBufferAnalystParameters({
  2141. dataset: CONST_VALUES.GX_DataSetName + "@" + CONST_VALUES.GX_DataSourceName,
  2142. filterQueryParameter: new SuperMap.FilterParameter({
  2143. attributeFilter: "SMID=" + gxSmid
  2144. }),
  2145. bufferSetting: new SuperMap.BufferSetting({
  2146. endType: SuperMap.BufferEndType.ROUND,
  2147. leftDistance: {value: radius},
  2148. rightDistance: {value: radius},
  2149. semicircleLineSegment: 10
  2150. })
  2151. });
  2152. dsBufferAnalystService.bufferAnalysis(dsBufferAnalystParameters, function (serviceResult) {
  2153. var ptArrayTemp = serviceResult.result.recordset.features.features[0].geometry.coordinates[0][0];
  2154. var ptArray = Array();
  2155. for(var i = 0; i < ptArrayTemp.length; i++) {
  2156. var tempArr = ptArrayTemp[i];
  2157. var ptTemp = Array();
  2158. ptTemp.push(tempArr[1]);
  2159. ptTemp.push(tempArr[0]);
  2160. ptArray.push(ptTemp);
  2161. }
  2162. var dataSourceName = CONST_VALUES.GX_DataSourceName;
  2163. var dataSetName = CONST_VALUES.GX_DataSetName;
  2164. var boundsParam = new SuperMap.GetFeaturesByBoundsParameters({
  2165. datasetNames: [dataSourceName + ":" + dataSetName],
  2166. fromIndex: 0,
  2167. toIndex: 100000,
  2168. maxFeatures: 100000,
  2169. bounds: L.polygon(ptArray).getBounds()
  2170. });
  2171. // 查询范围内的所有管线
  2172. L.supermap.featureService(dataUrl)
  2173. .getFeaturesByBounds(boundsParam, function (result) {
  2174. if (result.result.features.features.length > 0) {
  2175. // 坐标系转换
  2176. var result = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326);
  2177. L.geoJSON(result, {
  2178. style:{color: "#ef5b9c"},
  2179. onEachFeature: function (feature, layer) {
  2180. let attributes = "";
  2181. let lyrs = CONST_VALUES.GX_Datas;
  2182. for (var index = 0; index < lyrs.length; index++) {
  2183. var lyr = lyrs[index];
  2184. if(dataSourceName == lyr.dataSourceName && dataSetName == lyr.dataSetName){
  2185. var showCols = lyr.cols;
  2186. if(showCols != undefined && showCols != ""){
  2187. var colsArr = showCols.split(",");
  2188. for(var i = 0; i < colsArr.length; i++){
  2189. var colArr = colsArr[i].split(":");
  2190. let attValue = feature.properties[colArr[0]];
  2191. let attr = colArr[1] + ":" + attValue + "<br>";
  2192. attributes += attr;
  2193. }
  2194. }
  2195. break;
  2196. }
  2197. }
  2198. layer.bindPopup(attributes);
  2199. }
  2200. }).addTo(resultLayer);
  2201. pzfxProcess(sourceCoordinates,result,fxType,QSDH,ZDDH,bsm,fldm);
  2202. }
  2203. });
  2204. // 坐标系转换
  2205. var result = L.Util.transform(serviceResult.result.recordset.features, crs, L.CRS.EPSG4326);
  2206. //var result = serviceResult.result;
  2207. L.geoJSON(result, {color: "#00FF00"}).addTo(resultLayer);
  2208. });
  2209. },
  2210. btn2: function(index, layero){
  2211. layer.close(index);
  2212. }
  2213. });
  2214. layui.use(['form'], function() {
  2215. let form = layui.form;
  2216. form.render();
  2217. });
  2218. });
  2219. }
  2220. });
  2221. }
  2222. })
  2223. });
  2224. }
  2225. function pzfxProcess(sourceCoordinates,result,fxType,QSDHSel,ZDDHSel,bsmSel,fldmSel){
  2226. var pts = '';
  2227. for(var i = 0; i < result.features.length; i++)
  2228. {
  2229. var feature = result.features[i];
  2230. var QSDH = feature.properties["QSDH"]; // 起始点号
  2231. var ZDDH = feature.properties["ZDDH"]; // 终点点号
  2232. if(i < result.features.length-1){
  2233. pts += "'" + QSDH + "','" + ZDDH + "',";
  2234. }
  2235. else{
  2236. pts += "'" + QSDH + "','" + ZDDH + "'";
  2237. }
  2238. }
  2239. var sqlTemp = "BSM in (" + pts + ")";
  2240. var sqlParam = new SuperMap.GetFeaturesBySQLParameters({
  2241. queryParameter: {
  2242. name: CONST_VALUES.JD_DataSetName + "@" + CONST_VALUES.JD_DataSourceName,
  2243. attributeFilter: sqlTemp
  2244. },
  2245. datasetNames: [CONST_VALUES.JD_DataSourceName + ":" + CONST_VALUES.JD_DataSetName]
  2246. });
  2247. L.supermap.featureService(dataUrl).getFeaturesBySQL(sqlParam, function (serviceResult) {
  2248. if(serviceResult.result.features.features.length > 0){
  2249. var resultData = L.Util.transform(serviceResult.result.features, crs, L.CRS.EPSG4326);
  2250. var rsList = new Array();
  2251. // 选择的管线
  2252. var line1 = turf.lineString([[sourceCoordinates[0][0], sourceCoordinates[0][1]], [sourceCoordinates[1][0], sourceCoordinates[1][1]]]);
  2253. // 计算每条管线与选择管线的垂直和水平净距 两条线相交只要垂直净距,否则只有水平净距
  2254. for(var i = 0; i < result.features.length; i++){
  2255. var feature = result.features[i];
  2256. var coordinates = feature.geometry.coordinates;
  2257. var QSDHTemp = feature.properties["QSDH"]; // 起始点号
  2258. var ZDDHTemp = feature.properties["ZDDH"]; // 终点点号
  2259. var bsmTemp = feature.properties["BSM"];
  2260. var fldmTemp = feature.properties["FLDM"];
  2261. // 与选择管线连接的管线排除掉
  2262. if(QSDHTemp == QSDHSel || QSDHTemp == ZDDHSel || ZDDHTemp == QSDHSel || ZDDHTemp == ZDDHSel){
  2263. continue;
  2264. }
  2265. // 地图上划线查询到的管线
  2266. var line2 = turf.lineString([[coordinates[0][0], coordinates[0][1]], [coordinates[1][0], coordinates[1][1]]]);
  2267. // 交叉点
  2268. var intersects = turf.lineIntersect(line1, line2);
  2269. // 水平净距分析时如果有交叉点,则没有水平净距
  2270. if(fxType == 1 && intersects.features.length > 0){
  2271. continue;
  2272. }
  2273. // 垂直净距分析时如果没有交叉点,则没有垂直净距
  2274. if(fxType == 2 && intersects.features.length == 0){
  2275. continue;
  2276. }
  2277. var entityData = {};
  2278. entityData.bsm = bsmSel;
  2279. entityData.fldm = fldmSel;
  2280. entityData.bsmTemp = bsmTemp;
  2281. entityData.fldmTemp = fldmTemp;
  2282. entityData.spjjMin = CONST_VALUES.SP_Min;
  2283. entityData.czjjMin = CONST_VALUES.CZ_Min;
  2284. // 有交叉点,则计算垂直净距
  2285. if(fxType != 1 && intersects.features.length > 0) {
  2286. var pt1Data = undefined;
  2287. var pt2Data = undefined;
  2288. var pt1DataSel = undefined;
  2289. var pt2DataSel = undefined;
  2290. for(var j = 0; j < resultData.features.length; j++){
  2291. var bsm = resultData.features[j].properties["BSM"];
  2292. if(bsm == QSDHTemp){
  2293. pt1Data = resultData.features[j];
  2294. }
  2295. else if(bsm == ZDDHTemp){
  2296. pt2Data = resultData.features[j];
  2297. }
  2298. if(bsm == QSDHSel){
  2299. pt1DataSel = resultData.features[j];
  2300. }
  2301. else if(bsm == ZDDHSel){
  2302. pt2DataSel = resultData.features[j];
  2303. }
  2304. if(pt1Data != undefined && pt2Data != undefined && pt1DataSel != undefined && pt2DataSel != undefined){
  2305. break;
  2306. }
  2307. }
  2308. if(pt1Data == undefined || pt2Data == undefined || pt1DataSel == undefined || pt2DataSel == undefined){
  2309. continue;
  2310. }
  2311. var dmgcPT1 = pt1Data.properties["DMGC"] * 1; // 地面高程
  2312. var msPT1 = pt1Data.properties["MS"] * 1; // 埋深
  2313. var xPT1 = pt1Data.geometry.coordinates[0]; // x坐标
  2314. var yPT1 = pt1Data.geometry.coordinates[1]; // y坐标
  2315. var dmgcPT2 = pt2Data.properties["DMGC"] * 1; // 地面高程
  2316. var msPT2 = pt2Data.properties["MS"] * 1; // 埋深
  2317. var xPT2 = pt2Data.geometry.coordinates[0]; // x坐标
  2318. var yPT2 = pt2Data.geometry.coordinates[1]; // y坐标
  2319. var dmgcPT1Sel = pt1DataSel.properties["DMGC"] * 1; // 地面高程
  2320. var msPT1Sel = pt1DataSel.properties["MS"] * 1; // 埋深
  2321. var xPT1Sel = pt1DataSel.geometry.coordinates[0]; // x坐标
  2322. var yPT1Sel = pt1DataSel.geometry.coordinates[1]; // y坐标
  2323. var dmgcPT2Sel = pt2DataSel.properties["DMGC"] * 1; // 地面高程
  2324. var msPT2Sel = pt2DataSel.properties["MS"] * 1; // 埋深
  2325. var xPT2Sel = pt2DataSel.geometry.coordinates[0]; // x坐标
  2326. var yPT2Sel = pt2DataSel.geometry.coordinates[1]; // y坐标
  2327. var xPtTmp = intersects.features[0].geometry.coordinates[0];
  2328. var yPtTmp = intersects.features[0].geometry.coordinates[1];
  2329. var dmgc = undefined; // 地面高程
  2330. var ms = undefined; // 埋深
  2331. var gxgc = undefined; // 管线高程
  2332. if(dmgcPT1 == dmgcPT2){
  2333. dmgc = dmgcPT1;
  2334. }
  2335. else if (dmgcPT1 > dmgcPT2){
  2336. 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)));
  2337. }
  2338. else {
  2339. 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)));
  2340. }
  2341. if(msPT1 == msPT2){
  2342. ms = msPT1;
  2343. }
  2344. else if(msPT1 > msPT2){
  2345. 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)));
  2346. }
  2347. else{
  2348. 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)));
  2349. }
  2350. gxgc = dmgc - ms;
  2351. var dmgcSel = undefined; // 地面高程
  2352. var msSel = undefined; // 埋深
  2353. var gxgcSel = undefined; // 管线高程
  2354. if(dmgcPT1Sel == dmgcPT2Sel){
  2355. dmgcSel = dmgcPT1Sel;
  2356. }
  2357. else if (dmgcPT1Sel > dmgcPT2Sel){
  2358. 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)));
  2359. }
  2360. else {
  2361. 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)));
  2362. }
  2363. if(msPT1Sel == msPT2Sel){
  2364. msSel = msPT1Sel;
  2365. }
  2366. else if(msPT1Sel > msPT2Sel){
  2367. 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)));
  2368. }
  2369. else{
  2370. 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)));
  2371. }
  2372. gxgcSel = dmgcSel - msSel;
  2373. var distance = Math.abs(gxgcSel-gxgc).toFixed(2);
  2374. entityData.spjj = "--";
  2375. entityData.czjj = distance;
  2376. if(distance < CONST_VALUES.CZ_Min){
  2377. rsList.push(entityData);
  2378. }
  2379. }
  2380. // 没有交叉点,则计算水平净距
  2381. if(fxType != 2 && intersects.features.length == 0) {
  2382. var pt1 = turf.point([sourceCoordinates[0][0], sourceCoordinates[0][1]]);
  2383. var pt2 = turf.point([sourceCoordinates[1][0], sourceCoordinates[1][1]]);
  2384. var pt3 = turf.point([coordinates[0][0], coordinates[0][1]]);
  2385. var pt4 = turf.point([coordinates[1][0], coordinates[1][1]]);
  2386. var distance1 = turf.pointToLineDistance(pt1, line2, {units: 'kilometers'});
  2387. var distance2 = turf.pointToLineDistance(pt2, line2, {units: 'kilometers'});
  2388. var distance3 = turf.pointToLineDistance(pt3, line1, {units: 'kilometers'});
  2389. var distance4 = turf.pointToLineDistance(pt4, line1, {units: 'kilometers'});
  2390. var distance = distance1;
  2391. if(distance > distance1){
  2392. distance = distance1;
  2393. }
  2394. if(distance > distance2){
  2395. distance = distance2;
  2396. }
  2397. if(distance > distance3){
  2398. distance = distance3;
  2399. }
  2400. if(distance > distance4){
  2401. distance = distance4;
  2402. }
  2403. distance = distance * 1000;
  2404. entityData.spjj = distance.toFixed(2);
  2405. entityData.czjj = "--";
  2406. if(distance < CONST_VALUES.SP_Min){
  2407. rsList.push(entityData);
  2408. }
  2409. }
  2410. }
  2411. let tableNew = "<table id='THETABLEID' lay-filter='THETABLEID'></table>";
  2412. const tableNewID = utils.guid();
  2413. while (tableNew.indexOf('THETABLEID') > -1)
  2414. tableNew = tableNew.replace('THETABLEID', tableNewID);
  2415. layui.use('layer', function() {
  2416. if (rsList.length == 0) {
  2417. layui.layer.msg('分析结果中没法发现不符合标准的管线。');
  2418. return -1;
  2419. }
  2420. var layer = layui.layer;
  2421. layer.open({
  2422. id: "panel-pzfx",
  2423. type: 1,
  2424. area: ["800px", "550px"],
  2425. title: "碰撞分析结果",
  2426. skin: 'layui-ext-coolskin',
  2427. content: tableNew, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响
  2428. cancel: function (index, layero) {
  2429. layer.close(index);
  2430. }
  2431. });
  2432. });
  2433. let cols = [];
  2434. cols.push({ field: "bsm", title: "选中管线编号", sort: false, width: 120 });
  2435. cols.push({ field: "fldm", title: "选中管线类型", sort: false, width: 120 });
  2436. cols.push({ field: "bsmTemp", title: "分析管线编号", sort: false, width: 120 });
  2437. cols.push({ field: "fldmTemp", title: "分析管线类型", sort: false, width: 120 });
  2438. if(fxType != 2){
  2439. cols.push({ field: "spjj", title: "水平净距", sort: false, width: 120 });
  2440. cols.push({ field: "spjjMin", title: "标准水平净距", sort: false, width: 120 });
  2441. }
  2442. if(fxType != 1){
  2443. cols.push({ field: "czjj", title: "垂直净距", sort: false, width: 120 });
  2444. cols.push({ field: "czjjMin", title: "标准垂直净距", sort: false, width: 120 });
  2445. }
  2446. layui.use('table', function() {
  2447. let table = layui.table;
  2448. table.render({
  2449. elem: '#' + tableNewID,
  2450. data: rsList,
  2451. "lay-size": 'sm',
  2452. cols: [cols]
  2453. });
  2454. });
  2455. }
  2456. })
  2457. }
  2458. function ftfx(){
  2459. drawType = "FTFX";
  2460. setDefualtStyle();
  2461. drawMapControl.handler.disable();
  2462. drawMapControl.handler.libID = 0;
  2463. drawMapControl.handler.code = 32;
  2464. drawMapControl.handler.serverUrl = serverUrl;
  2465. drawMapControl.handler.enable();
  2466. }
  2467. function ftfxProcess(drawLayer){
  2468. var rectangleTemp = L.Util.transform(drawLayer._bounds, L.CRS.EPSG4326, crs);
  2469. var ptArrayTemp = rectangleTemp.geometry.coordinates[0];
  2470. var ptArray = Array();
  2471. for(var i = 0; i < ptArrayTemp.length; i++) {
  2472. var tempArr = ptArrayTemp[i];
  2473. var ptTemp = Array();
  2474. ptTemp.push(tempArr[1]);
  2475. ptTemp.push(tempArr[0]);
  2476. ptArray.push(ptTemp);
  2477. }
  2478. var dataSourceName = CONST_VALUES.GX_DataSourceName;
  2479. var dataSetName = CONST_VALUES.GX_DataSetName;
  2480. var boundsParam = new SuperMap.GetFeaturesByBoundsParameters({
  2481. datasetNames: [dataSourceName + ":" + dataSetName],
  2482. fromIndex: 0,
  2483. toIndex: 100000,
  2484. maxFeatures: 100000,
  2485. bounds: L.polygon(ptArray).getBounds()
  2486. });
  2487. L.supermap
  2488. .featureService(dataUrl)
  2489. .getFeaturesByBounds(boundsParam, function (serviceResult) {
  2490. // 坐标系转换
  2491. var result = L.Util.transform(serviceResult.result.features, crs, L.CRS.EPSG4326);
  2492. L.geoJSON(result, {
  2493. style:{color: "red"},
  2494. onEachFeature: function (feature, layer) {
  2495. let attributes = "";
  2496. let lyrs = CONST_VALUES.GX_Datas;
  2497. for (var index = 0; index < lyrs.length; index++) {
  2498. var lyr = lyrs[index];
  2499. if(dataSourceName == lyr.dataSourceName && dataSetName == lyr.dataSetName){
  2500. var showCols = lyr.cols;
  2501. if(showCols != undefined && showCols != ""){
  2502. var colsArr = showCols.split(",");
  2503. for(var i = 0; i < colsArr.length; i++){
  2504. var colArr = colsArr[i].split(":");
  2505. let attValue = feature.properties[colArr[0]];
  2506. let attr = colArr[1] + ":" + attValue + "<br>";
  2507. attributes += attr;
  2508. }
  2509. }
  2510. break;
  2511. }
  2512. }
  2513. layer.bindPopup(attributes);
  2514. }
  2515. }).addTo(resultLayer);
  2516. let tableNew = "<table id='THETABLEID' lay-filter='THETABLEID'></table>";
  2517. const tableNewID = utils.guid();
  2518. while (tableNew.indexOf('THETABLEID') > -1)
  2519. tableNew = tableNew.replace('THETABLEID', tableNewID);
  2520. layui.use('layer', function() {
  2521. var layer = layui.layer;
  2522. layer.open({
  2523. id: "panel-pzfx",
  2524. type: 1,
  2525. area: ["800px", "550px"],
  2526. title: "覆土分析",
  2527. skin: 'layui-ext-coolskin',
  2528. content: tableNew, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响
  2529. cancel: function (index, layero) {
  2530. layer.close(index);
  2531. }
  2532. });
  2533. });
  2534. let cols = [];
  2535. cols.push({ field: "SMID", title: "实体编码", sort: false, width: 100 });
  2536. cols.push({ field: "fxRs", title: "分析结果", sort: false, width: 120 });
  2537. cols.push({ field: "msMin", title: "标准埋深", sort: false, width: 100 });
  2538. cols.push({ field: "QDMS", title: "起点埋深", sort: false, width: 100 });
  2539. cols.push({ field: "ZDMS", title: "终点埋深", sort: false, width: 100 });
  2540. cols.push({ field: "CZ", title: "材质", sort: false, width: 80 });
  2541. cols.push({ field: "GJ", title: "管径", sort: false, width: 80 });
  2542. cols.push({ field: "BSM", title: "管段编号", sort: false, width: 100 });
  2543. cols.push({ field: "QSDH", title: "起始点号", sort: false, width: 100 });
  2544. cols.push({ field: "ZDDH", title: "终点点号", sort: false, width: 100 });
  2545. cols.push({ field: "MSFS", title: "埋设方式", sort: false, width: 100 });
  2546. let datas = [];
  2547. for (let i in result.features) {
  2548. var entity = result.features[i].properties;
  2549. var czTemp = entity["CZ"];
  2550. var qdmsTemp = entity["QDMS"];
  2551. var zdmsTemp = entity["ZDMS"];
  2552. var msMin = FTFX_Mins.get(czTemp);
  2553. entity["msMin"] = msMin;
  2554. if(msMin <= qdmsTemp && msMin <= zdmsTemp){
  2555. entity["fxRs"] = "符合标准";
  2556. }
  2557. else{
  2558. entity["fxRs"] = "不符合标准";
  2559. }
  2560. datas.push(entity);
  2561. }
  2562. layui.use('table', function() {
  2563. let table = layui.table;
  2564. table.render({
  2565. elem: '#' + tableNewID,
  2566. data: datas,
  2567. "lay-size": 'sm',
  2568. cols: [cols]
  2569. });
  2570. });
  2571. });
  2572. }
  2573. // 连通分析
  2574. function ltfx(){
  2575. map.off('click');
  2576. var isFirstPoint = true; //判断是否是起始点
  2577. var latLngTemp = null;//存储上一点击点临时变量
  2578. map.on('click', function(ev) {
  2579. TempLayer.clearLayers();
  2580. $("#tips").css('display', 'none');
  2581. var pt = crs.project(ev.latlng);
  2582. var _Point = L.marker([pt.y, pt.x]);
  2583. var dataSourceName = CONST_VALUES.GX_DataSourceName;
  2584. var dataSetName = CONST_VALUES.GX_DataSetName;
  2585. var bufferParam = new SuperMap.GetFeaturesByBufferParameters({
  2586. datasetNames: [dataSourceName + ":" + dataSetName],
  2587. bufferDistance: CONST_VALUES.QUERY_BufferDistance,
  2588. geometry: _Point
  2589. });
  2590. // 判断点击的点是否在管线上
  2591. L.supermap
  2592. .featureService(dataUrl)
  2593. .getFeaturesByBuffer(bufferParam, function (result) {
  2594. if(result.result.features.features.length > 0){
  2595. var texticon = L.divIcon({ //定义图标
  2596. className: "leaflet-div-icon-new"
  2597. });
  2598. L.marker([ev.latlng.lat, ev.latlng.lng], {
  2599. icon: texticon
  2600. }).addTo(resultLayer); //marker实现文本框显示
  2601. if(isFirstPoint) {
  2602. latLngTemp = ev.latlng; //存储上一点击点
  2603. isFirstPoint = false;
  2604. } else {
  2605. if(!latLngTemp.equals(ev.latlng)) { //避免出现结束双击,导致距离为0
  2606. map.off('click');
  2607. var findPathService = L.supermap.networkAnalystService(transportationAnalystUrl);
  2608. //创建最佳路径分析参数实例
  2609. var resultSetting = new SuperMap.TransportationAnalystResultSetting({
  2610. returnEdgeFeatures: true,
  2611. returnEdgeGeometry: true,
  2612. returnEdgeIDs: true,
  2613. returnNodeFeatures: true,
  2614. returnNodeGeometry: true,
  2615. returnNodeIDs: true,
  2616. returnPathGuides: true,
  2617. returnRoutes: true
  2618. });
  2619. var analystParameter = new SuperMap.TransportationAnalystParameter({
  2620. resultSetting: resultSetting,
  2621. //weightFieldName: "length"
  2622. });
  2623. var pt1 = L.point(pt.x, pt.y);
  2624. var ptTemp = crs.project(latLngTemp);
  2625. var pt2 = L.point(ptTemp.x, ptTemp.y);
  2626. var findPathParameter = new SuperMap.FindPathParameters({
  2627. isAnalyzeById: false,
  2628. nodes: [pt1, pt2],
  2629. parameter: analystParameter
  2630. });
  2631. //进行查找
  2632. findPathService.findPath(findPathParameter, function (serviceResult) {
  2633. if(serviceResult.type != "processFailed" && serviceResult.result.pathList[0].edgeFeatures.features.length > 0){
  2634. var result = L.Util.transform(serviceResult.result.pathList[0].edgeFeatures, crs, L.CRS.EPSG4326);
  2635. L.geoJSON(result, {
  2636. style:{color: "red"},
  2637. onEachFeature: function (feature, layer) {
  2638. let attributes = "";
  2639. let lyrs = CONST_VALUES.GX_Datas;
  2640. for (var index = 0; index < lyrs.length; index++) {
  2641. var lyr = lyrs[index];
  2642. if(dataSourceName == lyr.dataSourceName && dataSetName == lyr.dataSetName){
  2643. var showCols = lyr.cols;
  2644. if(showCols != undefined && showCols != ""){
  2645. var colsArr = showCols.split(",");
  2646. for(var i = 0; i < colsArr.length; i++){
  2647. var colArr = colsArr[i].split(":");
  2648. let attValue = feature.properties[colArr[0]];
  2649. let attr = colArr[1] + ":" + attValue + "<br>";
  2650. attributes += attr;
  2651. }
  2652. }
  2653. break;
  2654. }
  2655. }
  2656. layer.bindPopup(attributes);
  2657. }
  2658. }).addTo(resultLayer);
  2659. let tableNew = "<table id='THETABLEID' lay-filter='THETABLEID'></table>";
  2660. const tableNewID = utils.guid();
  2661. while (tableNew.indexOf('THETABLEID') > -1)
  2662. tableNew = tableNew.replace('THETABLEID', tableNewID);
  2663. layui.use('layer', function() {
  2664. var layer = layui.layer;
  2665. layer.open({
  2666. id: "panel-ltfx",
  2667. type: 1,
  2668. area: ["800px", "550px"],
  2669. title: "连通分析",
  2670. skin: 'layui-ext-coolskin',
  2671. content: tableNew, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响
  2672. cancel: function (index, layero) {
  2673. layer.close(index);
  2674. }
  2675. });
  2676. });
  2677. let cols = [];
  2678. let lyrs = CONST_VALUES.GX_Datas;
  2679. for (var index = 0; index < lyrs.length; index++) {
  2680. var lyr = lyrs[index];
  2681. if(dataSourceName == lyr.dataSourceName && dataSetName == lyr.dataSetName){
  2682. var showCols = lyr.cols;
  2683. if(showCols != undefined && showCols != ""){
  2684. var colsArr = showCols.split(",");
  2685. for(var i = 0; i < colsArr.length; i++){
  2686. var colArr = colsArr[i].split(":");
  2687. cols.push({ field: colArr[0], title: colArr[1], sort: true, width: 100 });
  2688. }
  2689. }
  2690. break;
  2691. }
  2692. }
  2693. let datas = [];
  2694. for (let i in result.features) {
  2695. datas.push(result.features[i].properties);
  2696. }
  2697. layui.use('table', function() {
  2698. let table = layui.table;
  2699. table.render({
  2700. elem: '#' + tableNewID,
  2701. data: datas,
  2702. "lay-size": 'sm',
  2703. cols: [cols]
  2704. });
  2705. });
  2706. }
  2707. else {
  2708. layui.layer.msg('所选位置不连通!');
  2709. return -1;
  2710. }
  2711. });
  2712. }
  2713. }
  2714. }
  2715. });
  2716. });
  2717. }
  2718. /**
  2719. * 编辑管网
  2720. */
  2721. function layerEdit() {
  2722. map.off('click');
  2723. map.off('contextmenu');
  2724. let lyrsSelect = '<div id="editTypes" class="layui-form" lay-filter="editTypesDiv"><div class="layui-form-item"><label class="layui-form-label">编辑类型</label><div class="layui-input-block" style="margin-left:30px">';
  2725. lyrsSelect += "<input type='radio' name='editType' title='新增' value='0' id='editType_0' lay-skin='primary'>";
  2726. lyrsSelect += "<input type='radio' name='editType' title='修改' value='1' id='editType_1' lay-skin='primary'>";
  2727. lyrsSelect += "<input type='radio' name='editType' title='删除' value='2' id='editType_2' lay-skin='primary'>";
  2728. lyrsSelect += '</div></div></div>';
  2729. let lyrs = CONST_VALUES.GX_Datas;
  2730. lyrsSelect += '<div id="layers" class="layui-form" lay-filter="lyrsSelectDiv"><div class="layui-form-item"><label class="layui-form-label">编辑图层</label><div class="layui-input-block" style="margin-left:30px">';
  2731. let listStr = "<input type='radio' name='editLayer' title='THETITLE' id='THEID' lay-skin='primary' dataSetName='THEDATASETNAME' dataSourceName='THEWS' dataType='THETYPE' >";
  2732. for (let index = 0; index < lyrs.length; index++) {
  2733. const lyr = lyrs[index];
  2734. let dom = listStr.replace('THETITLE', lyr.name);
  2735. dom = dom.replace('THEID', lyr.id);
  2736. dom = dom.replace('THEWS', lyr.dataSourceName);
  2737. dom = dom.replace('THEDATASETNAME', lyr.dataSetName);
  2738. dom = dom.replace('THETYPE', lyr.dataType);
  2739. lyrsSelect += dom;
  2740. }
  2741. lyrsSelect += '</div></div></div>';
  2742. layui.use('layer', function() {
  2743. let layer = layui.layer;
  2744. layer.open({
  2745. id: "panel-editTypes",
  2746. type: 1,
  2747. area: ["500px", "300px"],
  2748. btn: ['确定'],
  2749. title: "请选择编辑类型",
  2750. skin: 'layui-ext-coolskin',
  2751. content: lyrsSelect, //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响
  2752. cancel: function(index, layero) {
  2753. layer.close(index);
  2754. },
  2755. yes: function(e) {
  2756. let editType = $('input[name="editType"]:checked').val();
  2757. if (editType == undefined) {
  2758. layer.msg('请选择编辑类型!', {
  2759. icon: 7
  2760. });
  2761. return;
  2762. }
  2763. let editLayer = $('input[name="editLayer"]:checked').val();
  2764. if (editLayer == undefined) {
  2765. layer.msg('请选择编辑图层!', {
  2766. icon: 7
  2767. });
  2768. return;
  2769. }
  2770. layer.close(e);
  2771. var editTypeVal = $('input[name="editType"]:checked')[0].attributes.value.value;
  2772. var dataSourceName = $('input[name="editLayer"]:checked')[0].attributes.dataSourceName.value;
  2773. var dataSetName = $('input[name="editLayer"]:checked')[0].attributes.dataSetName.value;
  2774. var dataType = $('input[name="editLayer"]:checked')[0].attributes.dataType.value;
  2775. var editTypeMap
  2776. if(editTypeVal==0){
  2777. editTypeMap = SuperMap.EditType.ADD;
  2778. }
  2779. else if(editTypeVal == 1){
  2780. editTypeMap = SuperMap.EditType.UPDATE;
  2781. }
  2782. else if(editTypeVal == 2){
  2783. editTypeMap = SuperMap.EditType.DELETE;
  2784. }
  2785. map.on('contextmenu', function(evt){
  2786. map.off('click');
  2787. map.off('contextmenu');
  2788. });
  2789. // 新增
  2790. if(editTypeVal == 0){
  2791. // 添加管线
  2792. if(dataType == "line"){
  2793. var startPt;// 开始点击坐标
  2794. var endPt; // 结束点击坐标
  2795. var startGd;// 查询到开始管点
  2796. var endGd;// 查询到结束管点
  2797. var isFirst = true;
  2798. map.on('click', function (evt) {
  2799. var pt = crs.project(evt.latlng);
  2800. var _Point = L.marker([pt.y, pt.x]);
  2801. Q.queryByGeometry("",undefined,CONST_VALUES.JD_DataSetName, CONST_VALUES.JD_DataSourceName, _Point, function(result) {
  2802. if (result.result == undefined || result.result.features.features.length == 0) {
  2803. layui.layer.msg('附件没有发现管点信息,请重新选择!');
  2804. return;
  2805. }
  2806. var rs = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326);
  2807. if(isFirst){
  2808. isFirst = false;
  2809. startPt = evt.latlng;
  2810. startGd = rs.features[0];
  2811. }
  2812. else{
  2813. endPt = evt.latlng;
  2814. endGd = rs.features[0];
  2815. if(!startPt.equals(endPt)){
  2816. var newLine = L.polyline([ //与上一点连线
  2817. [startGd.geometry.coordinates[1], startGd.geometry.coordinates[0]],
  2818. [endGd.geometry.coordinates[1], endGd.geometry.coordinates[0]]
  2819. ], {
  2820. color: "#070af3"
  2821. });
  2822. newLine.addTo(map);
  2823. var from = turf.point([startGd.geometry.coordinates[0], startGd.geometry.coordinates[1]]);
  2824. var to = turf.point([endGd.geometry.coordinates[0], endGd.geometry.coordinates[1]]);
  2825. var options = {units: 'kilometers'};
  2826. var distance = (turf.distance(from, to, options) * 1000).toFixed(2);
  2827. var aa = newLine.toGeoJSON();
  2828. var bb = L.Util.transform(aa, L.CRS.EPSG4326, crs);
  2829. $.ajax({
  2830. url: '/static/maps/bs/create-line.html',
  2831. success: function(htmlContext) {
  2832. layui.use('layer', function(){
  2833. var layer = layui.layer,laydate = layui.laydate,form = layui.form;
  2834. layer.open({
  2835. type: 1 //此处以iframe举例
  2836. ,area: ["400px", "550px"]
  2837. ,title: "添加管线信息"
  2838. ,skin: 'layui-ext-coolskin'
  2839. //,shade: 0.8
  2840. ,maxmin: true
  2841. ,content: htmlContext
  2842. ,zIndex: layer.zIndex
  2843. ,cancel: function (index, layero) {
  2844. layer.close(index);
  2845. map.removeLayer(newLine);
  2846. }
  2847. ,success: function(layero, index){
  2848. $("#QSDH").val(startGd.properties["BSM"]);
  2849. $("#ZDDH").val(endGd.properties["BSM"]);
  2850. $("#QDMS").val(startGd.properties["MS"]);
  2851. $("#ZDMS").val(endGd.properties["MS"]);
  2852. $("#CD").val(distance);
  2853. var nowTime = new Date().Format("yyyyMMddhhmmssS");
  2854. $("#BSM").val(nowTime);
  2855. //日期
  2856. laydate.render({
  2857. elem: '#LRRQ',
  2858. });
  2859. laydate.render({
  2860. elem: '#MSRQ',
  2861. });
  2862. }
  2863. ,btn: ['保存', '关闭']
  2864. ,yes: function(){
  2865. var data = form.val('createLine');
  2866. bb.properties = data;
  2867. var featuresParameters = new SuperMap.EditFeaturesParameters({
  2868. dataSourceName: dataSourceName,
  2869. dataSetName: dataSetName,
  2870. features: [bb],
  2871. editType: editTypeMap,
  2872. returnContent: true
  2873. });
  2874. L.supermap.featureService(dataUrl)
  2875. .editFeatures(featuresParameters,function(result){
  2876. console.log(result);
  2877. });
  2878. layer.closeAll();
  2879. }
  2880. ,btn2: function(){
  2881. layer.closeAll();
  2882. map.removeLayer(newLine);
  2883. }
  2884. });
  2885. })
  2886. },
  2887. error: function() {
  2888. layui.layer.msg('功能未实现!', {
  2889. icon: 7
  2890. });
  2891. }
  2892. });
  2893. isFirst = true;
  2894. }
  2895. }
  2896. });
  2897. });
  2898. }
  2899. else{
  2900. map.on('click', function (evt) {
  2901. var pt = crs.project(evt.latlng);
  2902. var aaaaa = L.circleMarker(evt.latlng, {color: '#953716', radius: 3, fill: true, fillColor: 'green'}).addTo(map);
  2903. var _Point = L.marker([pt.y, pt.x]);
  2904. var aa = _Point.toGeoJSON();
  2905. $.ajax({
  2906. url: '/static/maps/bs/create-point.html',
  2907. success: function(htmlContext) {
  2908. layui.use('layer', function(){
  2909. var layer = layui.layer,laydate = layui.laydate,form = layui.form;
  2910. layer.open({
  2911. type: 1 //此处以iframe举例
  2912. ,area: ["390px", "550px"]
  2913. ,title: "添加管点信息"
  2914. ,skin: 'layui-ext-coolskin'
  2915. //,shade: 0.8
  2916. ,maxmin: true
  2917. ,content: htmlContext
  2918. ,zIndex: layer.zIndex
  2919. ,cancel: function (index, layero) {
  2920. layer.close(index);
  2921. map.removeLayer(aaaaa);
  2922. }
  2923. ,success: function(layero, index){
  2924. $("#X").val(aa.geometry.coordinates[0]);
  2925. $("#Y").val(aa.geometry.coordinates[1]);
  2926. var nowTime = new Date().Format("yyyyMMddhhmmssS");
  2927. $("#BSM").val(nowTime);
  2928. $("#WTH").val(nowTime);
  2929. //日期
  2930. laydate.render({
  2931. elem: '#LRRQ',
  2932. });
  2933. laydate.render({
  2934. elem: '#MSRQ',
  2935. });
  2936. }
  2937. ,btn: ['保存', '关闭']
  2938. ,yes: function(){
  2939. var data = form.val('createPoint');
  2940. aa.properties = data;
  2941. var featuresParameters = new SuperMap.EditFeaturesParameters({
  2942. dataSourceName: dataSourceName,
  2943. dataSetName: dataSetName,
  2944. features: [aa],
  2945. editType: editTypeMap,
  2946. returnContent: true
  2947. });
  2948. L.supermap.featureService(dataUrl)
  2949. .editFeatures(featuresParameters,function(result){
  2950. console.log(result);
  2951. });
  2952. layer.closeAll();
  2953. }
  2954. ,btn2: function(){
  2955. layer.closeAll();
  2956. map.removeLayer(aaaaa);
  2957. }
  2958. });
  2959. })
  2960. },
  2961. error: function() {
  2962. layui.layer.msg('功能未实现!', {
  2963. icon: 7
  2964. });
  2965. }
  2966. });
  2967. });
  2968. }
  2969. }
  2970. // 修改操作
  2971. else if(editTypeVal == 1){
  2972. map.on('click', function (evt) {
  2973. var pt = crs.project(evt.latlng);
  2974. var _Point = L.marker([pt.y, pt.x]);
  2975. Q.queryByGeometry("",undefined,dataSetName, dataSourceName, _Point, function(result) {
  2976. if (result.result == undefined || result.result.features.features.length < 1) return;
  2977. // 坐标系转换
  2978. //var result = L.Util.transform(result.result.features, crs, L.CRS.EPSG4326);
  2979. var editFeature = result.result.features.features[0];
  2980. var rsVal = editFeature.properties;
  2981. if(dataType == "line"){
  2982. $.ajax({
  2983. url: '/static/maps/bs/create-line.html',
  2984. success: function(htmlContext) {
  2985. layui.use('layer', function(){
  2986. var layer = layui.layer,laydate = layui.laydate,form = layui.form;
  2987. layer.open({
  2988. type: 1 //此处以iframe举例
  2989. ,area: ["400px", "550px"]
  2990. ,title: "编辑管线信息"
  2991. ,skin: 'layui-ext-coolskin'
  2992. //,shade: 0.8
  2993. ,maxmin: true
  2994. ,content: htmlContext
  2995. ,zIndex: layer.zIndex
  2996. ,cancel: function (index, layero) {
  2997. layer.close(index);
  2998. }
  2999. ,success: function(layero, index){
  3000. form.val('createLine', rsVal);
  3001. //日期
  3002. laydate.render({
  3003. elem: '#LRRQ',
  3004. });
  3005. laydate.render({
  3006. elem: '#MSRQ',
  3007. });
  3008. }
  3009. ,btn: ['保存', '关闭']
  3010. ,yes: function(){
  3011. var data = form.val('createLine');
  3012. editFeature.properties = data;
  3013. var featuresParameters = new SuperMap.EditFeaturesParameters({
  3014. dataSourceName: dataSourceName,
  3015. dataSetName: dataSetName,
  3016. features: [editFeature],
  3017. editType: editTypeMap,
  3018. returnContent: true
  3019. });
  3020. L.supermap.featureService(dataUrl)
  3021. .editFeatures(featuresParameters,function(result){
  3022. console.log(result);
  3023. });
  3024. layer.closeAll();
  3025. }
  3026. ,btn2: function(){
  3027. layer.closeAll();
  3028. }
  3029. });
  3030. })
  3031. },
  3032. error: function() {
  3033. layui.layer.msg('功能未实现!', {
  3034. icon: 7
  3035. });
  3036. }
  3037. });
  3038. }
  3039. else{
  3040. $.ajax({
  3041. url: '/static/maps/bs/create-point.html',
  3042. success: function(htmlContext) {
  3043. layui.use('layer', function(){
  3044. var layer = layui.layer,laydate = layui.laydate,form = layui.form;
  3045. layer.open({
  3046. type: 1 //此处以iframe举例
  3047. ,area: ["390px", "550px"]
  3048. ,title: "编辑管点信息"
  3049. ,skin: 'layui-ext-coolskin'
  3050. //,shade: 0.8
  3051. ,maxmin: true
  3052. ,content: htmlContext
  3053. ,zIndex: layer.zIndex
  3054. ,cancel: function (index, layero) {
  3055. layer.close(index);
  3056. }
  3057. ,success: function(layero, index){
  3058. form.val('createPoint', rsVal);
  3059. //日期
  3060. laydate.render({
  3061. elem: '#LRRQ',
  3062. });
  3063. laydate.render({
  3064. elem: '#MSRQ',
  3065. });
  3066. }
  3067. ,btn: ['保存', '关闭']
  3068. ,yes: function(){
  3069. var data = form.val('createPoint');
  3070. editFeature.properties = data;
  3071. var featuresParameters = new SuperMap.EditFeaturesParameters({
  3072. dataSourceName: dataSourceName,
  3073. dataSetName: dataSetName,
  3074. features: [editFeature],
  3075. editType: editTypeMap,
  3076. returnContent: true
  3077. });
  3078. L.supermap.featureService(dataUrl)
  3079. .editFeatures(featuresParameters,function(result){
  3080. console.log(result);
  3081. });
  3082. layer.closeAll();
  3083. }
  3084. ,btn2: function(){
  3085. layer.closeAll();
  3086. }
  3087. });
  3088. })
  3089. },
  3090. error: function() {
  3091. layui.layer.msg('功能未实现!', {
  3092. icon: 7
  3093. });
  3094. }
  3095. });
  3096. }
  3097. L.geoJSON(result, {
  3098. style:{color: "#ef5b9c"},
  3099. onEachFeature: function (feature, layer) {
  3100. let attributes = "";
  3101. let lyrs = CONST_VALUES.GX_Datas;
  3102. for (var index = 0; index < lyrs.length; index++) {
  3103. var lyr = lyrs[index];
  3104. if(ws == lyr.dataSourceName && dataSetName == lyr.dataSetName){
  3105. var showCols = lyr.cols;
  3106. if(showCols != undefined && showCols != ""){
  3107. var colsArr = showCols.split(",");
  3108. for(var i = 0; i < colsArr.length; i++){
  3109. var colArr = colsArr[i].split(":");
  3110. let attValue = feature.properties[colArr[0]];
  3111. let attr = colArr[1] + ":" + attValue + "<br>";
  3112. attributes += attr;
  3113. }
  3114. }
  3115. break;
  3116. }
  3117. }
  3118. layer.bindPopup(attributes);
  3119. }
  3120. }).addTo(resultLayer);
  3121. });
  3122. });
  3123. }
  3124. // 删除操作
  3125. else if(editTypeVal == 2){
  3126. drawType = "deletefeature";
  3127. // 创建绘制控件,并启用
  3128. var handler = new L.Draw.Polygon(map);
  3129. handler.enable();
  3130. map.on(L.Draw.Event.CREATED,function (e) {
  3131. if(drawType != "deletefeature"){
  3132. return;
  3133. }
  3134. var type = e.layerType,
  3135. layer = e.layer;
  3136. if (type === 'marker') {
  3137. layer.bindPopup('A popup!');
  3138. }
  3139. //将图形信息传给下一步,进行查询功能
  3140. var locationArray = e.layer.getLatLngs()[0];
  3141. var polygonArray = Array();
  3142. var midArray = Array();
  3143. var polygonArrayTmp = Array();
  3144. var midArrayTmp = Array();
  3145. var firstX = locationArray[0].lat;
  3146. var firstY = locationArray[0].lng;
  3147. for(var i =0;i<locationArray.length;i++){
  3148. var pt2 = crs.project(locationArray[i]);
  3149. var x = locationArray[i].lat;
  3150. var y = locationArray[i].lng;
  3151. midArray.push(x);
  3152. midArray.push(y);
  3153. polygonArray.push(midArray);
  3154. midArray = Array();
  3155. midArrayTmp.push(pt2.y);
  3156. midArrayTmp.push(pt2.x);
  3157. polygonArrayTmp.push(midArrayTmp);
  3158. midArrayTmp = Array();
  3159. }
  3160. midArray.push(firstX);
  3161. midArray.push(firstY);
  3162. polygonArray.push(midArray);
  3163. var pt2 = crs.project(locationArray[0]);
  3164. midArrayTmp.push(pt2.y);
  3165. midArrayTmp.push(pt2.x);
  3166. polygonArrayTmp.push(midArrayTmp);
  3167. var polygonTmp = L.polygon(polygonArrayTmp);
  3168. var polygon = L.polygon(polygonArray, {color: "#00FF00"});
  3169. resultLayer.addLayer(polygon);
  3170. Q.queryByBounds("",dataSetName, dataSourceName, polygonTmp, function(result,titleTmp) {
  3171. if (result.result == undefined) return;
  3172. var rs = result.result.features.features;
  3173. var ids = new Array();
  3174. for(var i = 0; i < rs.length; i++){
  3175. ids.push(rs[i].properties["SMID"]);
  3176. }
  3177. if(ids.length > 0){
  3178. layui.use('layer', function(){
  3179. let lyrsTmp = '<div style="font-size: 14px; color: white;"><br/>您确定要删除选择的管网元素信息吗!</div>';
  3180. var layer = layui.layer;
  3181. layer.open({
  3182. type: 1 //此处以iframe举例
  3183. ,area: ["350px", "250px"]
  3184. ,title: "提示"
  3185. ,skin: 'layui-ext-coolskin'
  3186. ,content: lyrsTmp
  3187. ,zIndex: layer.zIndex
  3188. ,cancel: function (index, layero) {
  3189. layer.close(index);
  3190. }
  3191. ,btn: ['确定', '取消']
  3192. ,yes: function(){
  3193. var featuresParameters = new SuperMap.EditFeaturesParameters({
  3194. dataSourceName: dataSourceName,
  3195. dataSetName: dataSetName,
  3196. editType: editTypeMap,
  3197. returnContent: true,
  3198. IDs: ids
  3199. });
  3200. L.supermap.featureService(dataUrl)
  3201. .editFeatures(featuresParameters,function(result){
  3202. clearLays();
  3203. });
  3204. layer.closeAll();
  3205. }
  3206. ,btn2: function(){
  3207. layer.closeAll();
  3208. clearLays();
  3209. }
  3210. });
  3211. })
  3212. }
  3213. else {
  3214. layui.layer.msg('选择的区域没有数据信息!', {
  3215. icon: 7
  3216. });
  3217. }
  3218. });
  3219. });
  3220. }
  3221. }
  3222. });
  3223. layui.use(['form'], function() {
  3224. let form = layui.form;
  3225. form.render();
  3226. });
  3227. });
  3228. }
  3229. Date.prototype.Format = function (fmt) { // author: meizz
  3230. var o = {
  3231. "M+": this.getMonth() + 1, // 月份
  3232. "d+": this.getDate(), // 日
  3233. "h+": this.getHours(), // 小时
  3234. "m+": this.getMinutes(), // 分
  3235. "s+": this.getSeconds(), // 秒
  3236. "q+": Math.floor((this.getMonth() + 3) / 3), // 季度
  3237. "S": this.getMilliseconds() // 毫秒
  3238. };
  3239. if (/(y+)/.test(fmt))
  3240. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  3241. for (var k in o)
  3242. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  3243. return fmt;
  3244. }