bmap.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <meta name="viewport" content="initial-scale=1.0, user-scalable=yes" />
  6. <link href="//api.map.baidu.com/library/IndoorMap/1.0/src/indoor.min.css?v=1.0.1 " rel="stylesheet" type="text/css">
  7. <style type="text/css">
  8. html, body {
  9. width: 100%;
  10. height: 100%;
  11. margin: 0;
  12. padding: 0;
  13. font-family:"微软雅黑";
  14. overflow: hidden;
  15. }
  16. #map {
  17. width: 100%;
  18. height: 500px;
  19. }
  20. p {
  21. margin-left:5px;
  22. font-size:14px;
  23. }
  24. </style>
  25. <script type="text/javascript" src="//api.map.baidu.com/api?v=3.0&ak=KMEhEKew3P5477ozjc5iivZw2Hek2rqL "></script>
  26. <script type="text/javascript" src="//api.map.baidu.com/library/IndoorMap/1.0/src/indoor.min.js?v=1.0.1 "></script>
  27. <title>根据buildingId设置室内图</title>
  28. </head>
  29. <body>
  30. <div id="map"></div>
  31. <div id="r-result">
  32. <input type="button" onclick="setBuildingId(buildingId1);" value="进入五彩城" />
  33. <input type="button" onclick="setIndoor(buildingId2, floor2);" value="进入大悦城2层" />
  34. <input type="button" onclick="getBuildingId();" value="返回当前室内图buildingId" />
  35. <input type="button" onclick="setFloor(floor2);" value="设置当前楼层" />
  36. </div>
  37. </body>
  38. </html>
  39. <script type="text/javascript">
  40. // 百度地图API功能
  41. var map = new BMap.Map("map"); // 创建Map实例
  42. map.centerAndZoom(new BMap.Point(120.200973,30.191684), 19); // 初始化地图,设置中心点坐标和地图级别
  43. // map.centerAndZoom(new BMap.Point(116.37929911149689,39.91696702642507), 19); // 初始化地图,设置中心点坐标和地图级别
  44. map.enableScrollWheelZoom(true); // 开启鼠标滚轮缩放
  45. var buildingId1 = 'e96b44200baa3b4082288acc'; // 五彩城
  46. var buildingId2 = 'a5ef680f2175daceb9df8f46'; // 西单大悦城
  47. var floor2 = 'F2';
  48. var getPoiInfoOptions = {
  49. // 根据uid获取poi信息接口完成回调函数,(适用于根据uid初始化页面、根据uid设置室内图及楼层、根据uid获取poi信息等方法)
  50. onRequestComplete: function (e) {
  51. console.log('onRequestComplete', e);
  52. alert(e.info.uid);
  53. },
  54. // 根据uid获取poi信息接口成功回调函数
  55. onRequestSuccess: function (e) {
  56. console.log('onRequestSuccess', e);
  57. },
  58. // 根据uid获取poi信息接口失败回调函数
  59. onRequestError: function (e) {
  60. console.log('onRequestError', e);
  61. }
  62. };
  63. // 创建室内图实例
  64. var indoorManager = new BMapLib.IndoorManager(map);
  65. // 设置室内图buildingId
  66. function setBuildingId(buildingId) {
  67. indoorManager.setBuildingId(buildingId, getPoiInfoOptions);
  68. }
  69. // 设置室内图buildingId和floor
  70. function setIndoor(buildingId, floor) {
  71. indoorManager.setIndoor(buildingId, floor, getPoiInfoOptions);
  72. }
  73. // 返回当前室内图buildingId
  74. function getBuildingId() {
  75. console.log(indoorManager.getBuildingId());
  76. }
  77. function setFloor (floor) {
  78. console.log('set floor',floor);
  79. // indoorManager.setFloor(floor);
  80. // indoorManager.hideBaseMap();
  81. // indoorManager.showBaseMap();
  82. }
  83. </script>