baidumap.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. //
  5. // 初始化表格参数配置
  6. Table.api.init({
  7. extend: {
  8. index_url: 'example/baidumap/index',
  9. add_url: 'example/baidumap/add',
  10. edit_url: 'example/baidumap/edit',
  11. del_url: 'example/baidumap/del',
  12. multi_url: 'example/baidumap/multi',
  13. table: '',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'id',
  22. columns: [
  23. [
  24. {checkbox: true},
  25. {field: 'id', title: 'ID', operate: false},
  26. {field: 'admin_id', title: __('Admin_id'), visible: false, operate: false},
  27. {field: 'username', title: __('Username'), formatter: Table.api.formatter.search},
  28. {field: 'title', title: __('Title')},
  29. {field: 'url', title: __('Url'), align: 'left'},
  30. {field: 'ip', title: __('IP')},
  31. {field: 'createtime', title: __('Create time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  32. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  33. ]
  34. ]
  35. });
  36. // 为表格绑定事件
  37. Table.api.bindevent(table);
  38. },
  39. add: function () {
  40. Controller.api.bindevent();
  41. },
  42. edit: function () {
  43. Controller.api.bindevent();
  44. },
  45. map: function () {
  46. Form.api.bindevent($("form[role=form]"));
  47. require(['async!BMap'], function () {
  48. // 更多文档可参考 http://lbsyun.baidu.com/jsdemo.htm
  49. // 百度地图API功能
  50. var map = new BMap.Map("allmap");
  51. var point = new BMap.Point(116.404, 39.915);
  52. map.centerAndZoom(point, 13); //设置中心坐标点和级别
  53. var marker = new BMap.Marker(point); // 创建标注
  54. map.addOverlay(marker); // 将标注添加到地图中
  55. marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
  56. map.enableDragging(); //开启拖拽
  57. //map.enableInertialDragging(); //开启惯性拖拽
  58. map.enableScrollWheelZoom(true); //是否允许缩放
  59. //map.centerAndZoom("上海",15); //根据城市名设定地图中心点
  60. var geolocation = new BMap.Geolocation();
  61. geolocation.getCurrentPosition(function (r) {
  62. if (this.getStatus() == BMAP_STATUS_SUCCESS) {
  63. var mk = new BMap.Marker(r.point);
  64. map.addOverlay(mk);
  65. map.panTo(r.point);
  66. //Layer.alert('您的位置:' + r.point.lng + ',' + r.point.lat);
  67. } else {
  68. Layer.alert('failed' + this.getStatus());
  69. }
  70. }, {enableHighAccuracy: true});
  71. // 点搜索按钮时解析地址坐标
  72. $(document).on('click', '.btn-search', function () {
  73. // 创建地址解析器实例
  74. var myGeo = new BMap.Geocoder();
  75. // 将地址解析结果显示在地图上,并调整地图视野
  76. myGeo.getPoint($("#searchaddress").val(), function (point) {
  77. if (point) {
  78. map.centerAndZoom(point, 16);
  79. map.addOverlay(new BMap.Marker(point));
  80. } else {
  81. Layer.alert("您选择地址没有解析到结果!");
  82. }
  83. });
  84. });
  85. });
  86. },
  87. api: {
  88. bindevent: function () {
  89. Form.api.bindevent($("form[role=form]"));
  90. }
  91. }
  92. };
  93. return Controller;
  94. });