GisShare.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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 "clickApparitorFeatureReturn":{
  78. clickApparitorFeatureReturn(payload.data[0])
  79. break;
  80. }
  81. case "doXyToStreetIdReturn":
  82. {
  83. doXyToStreetIdReturn(payload.data[0])
  84. break
  85. }
  86. case "popupClickReturn":
  87. {
  88. doPopupClickReturn(payload.data[0])
  89. break
  90. }
  91. case "closePopupReturn":
  92. {
  93. closePopupReturn(payload.data[0]);
  94. break
  95. }
  96. }
  97. };
  98. function ZoomIn(level) {
  99. postToIframeMethed("ZoomIn", level)
  100. }
  101. function ChangerExtent(xmax,xmin,ymax,ymin) {
  102. postToIframeMethed("ChangerExtent", [xmax,xmin,ymax,ymin])
  103. }
  104. function ZoomOut(level) {
  105. postToIframeMethed("ZoomOut", level)
  106. }
  107. function Clear(type) {
  108. //var type = "drawLayer" // all drawLayer queryLayer chartLayer
  109. postToIframeMethed("Clear", type)
  110. }
  111. function ViewChange() {
  112. postToIframeMethed("ViewChange")
  113. }
  114. function fullExtent() {
  115. postToIframeMethed("fullExtent");
  116. }
  117. function doSetExtent(num) {
  118. postToIframeMethed("doSetExtent", num);
  119. }
  120. function measureSquare() {
  121. postToIframeMethed("measureSquare");
  122. }
  123. function measureLength() {
  124. postToIframeMethed("measureLength");
  125. }
  126. function downLoadPicture() {
  127. postToIframeMethed("downLoadPicture");
  128. }
  129. function doGetGraphicByJson(jsonStr, isGoTo) {
  130. postToIframeMethed("doGetGraphicByJson", [jsonStr, isGoTo]);
  131. }
  132. function doDeletePointById(id) {
  133. postToIframeMethed("doDeletePointById", [id]);
  134. }
  135. function doShowAreaName(type, fieldName, bool, size, color) {
  136. postToIframeMethed("doShowAreaName", [type, fieldName, bool, size, color]);
  137. }
  138. function drawSquare() {
  139. postToIframeMethed("drawSquare");
  140. }
  141. function query(Str, layerName) {
  142. postToIframeMethed("query", [Str, layerName]);
  143. }
  144. function queryByWhereStr(Str, layerName) {
  145. postToIframeMethed("queryByWhereStr", [Str, layerName]);
  146. }
  147. function doOpenFeatureLayer(layerId, layerVisible) {
  148. postToIframeMethed("openFeatureLayer", [layerId, layerVisible])
  149. }
  150. function doOpenFeatureLayerByName(layerName, layerVisible, whereStr) {
  151. postToIframeMethed("openFeatureLayerByName", [layerName, layerVisible, whereStr])
  152. }
  153. function doCloseChangeLayer() {
  154. postToIframeMethed("CloseChangeLayer", [])
  155. }
  156. function doOpenFeatureLayer0(layerVisible) {
  157. postToIframeMethed("openFeatureLayer0", [layerVisible])
  158. }
  159. function doOpenFeatureLayer1(layerVisible) {
  160. postToIframeMethed("openFeatureLayer1", [layerVisible])
  161. }
  162. function doOpenFeatureLayer2(layerVisible) {
  163. postToIframeMethed("openFeatureLayer2", [layerVisible])
  164. }
  165. function doOpenFeatureLayer3(layerVisible) {
  166. postToIframeMethed("openFeatureLayer3", [layerVisible])
  167. }
  168. function doOpenFeatureLayer4(layerVisible) {
  169. postToIframeMethed("openFeatureLayer4", [layerVisible])
  170. }
  171. function doOpenFeatureLayer5(layerVisible) {
  172. postToIframeMethed("openFeatureLayer5", [layerVisible])
  173. }
  174. function doOpenFeatureLayer6(layerVisible) {
  175. postToIframeMethed("openFeatureLayer6", [layerVisible])
  176. }
  177. function doOpenFeatureLayer7(layerVisible) {
  178. postToIframeMethed("openFeatureLayer7", [layerVisible])
  179. }
  180. function doOpenFeatureLayer8(layerVisible) {
  181. postToIframeMethed("openFeatureLayer8", [layerVisible])
  182. }
  183. function doOpenFeatureLayer9(layerVisible) {
  184. postToIframeMethed("openFeatureLayer9", [layerVisible])
  185. }
  186. function doOpenFeatureLayer10(layerVisible) {
  187. postToIframeMethed("openFeatureLayer10", [layerVisible])
  188. }
  189. function doFlashStatus(layerName) {
  190. postToIframeMethed("doFlashStatus", [layerName])
  191. }
  192. function setCenterExtentByPointR(x, y, radius) {
  193. postToIframeMethed("setCenterExtent", [x, y, radius])
  194. }
  195. function doDrawCircle(color) {
  196. postToIframeMethed("drawCircle", [color]);
  197. }
  198. function doQueryByCircle(layerName, picUrl, width, height) {
  199. postToIframeMethed("queryByCircle", [layerName, picUrl, width, height])
  200. }
  201. // 2019 12 by hm
  202. function doOnLocation(x, y, Attribute, ToolTip, ImgUrl, ImgWidth, ImgHeight) {
  203. postToIframeMethed("onLocation", [x, y, Attribute, ToolTip, ImgUrl, ImgWidth, ImgHeight]);
  204. }
  205. function doMeasureLengthByPoint(x, y, x1, y1, backFun) {
  206. postToIframeMethed("MeasureLengthByPoint", [x, y, x1, y1], backFun);
  207. }
  208. function doNewQuery(str, layerName, isgoto) {
  209. postToIframeMethed("newQuery", [str, layerName, isgoto]);
  210. }
  211. function doGridQuery(str, isgoto) {
  212. doNewQuery(str, "责任网格", isgoto);
  213. }
  214. function doOnLocationforGrid(x, y) {
  215. postToIframeMethed("onLocationforGrid", [x, y]);
  216. }
  217. function doOnLocationforAddress(x, y) {
  218. postToIframeMethed("onLocationforAddress", [x, y]);
  219. }
  220. function doOnQueryByPoint(x, y, layername, radius, isshow, isGoTo) {
  221. postToIframeMethed("onQueryByPoint", [x, y, layername, radius, isshow, isGoTo]);
  222. }
  223. function doOnQueryByGrid(grid, layername) {
  224. postToIframeMethed("onQueryByGrid", [grid, layername]);
  225. }
  226. function doOnMapCenter() {
  227. postToIframeMethed("onMapCenter");
  228. }
  229. function doOnMapLevel() {
  230. postToIframeMethed("onMapLevel");
  231. }
  232. function doOnMapSetCenter(x, y) {
  233. postToIframeMethed("onMapSetCenter", [x, y]);
  234. }
  235. function doOnMapSetCenter3D(x, y,z,tilt,heading) {
  236. postToIframeMethed("onMapSetCenter3D", [x, y,z,tilt,heading]);
  237. }
  238. function HeatMap(type) {
  239. postToIframeMethed("HeatMap", [type]);
  240. }
  241. function doOnGetXYbyAddress(str) {
  242. postToIframeMethed("onGetXYbyAddress", [str]);
  243. }
  244. function doOnSetInitExtentByStr(layername, streetname) {
  245. postToIframeMethed("onSetInitExtentByStr", [layername, streetname]);
  246. }
  247. function doOnQueryByCondition(str, layername, isShow, isGoTo) {
  248. postToIframeMethed("onQueryByCondition", [str, layername, isShow, isGoTo]);
  249. }
  250. function doOpenFeatureLayerByNameandWhere(layername, type, name, isGoTo, isOpen) {
  251. postToIframeMethed("openFeatureLayerByNameandWhere", [layername, type, name, isGoTo, isOpen]);
  252. }
  253. //2020 2 by hm
  254. function doOnClickLocation(Attribute, ToolTip, ImgUrl, ImgWidth, ImgHeight) {
  255. postToIframeMethed("onClickLocation", [Attribute, ToolTip, ImgUrl, ImgWidth, ImgHeight]);
  256. }
  257. //2020 4 by hm
  258. function doOnSetResizeType(type, radius, layername) {
  259. postToIframeMethed("onSetResizeType", [type, radius, layername]);
  260. }
  261. function doOnSetLayerCluster(layername, iscluster) {
  262. postToIframeMethed("onSetLayerCluster", [layername, iscluster]);
  263. }
  264. function doOnShowPolygonandText(jsonarr) {
  265. postToIframeMethed("onShowPolygonandText", [jsonarr]);
  266. }
  267. //2020 9 by hm
  268. function doOnLocationGetLatLon(color) {
  269. postToIframeMethed("onLocationGetLatLon", [color]);
  270. }
  271. function doOnDrawPolygonCircle() {
  272. postToIframeMethed("onDrawPolygonCircle");
  273. }
  274. function doOnDrawPolygonSquare() {
  275. postToIframeMethed("onDrawPolygonSquare");
  276. }
  277. function doOnLightArea(type, where, color, orderField) {
  278. postToIframeMethed("onLightArea", [type, where, color, orderField]);
  279. }
  280. function doEchartsRoute(dataArray, color, imgSrc, imgsize) {
  281. postToIframeMethed("onEchartsRoute", [dataArray, color, imgSrc, imgsize]);
  282. }
  283. function doWaterRouteClick(whereStr) {
  284. postToIframeMethed("doWaterRouteClick", [whereStr]);
  285. }
  286. function doPopupIn(popupInfoArray, hasX) {
  287. postToIframeMethed("onPopupIn", [popupInfoArray, hasX]);
  288. }
  289. function doClosePopupIn() {
  290. postToIframeMethed("onPopupClose");
  291. }
  292. function doCorrugatedPointByOid(list) {
  293. postToIframeMethed("doCorrugatedPointByOid", [list]);
  294. }
  295. function doClearCorrugatedPoint() {
  296. postToIframeMethed("doClearCorrugatedPoint", []);
  297. }
  298. function doXyToStreetId(x, y) {
  299. postToIframeMethed("doXyToStreetId", [x, y]);
  300. }
  301. function doGoToGraphic(type,graphic) {
  302. postToIframeMethed("goToGraphic", [type, graphic]);
  303. }
  304. function doGoToJZ(type,graphic,radius){
  305. postToIframeMethed("GoToJZ", [type, graphic,radius]);
  306. }
  307. function ShowBuildlayer(where){
  308. postToIframeMethed("ShowBuildlayer", [where]);
  309. }
  310. function switch2Dor3DMap(where) {
  311. postToIframeMethed("switch2Dor3DMap", [where]);
  312. }
  313. function ShowBuildlayerSX(where){
  314. postToIframeMethed("ShowBuildlayerSX", [where]);
  315. }
  316. function ResettingMap(){
  317. postToIframeMethed("ResettingMap", []);
  318. }
  319. function consoleXYZ(){
  320. postToIframeMethed("consoleXYZ", []);
  321. }
  322. ////////////////////////////////////////////////////////////////////////
  323. window.addEventListener('message', function (e) {
  324. var data;
  325. try {
  326. data = JSON.parse(e.data);
  327. }catch(err){
  328. data=e.data
  329. }
  330. switch (data.method) {
  331. case "measureLengthCallback":
  332. {
  333. measureLengthCallback(data.data[0]);
  334. break;
  335. }
  336. case "identifyTaskcallbackfun":
  337. {
  338. identifyTaskcallbackfun(data.data[0]);
  339. break;
  340. }
  341. case "maploadCallback":
  342. {
  343. maploadCallback();
  344. break;
  345. }
  346. case "addressdataCallback":
  347. {
  348. addressdataCallback(data.data[0]);
  349. break;
  350. }
  351. case "dragendCallback":
  352. {
  353. dragendCallback();
  354. break;
  355. }
  356. case "queryByGeometryAndLayer":
  357. {
  358. queryByGeometryAndLayer(data.data[0]);
  359. break;
  360. }
  361. case "mapCenterCallback":
  362. {
  363. mapCenterCallback(data.data[0]);
  364. break;
  365. }
  366. case "mapOnclickCallback":
  367. {
  368. mapOnclickCallback(data.data[0], data.data[1]);
  369. break;
  370. }
  371. case "mapLevelCallback":
  372. {
  373. mapLevelCallback(data.data[0]);
  374. break;
  375. }
  376. case "resizeCallback":
  377. {
  378. resizeCallback();
  379. break;
  380. }
  381. case "XYbyAddressCallback":
  382. {
  383. XYbyAddressCallback(data.data[0]);
  384. break;
  385. }
  386. case "mapAnimationInProgressCallback":
  387. {
  388. mapAnimationInProgressCallback();
  389. break;
  390. }
  391. case "mapDragingCallback":
  392. {
  393. mapDragingCallback();
  394. break;
  395. }
  396. case "clicklocationcallbackfun":
  397. {
  398. clicklocationcallback(data.data[0], data.data[1]);
  399. break;
  400. }
  401. case "onLocationGetLatLonbackfun":
  402. {
  403. onLocationGetLatLonbackfun(data.data[0]);
  404. break;
  405. }
  406. case "onDrawPolygoncallbackfun":
  407. {
  408. onDrawPolygoncallbackfun(data.data[0]);
  409. break;
  410. }
  411. }
  412. }, false);
  413. function measureLengthCallback(len) {
  414. console.log(len);
  415. }
  416. function identifyTaskcallbackfun(results) {
  417. console.log("网格编码=" + results);
  418. }
  419. function maploadCallback() {
  420. console.log("maploaded");
  421. }
  422. function addressdataCallback(address) {
  423. console.log(address);
  424. }
  425. function doClusterByJson(jsonArray,img) {
  426. postToIframeMethed("doClusterByJson", [jsonArray,img]);
  427. }
  428. function dragendCallback() {
  429. console.log("dragend");
  430. }
  431. function queryByGeometryAndLayer(data) {
  432. console.log(data);
  433. }
  434. function mapCenterCallback(data) {
  435. // alert(data);
  436. }
  437. function mapOnclickCallback(data, gridid) {
  438. alert(data + "网格编码=" + gridid);
  439. }
  440. function mapLevelCallback(data) {
  441. // alert(data);
  442. }
  443. function resizeCallback() {
  444. console.log("mapresize");
  445. }
  446. function XYbyAddressCallback(data) {
  447. // alert(data);
  448. console.log(data);
  449. }
  450. function mapAnimationInProgressCallback() {
  451. console.log("mapAnimationInProgressCallback");
  452. }
  453. function mapDragingCallback() {
  454. console.log("mapDragingCallback");
  455. }
  456. function clicklocationcallback(data, lonlat) {
  457. console.log(data);
  458. console.log(lonlat);
  459. }
  460. function onLocationGetLatLonbackfun(data) {
  461. console.log(data);
  462. }
  463. function onDrawPolygoncallbackfun(data) {
  464. console.log(data);
  465. }