mapCommon.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. var flexElement;
  2. /**
  3. * 功能:页面加载时执行此方法
  4. * @return flexElement
  5. */
  6. function init(){
  7. //var f = parent.frmMainChild.document.getElementsByTagName("object")[0].id;
  8. //getmapSWF(f);//选择对象
  9. getmapSWF();
  10. }
  11. /**
  12. * 功能:地图标注相关方法
  13. * iframe中调用
  14. */
  15. function getmapSWF() {
  16. if (navigator.appName.indexOf("Microsoft") != -1) {
  17. flexElement = parent.frmMainChild.document.getElementById('FlexProject');
  18. }else{
  19. flexElement = parent.frmMainChild.document.getElementsByTagName("embed")[0];
  20. }
  21. wheel(flexElement,afterwheel,true);
  22. }
  23. /**
  24. * 获取用于标注地图的对象
  25. * 父页面调用
  26. */
  27. function getSWF() {
  28. if (navigator.appName.indexOf("Microsoft") != -1) {
  29. flexElement = document.getElementById("frmMainChild").contentWindow.document.getElementById('FlexProject');
  30. }else{
  31. flexElement = document.getElementById("frmMainChild").contentWindow.document.getElementsByTagName("embed")[0];
  32. }
  33. wheel(flexElement,afterwheel,true);
  34. return flexElement;
  35. }
  36. /**
  37. * 鼠标滚轮定点放大的方法
  38. * @param obj
  39. * @param fn
  40. * @param useCapture
  41. * @return
  42. */
  43. function wheel(obj, fn ,useCapture){
  44. var mousewheelevt=(/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel" ;
  45. //FF doesn't recognize mousewheel as of FF3.x
  46. if (obj.attachEvent) //if IE (and Opera depending on user setting)
  47. obj.attachEvent("on"+mousewheelevt, handler, useCapture);
  48. else if (obj.addEventListener) //WC3 browsers
  49. obj.addEventListener(mousewheelevt, handler, useCapture);
  50. function handler(event) {
  51. var delta = 0;
  52. var event = window.event || event ;
  53. var delta = event.detail ? -event.detail/3 : event.wheelDelta/120;
  54. if (event.preventDefault)
  55. event.preventDefault();
  56. event.returnValue = false;
  57. return fn.apply(obj, [event, delta,obj]);
  58. }
  59. }
  60. function afterwheel(event, delta,obj){
  61. //这个是FLEX里写的放大缩小方法
  62. obj.WheelScroll(delta);
  63. }
  64. function changeLayers(layerI){
  65. // alert(layerI);
  66. if(layerI==1){
  67. map.style.backgroundImage = "url(\"/nwyj/page/bin-release/assets/images/mapbg.jpg\")";
  68. }else {
  69. map.style.backgroundImage = "";
  70. }
  71. }