webChat.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. (function() {
  2. 'use strict';
  3. angular
  4. .module('app')
  5. .directive('gaodeMap', Directive);
  6. Directive.$inject = [];
  7. function Directive() {
  8. var directive = {
  9. link: link,
  10. restrict: 'E',
  11. template: '<div id="container"></div>',
  12. replace: true,
  13. scope: {
  14. options: '='
  15. }
  16. };
  17. return directive;
  18. function link($scope, element, attrs) {
  19. var map, geolocation, marker, geocoder;
  20. //加载地图,调用浏览器定位服务
  21. map = new AMap.Map('container', {
  22. resizeEnable: true,
  23. zoom: 17
  24. });
  25. map.plugin('AMap.Geolocation', function() {
  26. geolocation = new AMap.Geolocation({
  27. enableHighAccuracy: true, //是否使用高精度定位,默认:true
  28. timeout: 10000, //超过10秒后停止定位,默认:无穷大
  29. maximumAge: 0, //定位结果缓存0毫秒,默认:0
  30. convert: true, //自动偏移坐标,偏移后的坐标为高德坐标,默认:true
  31. showButton: true, //显示定位按钮,默认:true
  32. buttonPosition: 'RB', //定位按钮停靠位置,默认:'LB',左下角
  33. buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
  34. showMarker: true, //定位成功后在定位到的位置显示点标记,默认:true
  35. showCircle: true, //定位成功后用圆圈表示定位精度范围,默认:true
  36. panToLocation: true, //定位成功后将定位到的位置作为地图中心点,默认:true
  37. zoomToAccuracy: true, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
  38. useNative: true
  39. });
  40. map.addControl(geolocation);
  41. geolocation.getCurrentPosition();
  42. // AMap.event.addListener(geolocation, 'complete', function(ret) {
  43. // console.log(ret.message);
  44. // }); //返回定位信息
  45. // AMap.event.addListener(geolocation, 'error', function(ret) {
  46. // console.log(ret.message);
  47. // }); //返回定位出错信息
  48. // marker = new AMap.Marker({
  49. // map: map,
  50. // bubble: true,
  51. // content: '<div class="marker-route marker-marker-bus-from"></div>' //自定义点标记覆盖物内容,
  52. // });
  53. // marker.setLabel({
  54. // offset: new AMap.Pixel(20, 0),
  55. // content: "我在这里"
  56. // });
  57. // //geocoder = new AMap.Geocoder({});
  58. // map.on('click', function(e) {
  59. // marker.setPosition(e.lnglat);
  60. // geocoder.getAddress(e.lnglat, function(status, result) {
  61. // if (status == 'complete') {
  62. // document.getElementById('input').value = result.regeocode.formattedAddress
  63. // }
  64. // });
  65. // });
  66. });
  67. // $scope.$watch("options", function(newValue, oldValue) {
  68. // if ($scope.options) {
  69. // map.setCenter([$scope.options.lng, $scope.options.lat]);
  70. // marker.setPosition([$scope.options.lng, $scope.options.lat]);
  71. // }
  72. // }, true);
  73. }
  74. }
  75. })();