GisShare.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. /**
  2. * Created by Administrator on 2017/12/25.
  3. */
  4. function postToIframeMethed(methedName, data, backFun) {
  5. // if(typeof(exec_obj)=='undefined'){
  6. // exec_obj = document.createElement('iframe');
  7. // exec_obj.name = 'tmp_frame';
  8. // exec_obj.src = 'http://139.196.105.31/HKGisShare/ZoomIn.html';
  9. // exec_obj.style.display = 'none';
  10. // document.body.appendChild(exec_obj);
  11. // }else{
  12. // exec_obj.src = 'http://139.196.105.31/HKGisShare/ZoomIn.html?' + Math.random();
  13. // }
  14. var win = document.getElementsByTagName('iframe')[0].contentWindow;
  15. // var obj = { name: 'Jack' };
  16. // 存入对象
  17. win.postMessage(JSON.stringify({method: methedName, data: data, backfun: backFun}), '*');
  18. // 读取对象
  19. // win.postMessage(JSON.stringify({key: 'storage', method: "get"}), "*");
  20. // window.onmessage = function(e) {
  21. // if (e.origin != 'http://localhost') return;
  22. // // "Jack"
  23. // console.log(JSON.parse(e.data).name);
  24. // };
  25. }
  26. window.onmessage = function (e) {
  27. //alert(e.origin);
  28. //if (e.origin !== 'http://10.101.35.46/WJGisShare/')
  29. //return;
  30. var payload;
  31. try {
  32. payload = JSON.parse(e.data);
  33. }
  34. catch (e) {
  35. return;
  36. }
  37. switch (payload.method) {
  38. case "clickLightAreaReturn":
  39. {
  40. clickLightAreaReturn(payload.data[0]);
  41. break;
  42. }
  43. case "clickWaterTankReturn":
  44. {
  45. clickWaterTankReturn(payload.data[0]);
  46. break;
  47. }
  48. case "moveInLightAreaReturn":
  49. {
  50. moveInLightAreaReturn(payload.data[0]);
  51. break;
  52. }
  53. case "moveOutLightAreaReturn":
  54. {
  55. moveOutLightAreaReturn(payload.data[0]);
  56. break;
  57. }
  58. case "moveOutDrawLayerReturn":
  59. {
  60. moveOutDrawLayerReturn(payload.data[0]);
  61. break;
  62. }
  63. case "moveInDrawLayerReturn":
  64. {
  65. moveInDrawLayerReturn(payload.data[0]);
  66. break;
  67. }
  68. case "clickDrawLayerReturn":
  69. {
  70. clickDrawLayerReturn(payload.data[0]);
  71. break;
  72. }
  73. case "clickWZXYFeatureReturn":{
  74. clickWZXYFeatureReturn(payload.data[0]);
  75. break;
  76. }
  77. case "doXyToStreetIdReturn":
  78. {
  79. doXyToStreetIdReturn(payload.data[0])
  80. break
  81. }
  82. case "popupClickReturn":
  83. {
  84. doPopupClickReturn(payload.data[0])
  85. break
  86. }
  87. case "closePopupReturn":
  88. {
  89. closePopupReturn(payload.data[0]);
  90. break
  91. }
  92. }
  93. };
  94. function ZoomIn(level) {
  95. postToIframeMethed("ZoomIn", level)
  96. }
  97. function ZoomOut(level) {
  98. postToIframeMethed("ZoomOut", level)
  99. }
  100. function Clear(type) {
  101. //var type = "drawLayer" // all drawLayer queryLayer chartLayer
  102. postToIframeMethed("Clear", type)
  103. }
  104. function ViewChange() {
  105. postToIframeMethed("ViewChange")
  106. }
  107. function fullExtent() {
  108. postToIframeMethed("fullExtent");
  109. }
  110. function doSetExtent(num) {
  111. postToIframeMethed("doSetExtent", num);
  112. }
  113. function measureSquare() {
  114. postToIframeMethed("measureSquare");
  115. }
  116. function measureLength() {
  117. postToIframeMethed("measureLength");
  118. }
  119. function downLoadPicture() {
  120. postToIframeMethed("downLoadPicture");
  121. }
  122. function doGetGraphicByJson(jsonStr, isGoTo) {
  123. postToIframeMethed("doGetGraphicByJson", [jsonStr, isGoTo]);
  124. }
  125. function doDeletePointById(id) {
  126. postToIframeMethed("doDeletePointById", [id]);
  127. }
  128. function doShowAreaName(type, fieldName, bool, size, color) {
  129. postToIframeMethed("doShowAreaName", [type, fieldName, bool, size, color]);
  130. }
  131. function drawSquare() {
  132. postToIframeMethed("drawSquare");
  133. }
  134. function query(Str, layerName) {
  135. postToIframeMethed("query", [Str, layerName]);
  136. }
  137. function queryByWhereStr(Str, layerName) {
  138. postToIframeMethed("queryByWhereStr", [Str, layerName]);
  139. }
  140. function doOpenFeatureLayer(layerId, layerVisible) {
  141. postToIframeMethed("openFeatureLayer", [layerId, layerVisible])
  142. }
  143. function doOpenFeatureLayerByName(layerName, layerVisible, whereStr) {
  144. postToIframeMethed("openFeatureLayerByName", [layerName, layerVisible, whereStr])
  145. }
  146. function doCloseChangeLayer() {
  147. postToIframeMethed("CloseChangeLayer", [])
  148. }
  149. function doOpenFeatureLayer0(layerVisible) {
  150. postToIframeMethed("openFeatureLayer0", [layerVisible])
  151. }
  152. function doOpenFeatureLayer1(layerVisible) {
  153. postToIframeMethed("openFeatureLayer1", [layerVisible])
  154. }
  155. function doOpenFeatureLayer2(layerVisible) {
  156. postToIframeMethed("openFeatureLayer2", [layerVisible])
  157. }
  158. function doOpenFeatureLayer3(layerVisible) {
  159. postToIframeMethed("openFeatureLayer3", [layerVisible])
  160. }
  161. function doOpenFeatureLayer4(layerVisible) {
  162. postToIframeMethed("openFeatureLayer4", [layerVisible])
  163. }
  164. function doOpenFeatureLayer5(layerVisible) {
  165. postToIframeMethed("openFeatureLayer5", [layerVisible])
  166. }
  167. function doOpenFeatureLayer6(layerVisible) {
  168. postToIframeMethed("openFeatureLayer6", [layerVisible])
  169. }
  170. function doOpenFeatureLayer7(layerVisible) {
  171. postToIframeMethed("openFeatureLayer7", [layerVisible])
  172. }
  173. function doOpenFeatureLayer8(layerVisible) {
  174. postToIframeMethed("openFeatureLayer8", [layerVisible])
  175. }
  176. function doOpenFeatureLayer9(layerVisible) {
  177. postToIframeMethed("openFeatureLayer9", [layerVisible])
  178. }
  179. function doOpenFeatureLayer10(layerVisible) {
  180. postToIframeMethed("openFeatureLayer10", [layerVisible])
  181. }
  182. function doFlashStatus(layerName) {
  183. postToIframeMethed("doFlashStatus", [layerName])
  184. }
  185. function setCenterExtentByPointR(x, y, radius) {
  186. postToIframeMethed("setCenterExtent", [x, y, radius])
  187. }
  188. function doDrawCircle(color) {
  189. postToIframeMethed("drawCircle", [color]);
  190. }
  191. function doQueryByCircle(layerName, picUrl, width, height) {
  192. postToIframeMethed("queryByCircle", [layerName, picUrl, width, height])
  193. }
  194. // 2019 12 by hm
  195. function doOnLocation(x, y, Attribute, ToolTip, ImgUrl, ImgWidth, ImgHeight) {
  196. postToIframeMethed("onLocation", [x, y, Attribute, ToolTip, ImgUrl, ImgWidth, ImgHeight]);
  197. }
  198. function doMeasureLengthByPoint(x, y, x1, y1, backFun) {
  199. postToIframeMethed("MeasureLengthByPoint", [x, y, x1, y1], backFun);
  200. }
  201. function doNewQuery(str, layerName, isgoto) {
  202. postToIframeMethed("newQuery", [str, layerName, isgoto]);
  203. }
  204. function doGridQuery(str, isgoto) {
  205. doNewQuery(str, "责任网格", isgoto);
  206. }
  207. function doOnLocationforGrid(x, y) {
  208. postToIframeMethed("onLocationforGrid", [x, y]);
  209. }
  210. function doOnLocationforAddress(x, y) {
  211. postToIframeMethed("onLocationforAddress", [x, y]);
  212. }
  213. function doOnQueryByPoint(x, y, layername, radius, isshow, isGoTo) {
  214. postToIframeMethed("onQueryByPoint", [x, y, layername, radius, isshow, isGoTo]);
  215. }
  216. function doOnQueryByGrid(grid, layername) {
  217. postToIframeMethed("onQueryByGrid", [grid, layername]);
  218. }
  219. function doOnMapCenter() {
  220. postToIframeMethed("onMapCenter");
  221. }
  222. function doOnMapLevel() {
  223. postToIframeMethed("onMapLevel");
  224. }
  225. function doOnMapSetCenter(x, y) {
  226. postToIframeMethed("onMapSetCenter", [x, y]);
  227. }
  228. function doOnGetXYbyAddress(str) {
  229. postToIframeMethed("onGetXYbyAddress", [str]);
  230. }
  231. function doOnSetInitExtentByStr(layername, streetname) {
  232. postToIframeMethed("onSetInitExtentByStr", [layername, streetname]);
  233. }
  234. function doOnQueryByCondition(str, layername, isShow, isGoTo) {
  235. postToIframeMethed("onQueryByCondition", [str, layername, isShow, isGoTo]);
  236. }
  237. function doOpenFeatureLayerByNameandWhere(layername, type, name, isGoTo, isOpen) {
  238. postToIframeMethed("openFeatureLayerByNameandWhere", [layername, type, name, isGoTo, isOpen]);
  239. }
  240. //2020 2 by hm
  241. function doOnClickLocation(Attribute, ToolTip, ImgUrl, ImgWidth, ImgHeight) {
  242. postToIframeMethed("onClickLocation", [Attribute, ToolTip, ImgUrl, ImgWidth, ImgHeight]);
  243. }
  244. //2020 4 by hm
  245. function doOnSetResizeType(type, radius, layername) {
  246. postToIframeMethed("onSetResizeType", [type, radius, layername]);
  247. }
  248. function doOnSetLayerCluster(layername, iscluster) {
  249. postToIframeMethed("onSetLayerCluster", [layername, iscluster]);
  250. }
  251. function doOnShowPolygonandText(jsonarr) {
  252. postToIframeMethed("onShowPolygonandText", [jsonarr]);
  253. }
  254. //2020 9 by hm
  255. function doOnLocationGetLatLon(color) {
  256. postToIframeMethed("onLocationGetLatLon", [color]);
  257. }
  258. function doOnDrawPolygonCircle() {
  259. postToIframeMethed("onDrawPolygonCircle");
  260. }
  261. function doOnDrawPolygonSquare() {
  262. postToIframeMethed("onDrawPolygonSquare");
  263. }
  264. function doOnLightArea(type, where, color, orderField) {
  265. postToIframeMethed("onLightArea", [type, where, color, orderField]);
  266. }
  267. function doEchartsRoute(dataArray, color, imgSrc, imgsize) {
  268. postToIframeMethed("onEchartsRoute", [dataArray, color, imgSrc, imgsize]);
  269. }
  270. function doWaterRouteClick(whereStr) {
  271. postToIframeMethed("doWaterRouteClick", [whereStr]);
  272. }
  273. function doPopupIn(popupInfoArray, hasX) {
  274. postToIframeMethed("onPopupIn", [popupInfoArray, hasX]);
  275. }
  276. function doClosePopupIn() {
  277. postToIframeMethed("onPopupClose");
  278. }
  279. function doCorrugatedPointByOid(list) {
  280. postToIframeMethed("doCorrugatedPointByOid", [list]);
  281. }
  282. function doClearCorrugatedPoint() {
  283. postToIframeMethed("doClearCorrugatedPoint", []);
  284. }
  285. function doXyToStreetId(x, y) {
  286. postToIframeMethed("doXyToStreetId", [x, y]);
  287. }
  288. function doGoToGraphic(type,graphic) {
  289. postToIframeMethed("goToGraphic", [type, graphic]);
  290. }
  291. function doGoToJZ(type,graphic,radius){
  292. postToIframeMethed("GoToJZ", [type, graphic,radius]);
  293. }
  294. function ShowBuildlayer(where){
  295. postToIframeMethed("ShowBuildlayer", [where]);
  296. }
  297. function switch2Dor3DMap(where) {
  298. postToIframeMethed("switch2Dor3DMap", [where]);
  299. }
  300. function ShowBuildlayerSX(where){
  301. postToIframeMethed("ShowBuildlayerSX", [where]);
  302. }
  303. function ResettingMap(){
  304. postToIframeMethed("ResettingMap", []);
  305. }
  306. function consoleXYZ(){
  307. postToIframeMethed("consoleXYZ", []);
  308. }
  309. function doClusterByJson(jsonArray) {
  310. postToIframeMethed("doClusterByJson", [jsonArray]);
  311. }
  312. ////////////////////////////////////////////////////////////////////////
  313. window.addEventListener('message', function (e) {
  314. var data;
  315. try {
  316. data = JSON.parse(e.data);
  317. }catch(err){
  318. data=e.data
  319. }
  320. switch (data.method) {
  321. case "measureLengthCallback":
  322. {
  323. measureLengthCallback(data.data[0]);
  324. break;
  325. }
  326. case "identifyTaskcallbackfun":
  327. {
  328. identifyTaskcallbackfun(data.data[0]);
  329. break;
  330. }
  331. case "maploadCallback":
  332. {
  333. maploadCallback();
  334. break;
  335. }
  336. case "addressdataCallback":
  337. {
  338. addressdataCallback(data.data[0]);
  339. break;
  340. }
  341. case "dragendCallback":
  342. {
  343. dragendCallback();
  344. break;
  345. }
  346. case "queryByGeometryAndLayer":
  347. {
  348. queryByGeometryAndLayer(data.data[0]);
  349. break;
  350. }
  351. case "mapCenterCallback":
  352. {
  353. mapCenterCallback(data.data[0]);
  354. break;
  355. }
  356. case "mapOnclickCallback":
  357. {
  358. mapOnclickCallback(data.data[0], data.data[1]);
  359. break;
  360. }
  361. case "mapLevelCallback":
  362. {
  363. mapLevelCallback(data.data[0]);
  364. break;
  365. }
  366. case "resizeCallback":
  367. {
  368. resizeCallback();
  369. break;
  370. }
  371. case "XYbyAddressCallback":
  372. {
  373. XYbyAddressCallback(data.data[0]);
  374. break;
  375. }
  376. case "mapAnimationInProgressCallback":
  377. {
  378. mapAnimationInProgressCallback();
  379. break;
  380. }
  381. case "mapDragingCallback":
  382. {
  383. mapDragingCallback();
  384. break;
  385. }
  386. case "clicklocationcallbackfun":
  387. {
  388. clicklocationcallback(data.data[0], data.data[1]);
  389. break;
  390. }
  391. case "onLocationGetLatLonbackfun":
  392. {
  393. onLocationGetLatLonbackfun(data.data[0]);
  394. break;
  395. }
  396. case "onDrawPolygoncallbackfun":
  397. {
  398. onDrawPolygoncallbackfun(data.data[0]);
  399. break;
  400. }
  401. }
  402. }, false);
  403. function measureLengthCallback(len) {
  404. console.log(len);
  405. }
  406. function identifyTaskcallbackfun(results) {
  407. console.log("网格编码=" + results);
  408. }
  409. function maploadCallback() {
  410. console.log("maploaded");
  411. }
  412. function addressdataCallback(address) {
  413. console.log(address);
  414. }
  415. function dragendCallback() {
  416. console.log("dragend");
  417. }
  418. function queryByGeometryAndLayer(data) {
  419. console.log(data);
  420. }
  421. function mapCenterCallback(data) {
  422. // alert(data);
  423. }
  424. function mapOnclickCallback(data, gridid) {
  425. alert(data + "网格编码=" + gridid);
  426. }
  427. function mapLevelCallback(data) {
  428. // alert(data);
  429. }
  430. function resizeCallback() {
  431. console.log("mapresize");
  432. }
  433. function XYbyAddressCallback(data) {
  434. // alert(data);
  435. console.log(data);
  436. }
  437. function mapAnimationInProgressCallback() {
  438. console.log("mapAnimationInProgressCallback");
  439. }
  440. function mapDragingCallback() {
  441. console.log("mapDragingCallback");
  442. }
  443. function clicklocationcallback(data, lonlat) {
  444. console.log(data);
  445. console.log(lonlat);
  446. }
  447. function onLocationGetLatLonbackfun(data) {
  448. console.log(data);
  449. }
  450. function onDrawPolygoncallbackfun(data) {
  451. console.log(data);
  452. }