bdMap.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. function checkhHtml5() {
  2. if (typeof(Worker) === "undefined") {
  3. if(navigator.userAgent.indexOf("MSIE 9.0")<=0) {
  4. alert("请使用: chrome、firefox、safari、IE10 浏览器");
  5. }
  6. }
  7. }
  8. checkhHtml5();
  9. var bdMap;
  10. // 初始化地图
  11. function initBdMap () {
  12. bdMap = new BMap.Map('mapContainer');
  13. // 设置中心点
  14. if(curCityInfo.lng && curCityInfo.lat){
  15. var point = new BMap.Point(curCityInfo.lng, curCityInfo.lat);
  16. bdMap.centerAndZoom(point, curCityInfo.zoom || 10);
  17. }
  18. else{
  19. // 创建地址解析器实例
  20. var myGeo = new BMap.Geocoder();
  21. // 将地址解析结果显示在地图上,并调整地图视野
  22. var address = curCityInfo.name;
  23. myGeo.getPoint(address, function (point) {
  24. if (point) {
  25. bdMap.centerAndZoom(point, curCityInfo.zoom || 10);
  26. } else {
  27. alert("您选择地址没有解析到结果!");
  28. }
  29. }, address);
  30. }
  31. bdMap.enableScrollWheelZoom(true);
  32. // 设置地图风格
  33. var mapStyle ={
  34. features: ["road", "building","water","land"],//隐藏地图上的poi
  35. style : "midnight"
  36. };
  37. bdMap.setMapStyle(mapStyle);
  38. bdMap.clearOverlays();
  39. // 初始化宠物医院数据
  40. localStorage.getItem('isShowHospital') && initHospital();
  41. // 初始化宠物数据
  42. localStorage.getItem('isShowPets') && initPets();
  43. }
  44. // 宠物医院
  45. function initHospital() {
  46. let length = hospitalData.length;
  47. if (length == 0) {
  48. return;
  49. }
  50. var config = {
  51. icon: compbase + '/icon/hospital.png',
  52. iconWidth: 32,
  53. iconHeight: 32,
  54. };
  55. for(var i=0; i<length; i++) {
  56. let point = new BMap.Point(hospitalData[i]['Longitude'],hospitalData[i]['Latitude']);
  57. addBdMarker(point, config);
  58. }
  59. }
  60. // 宠物数据
  61. function initPets() {
  62. let length = 0;
  63. let mapPetData = [];
  64. for (index in petData) {
  65. petData[index] && $.merge(mapPetData, petData[index]);
  66. }
  67. length = mapPetData.length;
  68. if (length == 0) {
  69. return;
  70. }
  71. var config = {
  72. icon: compbase + '/icon/dog.png',
  73. iconWidth: 32,
  74. iconHeight: 32,
  75. };
  76. for(var i=0; i<length; i++) {
  77. let point = new BMap.Point(mapPetData[i]['Longitude'],mapPetData[i]['Latitude']);
  78. addBdMarker(point, config);
  79. }
  80. }
  81. // 添加覆盖物
  82. function addBdMarker(point, config){
  83. var options = {};
  84. // 图标尺寸
  85. var iconWidth = config.iconWidth || 32;
  86. var iconHeight = config.iconHeight || 32;
  87. var iconSize = new BMap.Size(iconWidth,iconHeight);
  88. if (config.icon) {
  89. options.icon = new BMap.Icon(config.icon,iconSize);
  90. }
  91. var marker = new BMap.Marker(point, options);
  92. bdMap.addOverlay(marker);
  93. }