Main.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. MWF.xApplication.BaiduMap.contextRoot = "x_component_BaiduMap";
  2. MWF.xApplication.BaiduMap.Main = new Class({
  3. Extends: MWF.xApplication.Common.Main,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "name": "BaiduMap",
  8. "icon": "icon.png",
  9. "width": "1000",
  10. "height": "600",
  11. "isResize": true,
  12. "title": MWF.xApplication.BaiduMap.LP.title
  13. },
  14. onQueryLoad: function(){
  15. this.lp = MWF.xApplication.BaiduMap.LP;
  16. this.mapPageLoaded = false;
  17. this.windowLoaded = false;
  18. },
  19. createNode: function(){
  20. this.content.setStyle("overflow", "hidden");
  21. this.node = new Element("iframe", {
  22. "styles": this.css.contentNode,
  23. "border": 1,
  24. "frameBorder": "1",
  25. "marginHeight": 0,
  26. "marginHeight": 0,
  27. "src": "/"+MWF.xApplication.BaiduMap.contextRoot+"/$Main/map.html"
  28. }).inject(this.content);
  29. this.mapWindow = this.node.contentWindow;
  30. this.mapDocument = this.mapWindow.document;
  31. this.mapDocument.addEventListener("readystatechange", function(){
  32. if (this.mapDocument.readyState=="complete"){
  33. this.mapPageLoaded = true;
  34. this.loadApplicationContent();
  35. }
  36. }.bind(this));
  37. },
  38. loadApplication: function(callback){
  39. this.createNode();
  40. if (!this.options.isRefresh){
  41. this.maxSize(function(){
  42. this.windowLoaded = true;
  43. this.loadApplicationContent();
  44. if (callback) callback();
  45. }.bind(this));
  46. }else{
  47. window.setTimeout(function(){
  48. this.windowLoaded = true;
  49. this.loadApplicationContent();
  50. }.bind(this), 200);
  51. if (callback) callback();
  52. }
  53. },
  54. loadApplicationContent: function(){
  55. if (this.mapPageLoaded && this.windowLoaded){
  56. this.mapNode = this.mapDocument.getElementById("map");
  57. if (navigator.geolocation){
  58. navigator.geolocation.getCurrentPosition(this.loadMap.bind(this), this.loadMap.bind(this));
  59. }else{
  60. this.loadMap();
  61. }
  62. }
  63. },
  64. loadMap: function(position){
  65. var point = null;
  66. if (position && position.coords){
  67. point = new this.mapWindow.BMap.Point(position.coords.longitude, position.coords.latitude);
  68. }
  69. var map = new this.mapWindow.BMap.Map(this.mapNode); // 创建Map实例
  70. map.centerAndZoom(point, 12); // 初始化地图,设置中心点坐标和地图级别
  71. // map.centerAndZoom(new this.mapWindow.BMap.Point(116.404, 39.915), 11); // 初始化地图,设置中心点坐标和地图级别
  72. // map.addControl(new this.mapWindow.BMap.MapTypeControl()); //添加地图类型控件
  73. // map.setCurrentCity("北京"); // 设置地图显示的城市 此项是必须设置的
  74. map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
  75. }
  76. });