cityGeology.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**
  2. * @fileoverview 城市地质
  3. * @author Lei.Xu
  4. * @version 1.0.0
  5. */
  6. define([], function(tplLayout, addressSearchF, poiSearchF, regionSearchF, routeSearchF) {
  7. /**
  8. * 模块数据 用于数据存储和外部调用
  9. * @type {Object}
  10. * 数据存放
  11. */
  12. var modValue = {
  13. markerGroup: null, //marker容器
  14. markers: [], //marker记录
  15. citys: [[119.18,26.03],[118.34,24.55],[112.11,32.05],[126.37,45.44]],
  16. };
  17. /**
  18. * 模块状态,用于存储模块的状态 例如:收起,关闭
  19. * @type {Object}
  20. */
  21. var status = {
  22. initialized: false //是否初始化
  23. };
  24. /**
  25. * 初始化并订阅事件
  26. * @return {[type]} [description]
  27. */
  28. function init() {
  29. if (!status.initialized) {
  30. subscribe();
  31. status.initialized = true;
  32. modValue.markerGroup = map23DControl.group({
  33. action: 'add'
  34. });
  35. for(var i=0;i<modValue.citys.length;i++){
  36. addCitys(modValue.citys[i]);
  37. }
  38. //添加到我的图层
  39. var cityGuid = map23DControl.buildGuid('cityGeology');
  40. var layerOptions = {
  41. action: "add",
  42. DOM: {
  43. guid: cityGuid,
  44. type: '',
  45. name: '城市地质'
  46. },
  47. mod: ''
  48. }
  49. ONEMAP.M.myLayers.myLayerControl(layerOptions);
  50. ONEMAP.C.publisher.subscribe(layerAction, layerOptions.DOM.guid);
  51. $("#cityGeology").attr("layer",cityGuid);
  52. map2DViewer.map.setView([39,116],5);
  53. } else{
  54. removeAll();
  55. status.initialized = false;
  56. }
  57. };
  58. function addCitys(cityCoors){
  59. var markerId = map23DControl.marker({
  60. action: 'add',
  61. groupId: modValue.markerGroup,
  62. geojson: {
  63. "properties": {
  64. iconUrl: map23DConfig.map23DAssetsUrl + '/images/layout/marker/roadsign_icon_0.png',
  65. iconSize: [60, 39],
  66. iconAnchor: [29, 39],
  67. popupAnchor: [0, -39]
  68. },
  69. "geometry": {
  70. "type": "Point",
  71. "coordinates": [cityCoors[0],cityCoors[1]]
  72. }
  73. }
  74. });
  75. modValue.markers.push(markerId);
  76. map2DViewer.markers[markerId].on('click', function() {
  77. var iframeDom = $('<div class="main"><iframe src="'+onemapUrlConfig.geolink+'" id="myiframe" scrolling="yes" frameborder="0"></iframe><div class="bk">返回</div></div>');
  78. $("body").append(iframeDom)
  79. iframeDom.ready(function(){
  80. var at = setInterval(function(){
  81. var deptObjs= document.getElementById("myiframe").contentWindow.document.getElementById("north");
  82. var deptops= document.getElementById("myiframe").contentWindow.document.querySelectorAll(".layout-panel");
  83. deptObjs.style.display = "none";
  84. for(var i=0;i<deptops.length;i++){
  85. deptops[i].style.top = "0"
  86. }
  87. // console.log(deptObjs.style.display);
  88. // console.log(deptops.length);
  89. if(deptObjs.style.display=="none"){
  90. clearInterval(at);
  91. }
  92. },50)
  93. })
  94. $(".bk").bind("click",function(){
  95. $(".main").remove();
  96. })
  97. });
  98. }
  99. function getDom(){
  100. console.log("out getdom");
  101. }
  102. // 设置透明度
  103. function setOpacity(zid, opt) {
  104. map23DControl.tileLayer({
  105. action: 'update',
  106. guid: zid,
  107. layer: {
  108. opacity: opt
  109. }
  110. })
  111. }
  112. // 监听图层操作动作
  113. function layerAction(options) {
  114. if (options.action == "remove") {
  115. removeAll(options.guid);
  116. } else if (options.action == "opacity") {
  117. var opt = options.options.opacity;
  118. setOpacity(options.guid, opt);
  119. }
  120. }
  121. function removeAll(){
  122. map23DControl.group({
  123. action: 'cleanAll',
  124. guid: modValue.markerGroup
  125. })
  126. $("#cityGeology").removeClass('current');
  127. status.initialized = false;
  128. // map23DControl.marker({
  129. // action: 'remove',
  130. // guid: guid
  131. // })
  132. }
  133. /**
  134. * 注册监听
  135. * @type {Function}
  136. */
  137. function subscribe() {
  138. ONEMAP.C.publisher.subscribe(removeAll, 'cleanMap');
  139. };
  140. return ONEMAP.M.cityGeology = {
  141. init: init,
  142. removeAll: removeAll
  143. }
  144. })