gis.anchored.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. var gis = gis || {};
  2. gis.anchored = function() {
  3. };
  4. var framedCloud;
  5. gis.anchored.popup = function(lonlat,data){
  6. //alert(JSON.stringify(data));
  7. //alert(gis.anchored.tohtml(data));
  8. /*
  9. data={popupBorder:"1px solid #A5AAB4",width:320,height:155,title:"专题",
  10. style:["width:30%","text-align:center;"],
  11. data:[['港口名称','南京港'],['港区个数','2'],['锚地个数','2'],['作业区个数','16']]};
  12. */
  13. var chicken=$('#chicken');
  14. chicken.remove();
  15. data=gis.anchored.portinfo({portName:'南京港',portNumber:2,anchorageNumber:2,chanceNumber:16})
  16. var popup = new SuperMap.Popup.Anchored(
  17. "chicken",
  18. lonlat,
  19. new SuperMap.Size(data.width,data.height),
  20. gis.anchored.tohtml(data),
  21. null,
  22. true,
  23. null
  24. );
  25. popup.setBorder(data.popupBorder||"0px solid #A5AAB4");
  26. //popup.updateSize();
  27. //chicken_contentDiv
  28. popup.extdataheight=data.height;
  29. return popup;
  30. }
  31. /*
  32. * 弹出框显示,并且控制显示位置
  33. */
  34. gis.anchored.popupHtml = function(lonlat,data,toHtml,e){
  35. var chicken=$('#chicken');
  36. chicken.remove();
  37. var popup;
  38. if(e){
  39. //console.log("event",e);
  40. //e.clientX,e.clientY
  41. if(gis.script.isNum(e.clientX)&&gis.script.isNum(e.clientY)){
  42. //alert(treedivWidth);
  43. var twidth=treedivWidth||0;
  44. var clientx=e.clientX-twidth;
  45. var clienty=e.clientY;
  46. //alert((clientx+data.width+25)+"=="+$("#bgrounddiv").width())
  47. if((clienty+data.height+25)>$("#bgrounddiv").height()){
  48. //alert((clienty+data.height)+"--"+$("#bgrounddiv").height())
  49. if((clientx+data.width+25)>$("#bgrounddiv").width()){
  50. lonlat= map.getLonLatFromPixel(new SuperMap.Pixel(clientx-(data.width+32),clienty-(data.height)));
  51. toHtml=toHtml+'<div id="chicken_zxj" class="smPopupzxjBox" style="width: 20px; height: 24px; position: absolute;right:-19px;top:'+(data.height-28)+'px;"></div>';
  52. }else{
  53. lonlat= map.getLonLatFromPixel(new SuperMap.Pixel(clientx+20,clienty-(data.height)));
  54. toHtml=toHtml+'<div id="chicken_yxj" class="smPopupyxjBox" style="width: 20px; height: 24px; position: absolute;left:-19px;top:'+(data.height-28)+'px;"></div>';
  55. }
  56. }else{
  57. if((clientx+data.width+25)>$("#bgrounddiv").width()){
  58. lonlat= map.getLonLatFromPixel(new SuperMap.Pixel(clientx-(data.width+32),clienty-28));
  59. toHtml=toHtml+'<div id="chicken_zsj" class="smPopupzsjBox" style="width: 20px; height: 24px; position: absolute;right:-19px;top:28px;"></div>';
  60. }else{
  61. lonlat= map.getLonLatFromPixel(new SuperMap.Pixel(clientx+20,clienty-28));
  62. toHtml=toHtml+'<div id="chicken_ysj" class="smPopupysjBox" style="width: 20px; height: 24px; position: absolute;left:-19px;top:28px;"></div>';
  63. }
  64. }
  65. popup = new SuperMap.Popup(
  66. "chicken",
  67. lonlat,
  68. new SuperMap.Size(data.width,data.height),
  69. toHtml,
  70. true,
  71. null
  72. );
  73. /*
  74. lonlat= map.getLonLatFromPixel(new SuperMap.Pixel(e.clientX-twidth+20,e.clientY-28));
  75. toHtml=toHtml+'<div id="chicken_ysj" class="smPopupysjBox" style="width: 20px; height: 24px; position: absolute;left:-20px;top: 28px;"></div>'
  76. var popup = new SuperMap.Popup(
  77. "chicken",
  78. lonlat,
  79. new SuperMap.Size(data.width,data.height),
  80. toHtml,
  81. true,
  82. null
  83. );
  84. */
  85. }
  86. }/*else{
  87. popup = new SuperMap.Popup.Anchored(
  88. "chicken",
  89. lonlat,
  90. new SuperMap.Size(data.width,data.height),
  91. toHtml,
  92. null,
  93. true,
  94. null
  95. );
  96. }*/
  97. if(!popup){
  98. popup = new SuperMap.Popup.Anchored(
  99. "chicken",
  100. lonlat,
  101. new SuperMap.Size(data.width,data.height),
  102. toHtml,
  103. null,
  104. true,
  105. null
  106. );
  107. }
  108. popup.setBorder(data.popupBorder||"1px solid #A5AAB4");
  109. //popup.updateSize();
  110. //chicken_contentDiv
  111. popup.extdataheight=data.height;
  112. return popup;
  113. }
  114. /*
  115. * 根据参数设置弹出框,以及显示数据的(表格)样式
  116. */
  117. gis.anchored.addPopup = function(map,popup,feature){
  118. map.addPopup(popup);
  119. //$('#chicken_close').css("display","none");
  120. var contentDiv=$('#chicken_contentDiv');
  121. //alert($('#chicken_GroupDiv').width());//overflow:visible
  122. contentDiv.css("overflow","visible");
  123. //contentDiv.css("position","absolute");
  124. //contentDiv.css("border","1px solid #A5AAB4");
  125. contentDiv.css("width",$('#chicken_GroupDiv').width());//alert(contentDiv.width());
  126. //alert(contentDiv.width()+"**"+$('#chicken_GroupDiv').width());
  127. var tableDiv=$('.tabledivClass');
  128. //alert($('.titleClass').height());
  129. //tableDiv.css("height",tableDiv.height());
  130. tableDiv.css("height",popup.extdataheight-26);
  131. //tableDiv.css("width",contentDiv.width());
  132. /*
  133. if($.support&&$.support.leadingWhitespace&&contentDiv.width()==$('#chicken_GroupDiv').width()){
  134. contentDiv.css("width",$('#chicken_GroupDiv').width()-12);
  135. //tableDiv.css("height",tableDiv.height()-26);
  136. }
  137. */
  138. $('.smPopupCloseBox').css("top",5);
  139. $('.smPopupCloseBox').css("right",5);
  140. /*
  141. $.each($(".altrowstable"), function(i,val){
  142. gis.anchored.tableBeautify.call(this,"#fff","#F5F5F5","#FFFFCC")
  143. });
  144. */
  145. if(feature
  146. &&gis.script.isNotBlank(feature.attributes.labelfieldid)){
  147. var titleName=feature.attributes[feature.attributes.labelfieldid];
  148. var titleClassDiv=$('.titleClass');
  149. if(titleClassDiv&&!gis.script.isBlank(titleName)){
  150. titleClassDiv.html(gis.anchored.titleEllipsis(titleName,20));
  151. }
  152. }
  153. /*
  154. if(feature
  155. &&gis.script.isNotBlank(feature.attributes.labelfieldid)
  156. &&gis.script.isNotBlank(feature.attributes[feature.attributes.labelfieldid])){
  157. //console.log("feature",feature);
  158. var titleClassDiv=$('.titleClass');
  159. titleClassDiv.html(feature.attributes[feature.attributes.labelfieldid]);
  160. }
  161. */
  162. $.each($(".altrowstable"), function(i,val){
  163. gis.anchored.tableBeautify2.call(this);
  164. });
  165. }
  166. gis.anchored.titleEllipsis = function(tname,tlength){
  167. try{
  168. if(!gis.script.isBlank(tname)&&gis.script.isNum(tlength)&&tname.length
  169. &&tlength>0&&tname.length>tlength){
  170. tname=tname.substring(0,tlength)+'...';
  171. }
  172. }catch(e){}
  173. return tname;
  174. }
  175. /*
  176. *
  177. */
  178. gis.anchored.addFramedCloud = function(lonlat,size,contentHTML){
  179. if(framedCloud){
  180. try{
  181. framedCloud.hide();
  182. framedCloud.destroy();
  183. }
  184. catch(e){}
  185. }
  186. //初始化FramedCloud类
  187. framedCloud = new SuperMap.Popup.FramedCloud(
  188. "chicken",
  189. lonlat,
  190. size,
  191. contentHTML,
  192. null,
  193. true,
  194. null,
  195. true
  196. );
  197. map.addPopup(framedCloud);
  198. var contentDiv=$('#chicken_contentDiv');
  199. //alert($('#chicken_GroupDiv').width());//overflow:visible
  200. contentDiv.css("overflow","visible");
  201. //contentDiv.css("position","absolute");
  202. //contentDiv.css("border","1px solid #A5AAB4");
  203. contentDiv.css("width",$('#chicken_GroupDiv').width());//alert(contentDiv.width());
  204. //alert(contentDiv.width()+"**"+$('#chicken_GroupDiv').width());
  205. /*
  206. var tabledivClass=$('.tabledivClass');
  207. tabledivClass.css("width",tabledivClass.width()-1);
  208. tabledivClass.css("height",222);
  209. */
  210. //var tableDiv=$('.titleClass');
  211. //tableDiv.css("width",tableDiv.width()-10);
  212. var smFramedCloudPopupContent=$('.smFramedCloudPopupContent');
  213. smFramedCloudPopupContent.css("padding","0");
  214. $('.smPopupCloseBox').css("top",4);
  215. $('.smPopupCloseBox').css("right",5);
  216. }
  217. /*
  218. * 显示数据的(表格)样式
  219. */
  220. gis.anchored.tableBeautify = function(oddColor,evenColor,ouseoverColor){
  221. //alert(this);return;
  222. if(this){
  223. //var tr=this.getElementsByTagName("tr");
  224. for(var i=0;i<this.rows.length;i++){
  225. var temptr=this.rows[i];
  226. if(i%2==0){
  227. temptr.style.backgroundColor=oddColor;
  228. /*
  229. if(i==0){
  230. continue;
  231. }
  232. */
  233. //鼠标离开
  234. temptr.onmouseout=function(){
  235. this.style.backgroundColor=oddColor;
  236. }
  237. }else{
  238. temptr.style.backgroundColor=evenColor;
  239. //鼠标离开
  240. temptr.onmouseout=function(){
  241. this.style.backgroundColor=evenColor;
  242. }
  243. }
  244. //鼠标进入
  245. temptr.onmouseover=function(){
  246. //alert(this.style.backgroundColor+"-->"+ouseoverColor);
  247. this.style.backgroundColor=ouseoverColor;
  248. }
  249. /*
  250. temptr.onclick=function(){
  251. //alert(this.sectionRowIndex);
  252. }
  253. */
  254. var tagName_td=temptr.getElementsByTagName("td");
  255. if(tagName_td){
  256. var presentColsAmount=temptr.getElementsByTagName("td").length;
  257. if(presentColsAmount&&presentColsAmount>=4){
  258. for(var cc=1;cc<presentColsAmount;cc++){
  259. //alert(tagName_td[cc]);
  260. //$(tagName_td[cc]).css("color","red");
  261. $(tagName_td[cc]).css("border-left","1px solid #A5AAB4");
  262. }
  263. }
  264. }
  265. }
  266. }
  267. }
  268. /*
  269. * 显示数据的(表格)样式2
  270. */
  271. gis.anchored.tableBeautify2 = function(){
  272. //alert(this);return;
  273. if(this){
  274. //var tr=this.getElementsByTagName("tr");
  275. //$(this).css("frame","void");
  276. for(var i=0;i<this.rows.length;i++){
  277. var temptr=this.rows[i];
  278. var tagName_td=temptr.getElementsByTagName("td");
  279. if(tagName_td){
  280. var presentColsAmount=temptr.getElementsByTagName("td").length;
  281. if(presentColsAmount){
  282. for(var cc=0;cc<presentColsAmount;cc++){
  283. if(cc==0){
  284. $(tagName_td[cc]).css("border-left","0");
  285. }
  286. if(cc==presentColsAmount-1){
  287. $(tagName_td[cc]).css("border-right","0");
  288. }
  289. if(i==this.rows.length-1){
  290. $(tagName_td[cc]).css("border-bottom","0");
  291. }
  292. if(cc%2==0){
  293. //temptr.style.backgroundColor=oddColor;
  294. //
  295. //alert($(tagName_td[cc]).html());
  296. $(tagName_td[cc]).css("backgroundColor","#e6eff9");
  297. //$(tagName_td[cc]).css("text-align","right");
  298. $(tagName_td[cc]).css("color","#185f8a");
  299. // text-align: right;//color: #185f8a;
  300. if(gis.script.isNotBlank($(tagName_td[cc]).html())){
  301. $(tagName_td[cc]).html($(tagName_td[cc]).html()+":");
  302. }
  303. }
  304. $(tagName_td[cc]).css("text-align","left");
  305. }
  306. }
  307. }
  308. }
  309. }
  310. }
  311. gis.anchored.tohtml = function(data){
  312. //alert(JSON.stringify(data));
  313. //$("<div id='popupWin'></div>").addClass("popupWindow").appendTo($("#result"));
  314. var html=new Array();
  315. var nvlval='';
  316. if(data){
  317. if(data.title){
  318. html.push("<div class='titleClass'>");
  319. html.push(data.title);
  320. html.push("</div>");
  321. }
  322. if(data.data){
  323. //html.push("<div class='tableClass' style='width: 335px; height: 115px; position: relative;border:1px solid #A5AAB4;overflow:auto;'>");
  324. html.push("<div class='tabledivClass'>");
  325. //html.push(data.title);html.push("<br>");
  326. html.push("<table class='altrowstable'>");
  327. for(var i=0;i<data.data.length;i++){
  328. var o=data.data[i];
  329. html.push("<tr>");
  330. for(var j=0;j<o.length;j++){
  331. html.push("<td style='"+(data.style[j]||nvlval)+"'>");
  332. html.push(o[j]);
  333. html.push("</td>");
  334. }
  335. html.push("</tr>");
  336. }
  337. html.push("</table>");
  338. html.push("</div>");
  339. }
  340. }
  341. //alert(html.join(""));
  342. return html.join("");
  343. }
  344. gis.anchored.portinfo = function(data){
  345. var obj={popupBorder:"1px solid #A5AAB4",width:320,height:152,title:"港口信息",
  346. style:["width:30%","text-align:center;"],
  347. data:[['港口名称',data.portName],['港区个数',data.portNumber],['锚地个数',data.anchorageNumber],['作业区个数',data.chanceNumber]]};
  348. return obj;
  349. }
  350. gis.anchored.nvlinfo = function(data){
  351. var obj={popupBorder:"1px solid #A5AAB4",width:320,height:155,title:data.poptitle,
  352. style:["width:30%","text-align:center;"],
  353. data:[['名称',data.portName]]};
  354. return obj;
  355. }
  356. $(document).ready(function() {
  357. });