gis.map.js 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649
  1. var layer,layeryx,locationLayer,gkvectorLayer,gqvectorLayer,zyqvectorLayer,mdvectorLayer,markersLayer,jyrvectorLayer,boatLayer,modifyvectorLayer;
  2. var modifyFeature,nowModifyFeature;
  3. var uflldLayerMap;
  4. var gis = gis || {};
  5. gis.script = function() {
  6. };
  7. //gis.script.url="http://localhost:8090/iserver/services/map-world/rest/maps/World";
  8. gis.script.phase={init:"init",refresh:"refresh",cbrefresh:"cbrefresh"};
  9. gis.script.layerloadover=false;
  10. gis.script.controlLayer=false;
  11. gis.script.subLayers = new Array();
  12. //gis.script.iserverUrl=iserverUrl||"http://"+serverName+":8090/iserver/services";
  13. //gis.script.url=gis.script.iserverUrl+"/map-gk/rest/maps/gist";
  14. //gis.script.yxurl=gis.script.iserverUrl+"/map-gk/rest/maps/gist";
  15. gis.script.url=gisConfigBean.config.sldt.url;
  16. gis.script.yxurl=gisConfigBean.config.yxdt.url;
  17. gis.script.markerAttr={};
  18. gis.script.yxslqh=false;
  19. gis.script.markersLayers={};
  20. gis.script.markersLayersInfo={};
  21. gis.script.selectallLayers={};
  22. gis.script.tckztreeloadover=false;
  23. gis.script.layersInitconfig=[];
  24. gis.script.layersInitconfigObject={};
  25. /*
  26. * 读取配置信息,动态加载图层
  27. */
  28. gis.script.initlayersconfig = function() {
  29. //{"gkvectorLayer":{"id":"gkvectorLayer","Model":{"ty":{"id":"ty","isshow":"true"},"cbdt":{"id":"cbdt","isshow":"false"}},"label":"港口图层"}}
  30. gis.script.layersInitconfig=[];
  31. gis.script.layersInitconfigObject={};
  32. if(gis.script.isBlank(treeType)){
  33. treeType="ty";
  34. }
  35. if(layerConfig){
  36. for(var n in layerConfig){
  37. var data=layerConfig[n];
  38. if(data&&data.Model&&data.Model[treeType]){
  39. var modeldata=jQuery.extend(true, {}, data.Model[treeType]);
  40. modeldata.layerName=n;
  41. gis.script.layersInitconfig.push(modeldata);
  42. gis.script.setlayersInitconfigObject(data.name||data.id,modeldata);
  43. }
  44. }
  45. }
  46. //根据orderby排序,以便按层次加载图层
  47. gis.script.layersInitconfig.sort(function(a,b){
  48. if(gis.script.isNum(a.orderby)&&gis.script.isNum(b.orderby)){
  49. //console.log("CCC1:",parseFloat(a.orderby));
  50. return parseFloat(a.orderby)<parseFloat(b.orderby)?-1:1;
  51. }
  52. return 0;
  53. });
  54. //console.log("CCC1:",gis.script.layersInitconfig);
  55. //console.log("CCC2:",gis.script.layersInitconfigObject);
  56. }
  57. /*
  58. * 配置信息存入layersInitconfigObject,方便读取图层配置信息
  59. */
  60. gis.script.setlayersInitconfigObject = function(key,obj) {
  61. //alert(key);
  62. var info=gis.script.layersInitconfigObject[key];
  63. if(!info){
  64. gis.script.layersInitconfigObject[key]=[];
  65. info=gis.script.layersInitconfigObject[key];
  66. }
  67. info.push(obj);
  68. }
  69. /*
  70. * 控制图层信息,可以通过设置动态显示图层。
  71. */
  72. gis.script.settrendsLayer=function (key,isshow){
  73. var info=gis.script.layersInitconfigObject[key];
  74. if(info&&info.length){
  75. for(var kk=0;kk<info.length;kk++){
  76. var obj=info[kk];
  77. if(obj){
  78. obj.isshow=isshow;
  79. }
  80. }
  81. }
  82. //console.log("CCC1-1:",gis.script.layersInitconfig);
  83. }
  84. /*
  85. * 地图可显示的比例尺
  86. */
  87. gis.script.scales=[2060000,1180000,640000, 320000, 160000, 80000, 40000, 20000, 10000, 5000, 2500,1250];
  88. /*
  89. gis.script.scales=[0.0000008234577570,0.000001180591620,0.0000020811127177082523,0.0000041622254354165045,0.000008324450870833009,0.000016648901741666018,
  90. 0.000033297803483332036,0.00006659560696666407,0.00013319121393332814,0.0002663824278666563,0.0005327648557333126,
  91. 0.0010655297114666252,0.0021310594229332503,0.004262118845866501,0.008524237691733001,0.017048475383466002];
  92. */
  93. /*
  94. * 初始化,加载SuperMap以及地图影像,根据分辨率动态设置按钮位置
  95. */
  96. gis.script.init = function() {
  97. var bgrounddiv=$("#bgrounddiv");
  98. bgrounddiv.css("width",bgrounddiv.width()-235);
  99. //alert(bgrounddiv.offset().left);
  100. $("#yxslqh").css("top",bgrounddiv.offset().top+10);
  101. //$("#yxslqh").css("left",bgrounddiv.offset().left+23);
  102. $("#yxslqh").css("right",25);
  103. $("#yxslqh img").attr("src",contextPath+'/theme/images/gis/satellite.png');
  104. $("#yxslqh img").bind("click",function(e){
  105. if(gis.script.layerloadover&&layer&&layeryx){
  106. if(gis.script.yxslqh){
  107. layer.setVisibility(true);
  108. layeryx.setVisibility(false);
  109. map.setBaseLayer(layer);
  110. $(this).attr("src",contextPath+'/theme/images/gis/satellite.png');
  111. }else{
  112. layer.setVisibility(false);
  113. layeryx.setVisibility(true);
  114. map.setBaseLayer(layeryx);
  115. $(this).attr("src",contextPath+'/theme/images/gis/map.png');
  116. }
  117. gis.script.yxslqh=!gis.script.yxslqh;
  118. }
  119. //gis.script[this.id](this);
  120. });
  121. annarray=['tckz','cbss','txbj'];
  122. for(var ii=0;ii<annarray.length;ii++){
  123. var annobj=$("#"+annarray[ii]);
  124. if(annobj&&annobj.length){
  125. annobj.css("top",bgrounddiv.offset().top+10);
  126. annobj.css("right",32+52*(ii+1));
  127. annobj.bind("mousedown",function(){
  128. $(this).css("border","1px solid transparent");
  129. });
  130. annobj.bind("mouseup",function(){
  131. $(this).css("border","0px solid transparent");
  132. });
  133. annobj.bind("mouseout",function(){
  134. $(this).css("border","0px solid #A5AAB4");
  135. });
  136. /*
  137. annobj.bind("click",function(e){
  138. $("#"+this.id+"list").show("slow");
  139. });
  140. */
  141. annobj.bind("click",function(e){
  142. /*
  143. var lobj=$("#"+this.id+"list");
  144. if(lobj.is(':hidden')){
  145. for(var ik=0;ik<annarray.length;ik++){
  146. $("#"+annarray[ik]+"list").hide("slow");
  147. }
  148. lobj.show("slow");
  149. }else{
  150. lobj.hide("slow");
  151. }
  152. //lobj.show("slow");
  153. */
  154. gis.script.buttonclickFun(this.id);
  155. });
  156. }
  157. }
  158. $("#tckz_close").bind("click",function(e){
  159. $("#tckzlist").hide("slow");
  160. gis.script.buttonimgObjRestore('tckz');
  161. });
  162. /*
  163. $("#tckz").css("top",bgrounddiv.offset().top+10);
  164. //$("#yxslqh").css("left",bgrounddiv.offset().left+23);
  165. $("#tckz").css("right",85);
  166. $("#tckz img").bind("click",function(e){
  167. $("#tckzlist").show("slow");
  168. });
  169. $("#tckz_close").bind("click",function(e){
  170. $("#tckzlist").hide("slow");
  171. });
  172. $("#tckz").bind("mousedown",function(){
  173. $("#tckz").css("border","1px solid transparent");
  174. });
  175. $("#tckz").bind("mouseup",function(){
  176. $("#tckz").css("border","0px solid transparent");
  177. });
  178. $("#tckz").bind("mouseover",function(){
  179. //border:0px solid #A5AAB4;
  180. //$("#tckz").css("border","1px solid transparent");
  181. });
  182. $("#tckz").bind("mouseout",function(){
  183. //border:0px solid #A5AAB4;
  184. $("#tckz").css("border","0px solid #A5AAB4");
  185. });
  186. */
  187. $('#banner').mousedown(function(event) {
  188. var isMove = true;
  189. var abs_x = event.pageX - $('div.moveBar').offset().left;
  190. var abs_y = event.pageY - $('div.moveBar').offset().top;
  191. $(document).mousemove(function(event) {
  192. if (isMove) {
  193. var obj = $('div.moveBar');
  194. obj.css({
  195. 'left' : event.pageX - abs_x,
  196. 'top' : event.pageY - abs_y
  197. });
  198. }
  199. }).mouseup(function() {
  200. isMove = false;
  201. });
  202. });
  203. /*
  204. $.each(uiaccordion.find('a').parent(), function(i,val){
  205. var ua=$(val);
  206. alert(i+">>"+val.id);
  207. });
  208. */
  209. /*
  210. var footer=parent.window.document.getElementById("footer");
  211. if(footer){
  212. //alert($(parent.window.document.getElementById("footer")).height());
  213. bgrounddiv.css("height",bgrounddiv.height()-$(footer).height());
  214. }
  215. */
  216. //map = new SuperMap.Map("bgrounddiv");//,{allOverlays: true}
  217. map = new SuperMap.Map("bgrounddiv",{allOverlays: true,controls: [
  218. new SuperMap.Control.Navigation({
  219. dragPanOptions: {
  220. enableKinetic: true
  221. }
  222. })]
  223. });
  224. //scales:[1 / 147914677, 1 / 73957338, 1 / 36978669, 1 / 18489334, 1 / 9244667, 1 / 4622333, 1 / 2311166, 1 / 1000000]
  225. map.addControl(new SuperMap.Control.ScaleLine());
  226. //map.addControl(new SuperMap.Control.ScaleLine(),new SuperMap.Pixel(bgrounddiv.width()-120,bgrounddiv.height()-60));
  227. //初始化复杂缩放控件类
  228. panzoombar=new SuperMap.Control.PanZoomBar();
  229. // 是否固定缩放级别为[0,16]之间的整数,默认为false
  230. panzoombar.forceFixedZoomLevel=true;
  231. //是否显示滑动条,默认值为false
  232. panzoombar.showSlider=true;
  233. /*点击箭头移动地图时,所移动的距离占总距离(上下移动的总距离为高度,左右移动的总距离为宽度)
  234. 的百分比,默认为null。 例如:如果slideRatio 设为0.5, 则垂直上移地图半个地图高度.*/
  235. panzoombar.slideRatio=0.5;
  236. //设置缩放条滑块的高度,默认为11
  237. panzoombar.zoomStopHeight=5;
  238. //设置缩放条滑块的宽度,默认为13
  239. panzoombar.zoomStopWidth=9;
  240. //map.addControl(panzoombar);
  241. map.addControl(panzoombar,new SuperMap.Pixel(bgrounddiv.width()-90,60));
  242. //map.addControl(new SuperMap.Control.LayerSwitcher());
  243. map.events.register("addlayer",null,function(e) {
  244. //alert(e.layer.CLASS_NAME);
  245. });
  246. map.events.on({"zoomend":gis.script.eventsZoomend});
  247. /*
  248. layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", gis.script.url, null,{maxResolution:"auto"});
  249. //layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", gis.script.url,{transparent: true}, {useCanvas: true, maxResolution: "auto"});
  250. layer.events.on({"layerInitialized": gis.script.addLayer});
  251. */
  252. /*
  253. if(gis.script.controlLayer){
  254. gis.script.initLayersInfo();
  255. }else{
  256. }
  257. */
  258. //1:1214391.3776 ,scales: [1/1214391.3776] ,scales:gis.script.scales
  259. layer = new SuperMap.Layer.TiledDynamicRESTLayer("sldtLayer", gis.script.url, null,{maxResolution:"auto",scales:gis.script.scales});
  260. //layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", gis.script.url,{transparent: true}, {useCanvas: true, maxResolution: "auto"});
  261. layer.visibility=true;
  262. layer.events.on({"layerInitialized": gis.script.addmoreLayer});
  263. //gis.script.initOthenLayer();
  264. //gis.script.initVectorLayer();
  265. //gis.script.initMarkersLayer();
  266. }
  267. /*
  268. * 删除map上的弹出框
  269. */
  270. gis.script.removeAllPopup = function() {
  271. map.removeAllPopup();
  272. }
  273. /*
  274. * 地图比例改变时触发事件
  275. */
  276. gis.script.eventsZoomend = function(e) {
  277. /*
  278. if(markersLayer){
  279. if(e.object&&e.object.zoom==0){
  280. var l=map.getLayer(markersLayer.id);
  281. if(!l){
  282. map.addLayer(markersLayer);
  283. }
  284. }else{
  285. var l=map.getLayer(markersLayer.id);
  286. if(l){
  287. map.removeLayer(l);
  288. }
  289. }
  290. }
  291. */
  292. gis.script.removeAllPopup();
  293. /*
  294. for(var vv in gis.script.markersLayersInfo){
  295. var objinfo=gis.script.markersLayersInfo[vv];
  296. if(!gis.script.isBlank(objinfo.marktypename)&&
  297. gis.script.isNum(objinfo.showMinzoom)&&gis.script.isNum(objinfo.showMaxzoom)){
  298. if(e.object){
  299. //alert((!gis.script.isNum(objinfo.showMinzoom)||objinfo.showMinzoom<=e.object.zoom)&&(!gis.script.isNum(objinfo.showMaxzoom)||objinfo.showMaxzoom>=e.object.zoom));
  300. if((!gis.script.isNum(objinfo.showMinzoom)||objinfo.showMinzoom<=e.object.zoom)&&(!gis.script.isNum(objinfo.showMaxzoom)||objinfo.showMaxzoom>=e.object.zoom)){
  301. var l=gis.script.getmapinLayer(objinfo.marktypename);
  302. if(!l&&gis.script.markersLayers[objinfo.marktypename]){
  303. map.addLayer(gis.script.markersLayers[objinfo.marktypename]);
  304. }
  305. }else{
  306. var l=gis.script.getmapinLayer(objinfo.marktypename);
  307. if(l){
  308. map.removeLayer(l);
  309. }
  310. }
  311. }
  312. }
  313. }
  314. var boatvectorLayers=gis.script.addboatvectorLayer([]);
  315. gis.script.removeLayer([labelLayer,gqvectorLayer,jyrvectorLayer,mtvectorLayer,bwvectorLayer,boatLayer]);
  316. gis.script.removeLayer(boatvectorLayers);
  317. //gis.script.removeLayer(gis.script.addboatvectorLayer([]));
  318. if(labelLayer){
  319. if(e.object&&(e.object.zoom>5)){
  320. var l=map.getLayer(labelLayer.id);
  321. if(!l){
  322. map.addLayer(labelLayer);
  323. }
  324. }
  325. }
  326. if(gqvectorLayer){
  327. if(e.object&&(e.object.zoom>5&&e.object.zoom<7)){
  328. var l=map.getLayer(gqvectorLayer.id);
  329. if(!l){
  330. map.addLayer(gqvectorLayer);
  331. }
  332. }
  333. }
  334. //jyrvectorLayer
  335. if(jyrvectorLayer){
  336. if(e.object&&e.object.zoom>5){
  337. var l=map.getLayer(jyrvectorLayer.id);
  338. if(!l){
  339. map.addLayer(jyrvectorLayer);
  340. }
  341. }
  342. }
  343. if(mtvectorLayer){
  344. if(e.object&&e.object.zoom>8){
  345. var l=map.getLayer(mtvectorLayer.id);
  346. if(!l){
  347. map.addLayer(mtvectorLayer);
  348. }
  349. }
  350. }
  351. if(bwvectorLayer){
  352. if(e.object&&e.object.zoom>8){
  353. var l=map.getLayer(bwvectorLayer.id);
  354. if(!l){
  355. map.addLayer(bwvectorLayer);
  356. }
  357. }
  358. }
  359. if(boatvectorLayers.length>0){
  360. if(gis.script.markersLayers&&gis.script.pitchonMarkers&&gis.script.markersLayers[gis.script.pitchonMarkers]){
  361. gis.script.markersLayers[gis.script.pitchonMarkers].clearMarkers();
  362. }
  363. if(boatLayer){
  364. if(e.object&&e.object.zoom>8){
  365. var l=map.getLayer(boatLayer.id);
  366. if(!l){
  367. map.addLayer(boatLayer);
  368. }
  369. }
  370. }
  371. for(var ik=0;ik<boatvectorLayers.length;ik++){
  372. var blayer=boatvectorLayers[ik];
  373. if(blayer){
  374. if(e.object&&e.object.zoom>8){
  375. var l=map.getLayer(blayer.id);
  376. if(!l){
  377. map.addLayer(blayer);
  378. }
  379. }
  380. }
  381. }
  382. }
  383. */
  384. gis.script.switchtoLayer();
  385. }
  386. /*
  387. * 根据地图比例以及图层配置动态设置显示图层以及图层层次设置
  388. */
  389. gis.script.switchtoLayer = function(){
  390. //alert(gis.script.locationLayerRunRemoveAllFeatures);
  391. /*
  392. if(gis.script.locationLayerRunRemoveAllFeatures){
  393. locationLayer.removeAllFeatures();
  394. }
  395. gis.script.locationLayerRunRemoveAllFeatures=true;
  396. */
  397. //alert(gis.script.locationLayerRunRemoveAllFeatures);
  398. //locationLayer.removeAllFeatures();
  399. //gis.script.removeLayer([gis.script.markersLayers.markersgkLayer,gis.script.markersLayers.markersQskLayer]);
  400. //gis.script.removeLayer([gis.script.markersLayers.gzkMarkersLayer]);
  401. if(gis.script.markersLayers){
  402. for(var nl in gis.script.markersLayers){
  403. gis.script.removeLayer([gis.script.markersLayers[nl]]);
  404. }
  405. }
  406. /*
  407. if(gis.script.selectallLayers){
  408. for(var nl in gis.script.selectallLayers){
  409. gis.script.removeLayer([gis.script.selectallLayers[nl]]);
  410. }
  411. }
  412. */
  413. gis.script.removeLayer([labelLayer,jyrlabelLayer,gqvectorLayer,zyqvectorLayer,mdvectorLayer,jyrvectorLayer,mtvectorLayer,bwvectorLayer,boatLayer]);
  414. gis.script.removeLayer(gis.script.addboatvectorLayer([]));
  415. //map.addLayer(eval("("+"gis.script.markersLayers.markersgkLayer"+")"));
  416. if(gis.script.layersInitconfig&&gis.script.layersInitconfig.length){
  417. for(var i=0;i<gis.script.layersInitconfig.length;i++){
  418. var objinfo=gis.script.layersInitconfig[i];
  419. //alert(data.layerName);
  420. //map.addLayer(eval("("+data.layerName+")"));
  421. /*
  422. if(objinfo.layerName=="gis.script.boatonLayer.boatdanger1"){
  423. alert(objinfo.isshow&&objinfo.isshow==='true');
  424. }
  425. */
  426. if(objinfo.isshow&&objinfo.isshow==='true'){
  427. if((!gis.script.isNum(objinfo.showMinzoom)||objinfo.showMinzoom<=map.zoom)&&(!gis.script.isNum(objinfo.showMaxzoom)||objinfo.showMaxzoom>=map.zoom)){
  428. //alert(objinfo.layerName);
  429. if(eval("("+objinfo.layerName+")")){
  430. if(!gis.script.isBlank(objinfo.clear)){
  431. eval("("+objinfo.layerName+"."+objinfo.clear+"())")
  432. }
  433. map.addLayer(eval("("+objinfo.layerName+")"));
  434. }
  435. }
  436. }
  437. }
  438. }
  439. if(modifyvectorLayer){
  440. var mvLayer=map.getLayer(modifyvectorLayer.id);
  441. if(mvLayer){
  442. gis.script.removeLayer([modifyvectorLayer]);
  443. map.addLayer(modifyvectorLayer);
  444. }
  445. }
  446. }
  447. /*
  448. * 根据id获取markersLayer
  449. */
  450. gis.script.getmapinLayer = function(id) {
  451. if(gis.script.markersLayers[id]){
  452. var vid=gis.script.markersLayers[id].id
  453. return map.getLayer(vid);
  454. }
  455. return;
  456. }
  457. /*
  458. * 删除图层
  459. */
  460. gis.script.removeLayer = function(ar) {
  461. if(ar&&ar.length){
  462. for(var i=0;i<ar.length;i++){
  463. var templayer=ar[i];
  464. if(templayer){
  465. var l=map.getLayer(templayer.id);
  466. if(l){
  467. map.removeLayer(l);
  468. }
  469. }
  470. }
  471. }
  472. }
  473. /*
  474. * 加载矢量地图,以及添加layerInitialized监听事件,根据treeType切换树展示
  475. */
  476. gis.script.addmoreLayer = function() {
  477. layeryx = new SuperMap.Layer.TiledDynamicRESTLayer("yxdtLayer", gis.script.yxurl, null,{maxResolution:"auto",scales:gis.script.scales});
  478. layeryx.visibility=false;
  479. layeryx.events.on({"layerInitialized":function() {
  480. map.addLayers([layer,layeryx]);
  481. //出图,map.setCenter函数显示地图
  482. //var lonlat = layer.maxExtent.getCenterLonLat();
  483. lon =119.66;
  484. lat =32.57;
  485. //定位地图中心
  486. map.setCenter(new SuperMap.LonLat(lon, lat), 0);
  487. //map.setCenter(new SuperMap.LonLat(0, 0), 1);
  488. //map.zoomToScale(1.0/1020090.0,true);
  489. //gis.script.layerloadover=true;
  490. gis.script.initOthenLayer();
  491. gis.script.initModifyFeature();
  492. //gis.script.loadboatLayer(boatLayer,[{id:'1',lon:119.66,lat:32.57},{id:'2',lon:119.56,lat:32.47}]);
  493. /*
  494. if(gis.script.loadcbdataService&&!document.getElementById("treecbdtdiviframe")){
  495. gis.script.loadcbdataService(gis.script.phase.init);
  496. }
  497. */
  498. //alert(treeType);
  499. //gis.script.initlayersconfig();
  500. //gis.script.switchtoLayer();
  501. //根据treeType切换树展示
  502. gis.script.switchTree(treeType);
  503. gis.script.openiframetree();
  504. }});
  505. }
  506. /*
  507. * 加载船舶动态的树页面
  508. */
  509. gis.script.openiframetree = function() {
  510. //treecbdtdiviframe
  511. if(document.getElementById("treecbdtdiviframe")){
  512. document.getElementById("treecbdtdiviframe").src=contextPath+"/zygl/treeiframe.html?model=cbdtTree";
  513. }
  514. if(document.getElementById("treeaqjgdiviframe")){
  515. //document.getElementById("treeaqjgdiviframe").src=contextPath+"/zygl/treeiframe.html?model=aqjgTree";
  516. }
  517. }
  518. /*
  519. * 地图按钮控制事件
  520. */
  521. gis.script.buttonclickFun = function(id) {
  522. var imgObj=$("#"+id).find("img");
  523. if(imgObj&&imgObj.length){
  524. $.each(imgObj, function(i,val){
  525. var tua=$(val);
  526. var attrSrc=tua.attr('src');
  527. if(attrSrc&&attrSrc.indexOf("_no.png")<0){
  528. tua.attr('src',attrSrc.replace(".png","_no.png"));
  529. }else{
  530. tua.attr('src',attrSrc.replace("_no.png",".png"));
  531. }
  532. });
  533. }
  534. if(id=='tckz'||id=='cbss'){
  535. //gis.script.loadcbdataService_client(gis.script.phase.init);return;
  536. var lobj=$("#"+id+"list");
  537. if(lobj.is(':hidden')){
  538. for(var ik=0;ik<annarray.length;ik++){
  539. if(id!=annarray[ik]){
  540. $("#"+annarray[ik]+"list").hide("slow");
  541. var imgo=$("#"+annarray[ik]).find("img");
  542. $.each(imgo, function(i,val){
  543. var tua=$(val);
  544. var attrSrc=tua.attr('src');
  545. //alert(id+"--"+annarray[ik]+"--"+val.id);
  546. if(attrSrc&&attrSrc.indexOf("_no.png")>0){
  547. tua.attr('src',attrSrc.replace("_no.png",".png"));
  548. }
  549. });
  550. }
  551. }
  552. lobj.show("slow");
  553. }else{
  554. lobj.hide("slow");
  555. }
  556. }else if(id=='txbj'){
  557. if(nowModifyFeature&&modifyFeature){
  558. gis.script.removeAllPopup();
  559. //如果是编辑状态就终止编辑
  560. if(modifyvectorLayer){
  561. var mvLayer=map.getLayer(modifyvectorLayer.id);
  562. if(mvLayer){
  563. gis.script.clearAllDeactivate();
  564. gis.script.toastmessage({text:'退出地物编辑状态。'});
  565. return;
  566. }
  567. }
  568. //编辑地物前地图定位到地物中心
  569. try{
  570. if(nowModifyFeature.attributes&&nowModifyFeature.attributes.editinfoobj){
  571. //console.log("1.nowModifyFeature",nowModifyFeature.attributes.editinfoobj);
  572. var editinfoobj=nowModifyFeature.attributes.editinfoobj;
  573. map.setCenter(new SuperMap.LonLat(editinfoobj.lon,editinfoobj.lat));
  574. }
  575. }catch(e){
  576. }
  577. //进入编辑地物状态
  578. gis.script.clearAllDeactivate();
  579. //gis.script.removeLayer([modifyvectorLayer]);
  580. map.addLayer(modifyvectorLayer);
  581. modifyFeature.activate();
  582. gis.script.toastmessage({text:'点击编辑区域后进入编辑状态。'});
  583. }else{
  584. gis.script.toastmessage({text:'请先选择可编辑区域。'});
  585. gis.script.buttonimgObjRestore(id);
  586. }
  587. }
  588. }
  589. gis.script.buttonimgObjRestore = function(id) {
  590. var imgObj=$("#"+id).find("img");
  591. if(imgObj&&imgObj.length){
  592. $.each(imgObj, function(i,val){
  593. var tua=$(val);
  594. var attrSrc=tua.attr('src');
  595. if(attrSrc&&attrSrc.indexOf("_no.png")>0){
  596. tua.attr('src',attrSrc.replace("_no.png",".png"));
  597. }
  598. });
  599. }
  600. }
  601. /*
  602. * 信息提示
  603. */
  604. gis.script.toastmessage = function(obj) {
  605. var newObject = jQuery.extend(true,{
  606. sticky : false,
  607. position : 'top-right',
  608. type : 'notice',//type:notice,type:success
  609. closeText: '',
  610. stayTime : 2000,
  611. position : 'top-center'},obj);
  612. $().toastmessage('showToast',newObject);
  613. //console.log("...",newObject);
  614. }
  615. /*
  616. *清除编辑的feature
  617. */
  618. gis.script.clearAllDeactivate = function() {
  619. if(modifyFeature){
  620. if(modifyvectorLayer){
  621. gis.script.removeLayer([modifyvectorLayer]);
  622. }
  623. modifyFeature.deactivate();
  624. }
  625. }
  626. /*
  627. * 创建可编辑图层
  628. */
  629. gis.script.initModifyFeature = function() {
  630. if(layerUserControl&&typeof(layerUserControl)!='undefined'){
  631. if(typeof(layerUserControl.modifyFeature)!='undefined'){
  632. if(layerUserControl.modifyFeature==false){
  633. return;
  634. }
  635. }
  636. }
  637. //alert(layerUserControl.modifyFeature);
  638. modifyFeature = new SuperMap.Control.ModifyFeature(modifyvectorLayer);
  639. map.addControl(modifyFeature);
  640. }
  641. /*
  642. * 图层编辑完成后的触发函数
  643. */
  644. gis.script.editFeatureCompleted = function(event) {
  645. //alert($.confirm)
  646. $.confirm({
  647. title : '确认框',
  648. content : '确认保存编辑区域吗',
  649. confirm : function() {
  650. if(event){
  651. var feature = event.feature;
  652. gis.script.editgisFeatureService(feature);
  653. }
  654. }
  655. });
  656. gis.script.buttonimgObjRestore('txbj');
  657. gis.script.clearAllDeactivate();
  658. }
  659. /*
  660. * 编辑信息写入
  661. */
  662. gis.script.editgisFeatureService = function(feature) {
  663. if(feature&&feature.attributes
  664. &&feature.attributes.gisEditLayerinfoKey
  665. &&gis.script.isNum(feature.attributes.featureidval)){
  666. if(dataServices){
  667. gis.script.consolelog('dataServices',dataServices);
  668. for(var n in dataServices){
  669. var data=gisConfigBean.dataconfig[n];
  670. if(data&&feature.attributes.gisEditLayerinfoKey==data.gisLayerinfoKey){
  671. data=jQuery.extend(true, {}, data);
  672. data.datasetNames=data.datasetNames.split(",");
  673. data.fields=data.fields.split(",");
  674. data.url=data.url||defdataUrl;
  675. //console.log("data",data);
  676. if(data.fields&&data.fields.length){
  677. var attributes = feature.attributes;
  678. var attrNames = data.fields;
  679. var attrValues = [];
  680. for(var i=0;i<attrNames.length;i++){
  681. //alert(attrNames[i]);
  682. attrValues.push(attributes[attrNames[i]]);
  683. }
  684. var features = {
  685. fieldNames:attrNames,
  686. fieldValues:attrValues,
  687. geometry:feature.geometry
  688. };
  689. //console.log("features",features);
  690. //alert(features.geometry.id+"--"+feature.attributes.featureidval)
  691. features.geometry.id = feature.attributes.featureidval;
  692. var editFeatureParameter = new SuperMap.REST.EditFeaturesParameters({
  693. features: [features],
  694. editType: SuperMap.REST.EditType.UPDATE
  695. });
  696. if(data.url&&data.datasetNames&&data.datasetNames.length==1){
  697. var dnames=data.datasetNames[0].split(":");
  698. if(dnames&&dnames.length==2){
  699. //console.log("dnames",dnames);
  700. var url=data.url+"/datasources/"+dnames[0]+"/datasets/"+dnames[1];
  701. //alert("http://127.0.0.1:8090/iserver/services/data-ST/rest/data/datasources/gkzyYS/datasets/L_GQ_PY"+"\n"+url);
  702. var editFeatureService = new SuperMap.REST.EditFeaturesService(url, {
  703. eventListeners: {
  704. "processCompleted": function(editFeaturesEventArgs) {
  705. gis.script.updateFeaturesProcessCompleted(editFeaturesEventArgs,feature);
  706. },
  707. "processFailed": gis.script.sqlProcessFailed
  708. }
  709. });
  710. editFeatureService.processAsync(editFeatureParameter);
  711. }
  712. }
  713. }
  714. break;
  715. }
  716. }
  717. }
  718. }
  719. }
  720. /*
  721. * 提示用户地物编辑是否保存成功,并且刷新图层
  722. */
  723. gis.script.updateFeaturesProcessCompleted = function(editFeaturesEventArgs,feature) {
  724. if(editFeaturesEventArgs&&editFeaturesEventArgs.result.resourceInfo.succeed) {
  725. //alert("更新地物成功");
  726. gis.script.toastmessage({text:'更新地物成功。',type:'success'});
  727. gis.script.updateFeaturesloadLayerdata(editFeaturesEventArgs,feature);
  728. }else{
  729. gis.script.toastmessage({text:'更新地物失败。',type:'warning'});
  730. }
  731. }
  732. //var uflldMap={"GK_BASIC_JSJY_GK_GQ":gqvectorLayer,"GK_BASIC_JSJY_JYR":jyrvectorLayer,"GK_BASIC_JSJY_JYR_MT":mtvectorLayer,"GK_BASIC_JSJY_JYR_BW":bwvectorLayer,"GK_BASIC_JSJY_GK_ZYQ":zyqvectorLayer};
  733. gis.script.updateFeaturesloadLayerdata = function(editFeaturesEventArgs,feature) {
  734. if(feature&&feature.attributes
  735. &&feature.attributes.gisEditLayerinfoKey){
  736. //console.log("feature",feature);//uflldLayerMap
  737. if(uflldLayerMap&&uflldLayerMap[feature.attributes.gisEditLayerinfoKey]){
  738. var tlayer=uflldLayerMap[feature.attributes.gisEditLayerinfoKey];
  739. if(dataServices){
  740. for(var n in dataServices){
  741. var data=gisConfigBean.dataconfig[n];
  742. if(data&&feature.attributes.gisEditLayerinfoKey==data.gisLayerinfoKey){
  743. data=jQuery.extend(true, {}, data);
  744. if(data.gisLayerinfoAttrKey&&feature.attributes[data.gisLayerinfoAttrKey]){
  745. /*
  746. var param={};
  747. param[data.gisLayerinfoAttrKey]=feature.attributes[data.gisLayerinfoAttrKey];
  748. */
  749. var fba=tlayer.getFeaturesByAttribute(data.gisLayerinfoAttrKey,feature.attributes[data.gisLayerinfoAttrKey]);
  750. if(fba&&fba.length==1){
  751. if(locationLayer){
  752. locationLayer.removeAllFeatures();
  753. var cloneFeature=feature.clone();
  754. var fillColor="#a4a5a7";//"#ffff00"
  755. var fillOpacity=0.5;
  756. cloneFeature.style = {
  757. fill:true,
  758. stroke:true,
  759. strokeColor: "#ffff00",
  760. strokeWidth: 3,
  761. //pointerEvents: "visiblePainted",
  762. //fillColor: "#a4a5a7",
  763. strokeDashstyle:"solid",
  764. fillColor: fillColor,
  765. fillOpacity: fillOpacity
  766. };
  767. locationLayer.addFeatures(cloneFeature);
  768. }
  769. tlayer.removeFeatures(fba);
  770. if(data.Model&&data.Model[gis.script.modelid]){
  771. var model=data.Model[gis.script.modelid];
  772. data.datasetNames=data.datasetNames.split(",");
  773. data.fields=data.fields.split(",");
  774. data.cachedata=model.cachedata||data.cachedata;
  775. data.zoom=model.zoom||data.zoom;
  776. data.processCompleted=model.processCompleted;
  777. data.onSelectOpenPopkey=model.onSelectOpenPopkey;
  778. data.modelObj=model;
  779. data.url=data.url||defdataUrl;
  780. data.attributeFilter=data.gisLayerinfoAttrKey+"="+feature.attributes[data.gisLayerinfoAttrKey];
  781. //console.log("data",data);
  782. gis.script.loadLayerFeaturesBySqls(data);
  783. }
  784. }
  785. }
  786. }
  787. }
  788. }
  789. }
  790. }
  791. }
  792. /*
  793. * 创建地图中的所有所需的图层
  794. */
  795. gis.script.initOthenLayer = function() {
  796. gkvectorLayer = new SuperMap.Layer.Vector("gkvectorLayer");
  797. gqvectorLayer = new SuperMap.Layer.Vector("gqvectorLayer");
  798. zyqvectorLayer = new SuperMap.Layer.Vector("zyqvectorLayer");
  799. mdvectorLayer = new SuperMap.Layer.Vector("mdvectorLayer");
  800. jyrvectorLayer = new SuperMap.Layer.Vector("jyrvectorLayer");
  801. locationLayer = new SuperMap.Layer.Vector("locationLayer");
  802. mtvectorLayer = new SuperMap.Layer.Vector("mtvectorLayer");
  803. bwvectorLayer = new SuperMap.Layer.Vector("bwvectorLayer");
  804. vectorLayer = new SuperMap.Layer.Vector("vector");
  805. boatLayer = new SuperMap.Layer.Vector("boatLayer");
  806. markersLayer = new SuperMap.Layer.Markers("Markers");
  807. //modifyvectorLayer = new SuperMap.Layer.Vector("modifyvectorLayer", {renderers: ["Canvas2"]});
  808. modifyvectorLayer = new SuperMap.Layer.Vector("modifyvectorLayer");
  809. modifyvectorLayer.events.on({"afterfeaturemodified": gis.script.editFeatureCompleted});
  810. uflldLayerMap={"GK_BASIC_JSJY_GK_GQ":gqvectorLayer,"GK_BASIC_JSJY_JYR":jyrvectorLayer,"GK_BASIC_JSJY_JYR_MT":mtvectorLayer,"GK_BASIC_JSJY_JYR_BW":bwvectorLayer,"GK_BASIC_JSJY_GK_ZYQ":zyqvectorLayer,"GK_BASIC_JSJY_GK_MD":mdvectorLayer};
  811. //uflldLayerMap={"GK_BASIC_JSJY_GK_GQ":gqvectorLayer,"GK_BASIC_JSJY_JYR":jyrvectorLayer,"GK_BASIC_JSJY_JYR_MT":mtvectorLayer,"GK_BASIC_JSJY_JYR_BW":bwvectorLayer,"GK_BASIC_JSJY_GK_ZYQ":zyqvectorLayer};
  812. gis.script.markersLayers.markersgkLayer=new SuperMap.Layer.Markers("markersgkLayer");
  813. gis.script.markersLayers.gzkMarkersLayer=new SuperMap.Layer.Markers("gzkMarkersLayer");
  814. gis.script.markersLayers.markersQskLayer=new SuperMap.Layer.Markers("markersQskLayer");
  815. //gis.script.selectallLayers.bwSelectvectorLayer=new SuperMap.Layer.Vector("bwSelectvectorLayer");
  816. if(gis.script.initboatonLayer){
  817. gis.script.initboatonLayer();
  818. }
  819. boatLayer.styleMap = new SuperMap.StyleMap({
  820. "default":new SuperMap.Style({
  821. fillColor:"#000000",
  822. strokeColor:"#000000",
  823. fillOpacity: 0.6,
  824. graphicZIndex:1
  825. })
  826. });
  827. gqvectorLayer.styleMap=new SuperMap.StyleMap({
  828. "default":new SuperMap.Style({
  829. fill:true,
  830. fillColor:"#ffffff",
  831. strokeColor:"#ff0000",
  832. strokeDashstyle:"longdashdot",
  833. fillOpacity: 0.1,
  834. graphicZIndex:1
  835. }),
  836. "select":{
  837. strokeColor: "#ffff00",
  838. strokeWidth: 2,
  839. strokeDashstyle:"solid",
  840. fillColor: "#a4a5a7",
  841. fillOpacity: 0.5,
  842. graphicZIndex:2
  843. }
  844. });
  845. zyqvectorLayer.styleMap=new SuperMap.StyleMap({
  846. "default":new SuperMap.Style({
  847. fill:true,
  848. fillColor:"#ffffff",
  849. strokeColor:"#ff0000",
  850. strokeDashstyle:"longdashdot",
  851. fillOpacity: 0.1,
  852. graphicZIndex:1
  853. }),
  854. "select":{
  855. strokeColor: "#ffff00",
  856. strokeWidth: 2,
  857. strokeDashstyle:"solid",
  858. fillColor: "#a4a5a7",
  859. fillOpacity: 0.5,
  860. graphicZIndex:2
  861. }
  862. });
  863. mdvectorLayer.styleMap=new SuperMap.StyleMap({
  864. "default":new SuperMap.Style({
  865. fill:true,
  866. fillColor:"#ffffff",
  867. strokeColor:"#ff0000",
  868. strokeDashstyle:"longdashdot",
  869. fillOpacity: 0.1,
  870. graphicZIndex:1
  871. }),
  872. "select":{
  873. strokeColor: "#ffff00",
  874. strokeWidth: 2,
  875. strokeDashstyle:"solid",
  876. fillColor: "#a4a5a7",
  877. fillOpacity: 0.5,
  878. graphicZIndex:2
  879. }
  880. });
  881. jyrvectorLayer.styleMap=new SuperMap.StyleMap({
  882. "default":new SuperMap.Style({
  883. fill:true,
  884. fillColor:"#ffffff",
  885. strokeColor:"#e36c09",
  886. strokeDashstyle:"dash",
  887. fillOpacity: 0.1,
  888. graphicZIndex:1
  889. }),
  890. "select":{
  891. strokeColor: "#ffff00",
  892. strokeWidth: 2,
  893. strokeDashstyle:"solid",
  894. fillColor: "#a4a5a7",
  895. fillOpacity: 0.5,
  896. graphicZIndex:2
  897. }
  898. });
  899. mtvectorLayer.styleMap=new SuperMap.StyleMap({
  900. "default":new SuperMap.Style({
  901. fill:true,
  902. fillColor:"#e4deea",
  903. strokeColor:"#a9a297",
  904. strokeDashstyle:"solid",
  905. strokeOpacity:0.8,
  906. strokeWidth:1,
  907. fillOpacity: 0.5,
  908. graphicZIndex:1
  909. }),
  910. "select":{
  911. strokeColor: "#ffff00",
  912. strokeWidth: 2,
  913. strokeDashstyle:"solid",
  914. fillColor: "#a4a5a7",
  915. fillOpacity: 0.5,
  916. graphicZIndex:2
  917. }
  918. });
  919. bwvectorLayer.styleMap=new SuperMap.StyleMap({
  920. "default":new SuperMap.Style({
  921. fill:true,
  922. fillColor:"#77a4dc",
  923. strokeColor:"#303030",
  924. strokeDashstyle:"solid",
  925. strokeOpacity:0.8,
  926. strokeWidth:1,
  927. fillOpacity: 0.1,
  928. graphicZIndex:1
  929. }),
  930. "select":{
  931. strokeColor: "#ffff00",
  932. strokeWidth: 2,
  933. strokeDashstyle:"solid",
  934. //strokeOpacity:0.8,
  935. fillColor: "#a4a5a7",
  936. fillOpacity: 0.5,
  937. graphicZIndex:2
  938. }
  939. });
  940. var strategy = new SuperMap.Strategy.GeoText();
  941. strategy.style = {
  942. //fontColor:"#FF7F00",
  943. fontColor:"#000000",
  944. fontWeight:"bolder",
  945. fontSize:"14px",
  946. fill: false,
  947. fillColor: "#FFFFFF",
  948. fillOpacity: 1,
  949. stroke: false,
  950. strokeColor:"#8B7B8B"
  951. };
  952. labelLayer = new SuperMap.Layer.Vector("Label",{strategies: [strategy]});
  953. var jyrstrategy = new SuperMap.Strategy.GeoText();
  954. jyrstrategy.style = {
  955. //fontColor:"#FF7F00",
  956. fontColor:"#000000",
  957. fontWeight:"bolder",
  958. fontSize:"14px",
  959. fill: false,
  960. fillColor: "#FFFFFF",
  961. fillOpacity: 1,
  962. stroke: false,
  963. strokeColor:"#8B7B8B"
  964. };
  965. jyrlabelLayer = new SuperMap.Layer.Vector("jyrlabelLayer",{strategies: [jyrstrategy]});
  966. //gis.script.layerSelectFeature([gkvectorLayer,gqvectorLayer,jyrvectorLayer,bwvectorLayer,vectorLayer]);
  967. //gis.script.layerSelectFeature([gkvectorLayer,gqvectorLayer,jyrvectorLayer,vectorLayer,boatLayer]);
  968. gis.script.layerSelectFeature(gis.script.addboatvectorLayer([gkvectorLayer,gqvectorLayer,zyqvectorLayer,mdvectorLayer,jyrvectorLayer,mtvectorLayer,bwvectorLayer,vectorLayer]));
  969. gis.script.loadLayerdata();
  970. //map.addLayers([gkvectorLayer,gqvectorLayer,vectorLayer,markersLayer]);
  971. map.addLayers([labelLayer,locationLayer,gkvectorLayer,vectorLayer,markersLayer]);
  972. /*
  973. var geoText = new SuperMap.Geometry.GeoText(119.66, 32.57,"中华人民共和国");
  974. var geotextFeature = new SuperMap.Feature.Vector(geoText);
  975. labelLayer.addFeatures([geotextFeature]);
  976. */
  977. gis.script.layerloadover=true;
  978. }
  979. gis.script.addboatvectorLayer = function(objs) {
  980. if(gis.script.loadcbdataService&&gis.script.boatonLayer&&objs){
  981. //console.log("CCC:",gis.script.boatonLayer);
  982. for(var n in gis.script.boatonLayer){
  983. objs.push(gis.script.boatonLayer[n]);
  984. }
  985. //console.log("CCC:",objs);
  986. }
  987. return objs
  988. }
  989. gis.script.initMarkersLayer = function() {
  990. markersLayer = new SuperMap.Layer.Markers("Markers");
  991. layer.events.on({"layerInitialized":function() {
  992. map.addLayer(markersLayer);
  993. if(gis.script.loadMarkersLayerdata){
  994. gis.script.loadMarkersLayerdata();
  995. }
  996. }});
  997. }
  998. gis.script.initVectorLayer = function() {
  999. vectorLayer = new SuperMap.Layer.Vector("vector");
  1000. layer.events.on({"layerInitialized": function() {
  1001. map.addLayer(vectorLayer);
  1002. gis.script.selectFeature();
  1003. }
  1004. });
  1005. }
  1006. gis.script.addLayer = function() {
  1007. map.addLayer(layer);
  1008. //出图,map.setCenter函数显示地图
  1009. var lonlat = layer.maxExtent.getCenterLonLat();
  1010. lon = lonlat.lon;
  1011. lat = lonlat.lat;
  1012. map.setCenter(new SuperMap.LonLat(lon, lat), 0);
  1013. //map.setCenter(new SuperMap.LonLat(0, 0), 1);
  1014. //map.zoomToScale(1.0/1020090.0,true);
  1015. gis.script.layerloadover=true;
  1016. }
  1017. /*
  1018. * 给Feature添加点击事件,Feature包括港区、经营人、码头、泊位、船舶
  1019. */
  1020. gis.script.layerSelectFeature = function(vlist){
  1021. if(vlist&&vlist.length){
  1022. var selectFeature= new SuperMap.Control.SelectFeature(vlist, {
  1023. //是否重复触发地物选择事件,只在单选非toggle模式下有效。默认为false,表示处于 选中状态的地物不在触发选择事件。
  1024. //repeat:true,
  1025. hover:true,
  1026. callbacks:{
  1027. click: function(feature){
  1028. //for(var cf in currentFeature){alert(cf);}
  1029. //alert(event.clientX+"--"+event.clientY);
  1030. //var lonlat=map.getLonLatFromPixel(new SuperMap.Pixel(event.clientX,event.clientY));
  1031. //alert(lonlat.lon.toFixed(5));
  1032. var eve=window.event;
  1033. gis.script.featurecallbacksclick(feature,eve);
  1034. if(feature){
  1035. var fillColor="#a4a5a7";//"#ffff00"
  1036. var fillOpacity=0.5;
  1037. var cloneFeature=feature.clone();
  1038. cloneFeature.style = {
  1039. fill:true,
  1040. stroke:true,
  1041. strokeColor: "#ffff00",
  1042. strokeWidth: 3,
  1043. //pointerEvents: "visiblePainted",
  1044. //fillColor: "#a4a5a7",
  1045. strokeDashstyle:"solid",
  1046. fillColor: fillColor,
  1047. fillOpacity: fillOpacity
  1048. };
  1049. locationLayer.addFeatures(cloneFeature);
  1050. nowModifyFeature=feature.clone();
  1051. /*
  1052. var mapCenter=map.getCenter();
  1053. if(mapCenter){
  1054. nowModifyFeature.attributes.editinfoobj={lon:mapCenter.lon,lat:mapCenter.lat,zoom:map.zoom};
  1055. //console.log("1.getCenter",map.getCenter());
  1056. //console.log("1.nowModifyFeature.attributes.editinfoobj",nowModifyFeature.attributes.editinfoobj);
  1057. }
  1058. */
  1059. var centerLonLat = feature.geometry.getBounds().getCenterLonLat();
  1060. if(centerLonLat){
  1061. nowModifyFeature.attributes.editinfoobj={lon:centerLonLat.lon,lat:centerLonLat.lat,zoom:map.zoom};
  1062. //console.log("2.nowModifyFeature.attributes.editinfoobj",nowModifyFeature.attributes.editinfoobj);
  1063. }
  1064. modifyvectorLayer.removeAllFeatures();
  1065. modifyvectorLayer.addFeatures(nowModifyFeature);
  1066. }
  1067. }
  1068. },
  1069. onSelect: function(feature) {
  1070. //gis.script.featurecallbacksclick(feature);
  1071. }
  1072. });
  1073. map.addControl(selectFeature);
  1074. selectFeature.activate();
  1075. }
  1076. }
  1077. gis.script.featurecallbacksclick = function(feature,e){
  1078. //alert(feature.attributes.onSelectOpenPopkey);
  1079. if(locationLayer){
  1080. locationLayer.removeAllFeatures();
  1081. }
  1082. var chicken=$('#chicken');
  1083. chicken.remove();
  1084. if(feature.attributes&&feature.attributes.onSelectOpenPopkey&&gis.script[feature.attributes.onSelectOpenPopkey]){
  1085. //alert(feature.attributes.onSelectOpenPopkey);
  1086. gis.script[feature.attributes.onSelectOpenPopkey](feature,e);
  1087. }
  1088. /*
  1089. if(gis.script.gisidTo&&feature.attributes&&feature.attributes.gisidToKey){
  1090. var sinfo=gis.script.gisidTo[feature.attributes.gisidToKey];
  1091. var tempSize={width:320,height:155};
  1092. if(sinfo&&sinfo.ID){
  1093. //alert(sinfo.ID);
  1094. gis.script.jsonAjax({url:contextPath+"/zygl/queryGK.html",async:true,data:{id:sinfo.ID}},
  1095. function(data){
  1096. //alert(JSON.stringify(data));
  1097. if(data&&data.message){
  1098. //alert(data.message);
  1099. //alert(gis.script.popSize[feature.attributes.gisLayerinfoKey]);
  1100. var popup = gis.anchored.popupHtml(feature.geometry.getBounds().getCenterLonLat(),gis.script.popSize[feature.attributes.gisLayerinfoKey]||tempSize,data.message);
  1101. gis.anchored.addPopup(map,popup);
  1102. }
  1103. });
  1104. }else{
  1105. var popup = gis.anchored.popupHtml(feature.geometry.getBounds().getCenterLonLat(),tempSize,
  1106. gis.anchored.tohtml(gis.anchored.nvlinfo({poptitle:"&nbsp;",portName:feature.attributes.NAME||feature.attributes.name||""})));
  1107. gis.anchored.addPopup(map,popup);
  1108. }
  1109. }
  1110. */
  1111. }
  1112. gis.script.selectFeature = function(){
  1113. /*
  1114. var callbacks={
  1115. click: function(currentFeature){
  1116. //for(var cf in currentFeature){alert(cf);}
  1117. alert(cf.data);
  1118. }
  1119. };
  1120. var selectFeature = new SuperMap.Control.SelectFeature(vectorLayer,
  1121. {
  1122. callbacks: callbacks
  1123. });
  1124. */
  1125. var selectFeature= new SuperMap.Control.SelectFeature(vectorLayer, {
  1126. //是否重复触发地物选择事件,只在单选非toggle模式下有效。默认为false,表示处于 选中状态的地物不在触发选择事件。
  1127. repeat:true,
  1128. onSelect: function(feature) {
  1129. /*
  1130. selecedtBus = feature;
  1131. popup = new SuperMap.Popup("chicken",
  1132. selecedtBus.geometry.getBounds().getCenterLonLat(),
  1133. new SuperMap.Size(300,42),
  1134. "", null, true);
  1135. selecedtBus.popup = popup;
  1136. map.addPopup(popup);
  1137. */
  1138. //console.log('feature:',feature);
  1139. //alert(feature.id);
  1140. var popup = gis.anchored.popup(feature.geometry.getBounds().getCenterLonLat(),{});
  1141. gis.anchored.addPopup(map,popup);
  1142. }
  1143. }
  1144. );
  1145. map.addControl(selectFeature);
  1146. selectFeature.activate();
  1147. /*
  1148. var selectFeature= new SuperMap.Control.SelectFeature(vectorLayer, {
  1149. onSelect: function(feature) {
  1150. selecedtBus = feature;
  1151. popup = new SuperMap.Popup("chicken",
  1152. selecedtBus.geometry.getBounds().getCenterLonLat(),
  1153. new SuperMap.Size(300,42),
  1154. "dddddddddddd", null, true);
  1155. selecedtBus.popup = popup;
  1156. map.addPopup(popup);
  1157. //var popup = gis.anchored.popup(feature.geometry.getBounds().getCenterLonLat(),{});
  1158. //gis.anchored.addPopup(map,popup);
  1159. },
  1160. //onUnselect: function() {alert(2)}
  1161. }
  1162. );
  1163. map.addControl(selectFeature);
  1164. selectFeature.activate();
  1165. */
  1166. }
  1167. /*
  1168. * 给Marker添加点击事件,Marker包括港口
  1169. */
  1170. gis.script.addMarker = function(obj){
  1171. var size;
  1172. var offset;
  1173. var mattr=gis.script.markerAttr[obj.type];
  1174. if(!mattr){
  1175. size= new SuperMap.Size(obj.w,obj.h);
  1176. offset=new SuperMap.Pixel(-(size.w/2), -(size.h/2));
  1177. gis.script.markerAttr[obj.type]={};
  1178. gis.script.markerAttr[obj.type].size=size;
  1179. gis.script.markerAttr[obj.type].offset=offset;
  1180. }else{
  1181. size=gis.script.markerAttr[obj.type].size;
  1182. offset=gis.script.markerAttr[obj.type].offset
  1183. }
  1184. if(size&&offset){
  1185. //alert(size);
  1186. var icon = new SuperMap.Icon(obj.src, size, offset);
  1187. var marker = new SuperMap.Marker(new SuperMap.LonLat(obj.lon,obj.lat),icon);
  1188. //添加覆盖物到标记图层
  1189. //markersLayer.addMarker(marker);
  1190. gis.script.addMarkerLayer(obj,marker);
  1191. //eval("(showMarkerInfo())")
  1192. if(!gis.script.isBlank(obj.functionName)){
  1193. marker.events.on({"click":function(e) {
  1194. //alert(e);alert(event);
  1195. //alert(this);alert(event);
  1196. var eve=window.event||e;
  1197. obj.events=this;
  1198. //gis.script[obj.functionName](obj.feature,event);
  1199. gis.script[obj.functionName](obj.feature,eve);
  1200. }});
  1201. }
  1202. }
  1203. }
  1204. gis.script.addMarkerLayer = function(obj,marker){
  1205. if(!gis.script.isBlank(obj.marktypename)){
  1206. //alert(obj.marktypename);
  1207. //gis.script.markersLayers
  1208. /*
  1209. if(!gis.script.markersLayers[obj.marktypename]){
  1210. gis.script.markersLayers[obj.marktypename] = new SuperMap.Layer.Markers(obj.marktypename);
  1211. if(obj.defshow&&obj.defshow=="true"){
  1212. map.addLayer(gis.script.markersLayers[obj.marktypename]);
  1213. }
  1214. gis.script.markersLayersInfo[obj.marktypename]=obj;
  1215. }
  1216. */
  1217. //alert(gis.script.markersLayers[obj.marktypename]);
  1218. //alert(obj.marktypename);
  1219. //console.log('obj.marktypename:',obj.marktypename);
  1220. gis.script.markersLayers[obj.marktypename].addMarker(marker);
  1221. }
  1222. }
  1223. gis.script.showMarkerInfo = function(obj){
  1224. //alert(JSON.stringify(obj));
  1225. //var popup = gis.anchored.popup(obj.events.getLonLat(),{});
  1226. var popup = gis.anchored.popupHtml(obj.events.getLonLat(),{width:320,height:155},
  1227. gis.anchored.tohtml(gis.anchored.portinfo({portName:obj.name,portNumber:2,anchorageNumber:2,chanceNumber:16})));
  1228. gis.anchored.addPopup(map,popup);
  1229. }
  1230. gis.script.getLayersInfo = function(){
  1231. var getLayersInfoService = new SuperMap.REST.GetLayersInfoService(gis.script.url);
  1232. getLayersInfoService.events.on({ "processCompleted": gis.script.processCompletedlayers});
  1233. getLayersInfoService.processAsync();
  1234. }
  1235. gis.script.processCompletedlayers = function(e){
  1236. //gis.script.consolelog('e:',e);
  1237. if(e&&e.result&&e.result.subLayers){
  1238. var layers=e.result.subLayers.layers;
  1239. for (var j = 0; j <layers.length; j++) {
  1240. gis.script.subLayers.push(layers[j])
  1241. //alert(layers[j]);
  1242. //alert("<input type='checkbox' checked="+layers[j].visible+"/><span>"+layers[j].name+"</span>");
  1243. $("<input type='checkbox' class='checkboxSel' value='"+layers[j].name+"' "+(layers[j].visible?"checked=true":"")+"/><span>"+layers[j].name+"</span>").addClass("popupSpan").appendTo($("#layers"));
  1244. //break;
  1245. }
  1246. }
  1247. //alert("-->"+$("#layers .checkboxSel").length)
  1248. var cb=$("#layers .checkboxSel");
  1249. cb.click(function () {
  1250. alert(layer.params.layersID)
  1251. var str=new Array();
  1252. str.push("[");
  1253. $.each(cb, function(i, item){
  1254. if(eval(item.checked) == true){
  1255. str.push(args);
  1256. }
  1257. });
  1258. str.push(",]");
  1259. alert(str.length+"-->"+str.join("").replace(",]","]"));
  1260. //layer.redraw();
  1261. });
  1262. //样式为BootStrap框架设置
  1263. /*
  1264. cb.hover(function () {
  1265. $(this).addClass("label-success");
  1266. }, function () {
  1267. $(this).removeClass("label-success");
  1268. });
  1269. */
  1270. gis.script.createTempLayer();
  1271. }
  1272. gis.script.createTempLayer = function(){
  1273. var cb=$("#layers .checkboxSel");
  1274. var layerStatusParameters = new SuperMap.REST.SetLayerStatusParameters();
  1275. layerStatusParameters = (function(parameters) {
  1276. //alert(parameters);
  1277. $.each(cb, function(i, item){
  1278. var layerStatus = new SuperMap.REST.LayerStatus();
  1279. layerStatus.layerName = item.value;
  1280. layerStatus.isVisible = eval(item.checked);
  1281. //alert(layerStatus.layerName+"--"+layerStatus.isVisible)
  1282. parameters.layerStatusList.push(layerStatus);
  1283. });
  1284. //设置资源在服务端保存的时间,单位为分钟,默认为10
  1285. parameters.holdTime = 30;
  1286. return parameters;
  1287. })(layerStatusParameters);
  1288. var setLayerStatusService = new SuperMap.REST.SetLayerStatusService(gis.script.url);
  1289. setLayerStatusService.events.on({ "processCompleted": function(createTempLayerEventArgs){
  1290. tempLayerID = createTempLayerEventArgs.result.newResourceID;
  1291. //创建 TiledDynamicRESTLayer
  1292. //layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", gis.script.url, {transparent: true, cacheEnabled: false, redirect: true, layersID: tempLayerID}, {maxResolution: "auto", bufferImgCount: 0});
  1293. //layer.bufferImgCount = 0;
  1294. //layer.events.on({"layerInitialized": gis.script.addLayer});
  1295. layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", gis.script.url, {transparent: true, cacheEnabled: false, redirect: true, layersID: tempLayerID},{maxResolution:"auto", bufferImgCount: 0});
  1296. layer.bufferImgCount = 0;
  1297. layer.events.on({"layerInitialized": gis.script.addLayer});
  1298. }});
  1299. setLayerStatusService.processAsync(layerStatusParameters);
  1300. }
  1301. gis.script.initLayersInfo = function() {
  1302. gis.script.getLayersInfo();
  1303. }
  1304. gis.script.setMapCenter = function(info){
  1305. //alert(info.zoomSize);
  1306. if(info&&typeof(info.lon)!="undefined"&&typeof(info.lat)!="undefined"){
  1307. map.setCenter(new SuperMap.LonLat(info.lon, info.lat),info.zoomSize);
  1308. issetCenter=true;
  1309. }
  1310. }
  1311. gis.script.setMaplocationLayer = function(feature,o){
  1312. locationLayer.removeAllFeatures();
  1313. if(feature){
  1314. locationLayer.addFeatures(feature);
  1315. try{
  1316. if(o.labelfield&&feature.attributes[o.labelfield]){
  1317. labelLayer.removeAllFeatures();
  1318. var geoText = new SuperMap.Geometry.GeoText(centerLonLat.lon, centerLonLat.lat,feature.attributes[o.labelfield]);
  1319. var geotextFeature = new SuperMap.Feature.Vector(geoText);
  1320. labelLayer.addFeatures([geotextFeature]);
  1321. }
  1322. }catch(e){
  1323. }
  1324. }
  1325. }
  1326. var switchto=false;
  1327. gis.script.testSwitchto = function(){
  1328. var uri;
  1329. if(switchto){
  1330. uri="/znjg/zygl/treeiframe.html?model=gis&treeType=ty"
  1331. }else{
  1332. uri="/znjg/zygl/treeiframe.html?model=gis&treeType=cbdt"
  1333. }
  1334. //alert(gis.script.queryString(uri,"treeType"));
  1335. var o={menuurl:uri}
  1336. gis.script.switchto(o);
  1337. switchto=!switchto;
  1338. }
  1339. /*
  1340. * 切换专辑图
  1341. */
  1342. gis.script.switchto = function(o){
  1343. if(o&&o.menuurl){
  1344. if(!gis.script.layerloadover){
  1345. window.location.href=o.menuurl;
  1346. return;
  1347. }
  1348. var ttype=gis.script.queryString(o.menuurl,"treeType");
  1349. gis.script.switchTree(ttype);
  1350. }
  1351. //alert($(".treedivClass").length);
  1352. }
  1353. gis.script.switchTree = function(ttype){
  1354. treeType=ttype;
  1355. if(treeType){
  1356. //alert(treeType);
  1357. $.each($(".treedivClass"), function(i,val){
  1358. var ua=$(val);
  1359. ua.css("display","none");
  1360. });
  1361. $("#tree"+treeType+"div").css("display","");
  1362. }
  1363. gis.script.initlayersconfig();
  1364. //gis.script.settrendsLayer("gkMarkLayer","false");
  1365. //gis.script.settrendsLayer("gqvectorLayer","false");
  1366. //gis.script.settrendsLayer("boatonLayers",'true');
  1367. gis.script.switchtoLayer();
  1368. gis.script.switchtckzTree();
  1369. gis.script.switchcbsslist(ttype);
  1370. }
  1371. gis.script.switchcbsslist = function(ttype){
  1372. if(ttype=='cbdt'){
  1373. $("#cbss").css("display","");
  1374. }else{
  1375. $("#cbss").css("display","none");
  1376. $("#cbsslist").css("display","none");
  1377. }
  1378. //$("#txbj").css("display","");
  1379. if(layerUserControl&&typeof(layerUserControl)!='undefined'){
  1380. if(typeof(layerUserControl.modifyFeature)!='undefined'){
  1381. if(layerUserControl.modifyFeature==true){
  1382. $("#txbj").css("display","");
  1383. }
  1384. }
  1385. }
  1386. var kk=0;
  1387. for(var ii=0;ii<annarray.length;ii++){
  1388. var annobj=$("#"+annarray[ii]);
  1389. if(annobj&&annobj.length){
  1390. //annobj.css("top",bgrounddiv.offset().top+10);
  1391. //annobj.css("right",32+52*(ii+1));
  1392. //alert(annobj.css('display'));
  1393. if(annobj.css('display')&&annobj.css('display')!='none'){
  1394. annobj.css("right",32+52*(kk+1));
  1395. kk=kk+1;
  1396. }
  1397. }
  1398. }
  1399. }
  1400. gis.script.switchtckzTree = function(){
  1401. var iframepage=document.getElementById("treetckzdiviframe");
  1402. if(iframepage){
  1403. if(!gis.script.tckztreeloadover){
  1404. iframepage.src=contextPath+"/zygl/treeiframe.html?model=tckzTree";
  1405. }else{
  1406. if(iframepage.contentWindow){
  1407. iframepage.contentWindow.gis.tree.inittreeCheck("tree");
  1408. }
  1409. }
  1410. }
  1411. }
  1412. /*
  1413. * 获取参数
  1414. */
  1415. gis.script.queryString = function (uri,val){
  1416. //var uri = window.location.search;
  1417. var re = new RegExp("" +val+ "=([^\&\?]*)", "ig");
  1418. return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null);
  1419. }
  1420. $(document).ready(function() {
  1421. if(document.getElementById("treetydiviframe")){
  1422. //${contextPath}/zygl/gisiframe.html?model=commonTree
  1423. document.getElementById("treetydiviframe").src=contextPath+"/zygl/treeiframe.html?model=commonTree";
  1424. }
  1425. gis.script.init();
  1426. });