当前位置:   article > 正文

vue 地图找房功能

vue 地图找房功能
  1. <template>
  2. <div class="mapSeekShop">
  3. <div class="nav clearfix">
  4. <img class="navBack fl" src="../../../static/images/common/back.png" alt="" @click="navBack()">
  5. <h2 class="navTitle fl">地图找房</h2>
  6. </div>
  7. <div id="container"></div>
  8. <!-- <div class="containerTab"> -->
  9. <ul class="containerTab">
  10. <li @click="sellBtn" :class="{'lastLi':tab===0}">销售</li>
  11. <li @click="merchantsBtn" :class="{'lastLi':tab===1}">招商</li>
  12. </ul>
  13. <!-- </div> -->
  14. </div>
  15. </template>
  16. <script>
  17. import $ from '../../../static/js/jquery.min.js';
  18. import axios from 'axios';
  19. import qs from 'qs';
  20. export default {
  21. name: "mapSeekShop",
  22. data () {
  23. return {
  24. sessionCityId: "110100", // 全局城市Id
  25. sessionProvinceId: "11000", // 全局省Id
  26. seekMapArr: [],
  27. tab: 1
  28. }
  29. },
  30. computed:{
  31. },
  32. methods:{
  33. // 点击返回按钮
  34. navBack(){
  35. this.$router.push({path: '/home'});
  36. },
  37. seekMapData(type){
  38. let url = this.changeData() + '/project/projectOnMap'
  39. axios(url,{
  40. method: 'post',
  41. params: {
  42. cityId: this.sessionCityId || 110100, //所属城市【必传】
  43. projectType: type, // 项目类型【必传】,1是销售、2是招商
  44. }
  45. }).then(data => {
  46. // console.log(data);
  47. var lnglats = data.data.projectList;
  48. // console.log(this.seekMapArr);
  49. // 百度地图API功能
  50. var mp = new BMap.Map("container");
  51. mp.centerAndZoom(new BMap.Point(116.4573195952, 39.911365), 11);
  52. mp.enableScrollWheelZoom();
  53. var geoc = new BMap.Geocoder();//逆地址解析
  54. // 复杂的自定义覆盖物
  55. function ComplexCustomOverlay(point, text){
  56. this._point = point;
  57. this._text = text;
  58. }
  59. // 继承API的BMap.Overlay
  60. ComplexCustomOverlay.prototype = new BMap.Overlay();
  61. // 实现初始化方法
  62. ComplexCustomOverlay.prototype.initialize = function(map){
  63. this._map = map;
  64. var div = this._div = document.createElement("div");
  65. div.style.position = "absolute";
  66. div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
  67. div.style.backgroundColor = "#84C0F7";
  68. div.style.border = "1px solid #84C0F7";
  69. div.style.color = "white";
  70. div.style.height = ".4rem";
  71. div.style.borderRadius = "5px";
  72. div.style.padding = ".02rem .05rem";
  73. div.style.lineHeight = ".4rem";
  74. div.style.whiteSpace = "nowrap";
  75. div.style.MozUserSelect = "none";
  76. div.style.fontSize = ".24rem"
  77. var span = this._span = document.createElement("span");
  78. div.appendChild(span);
  79. span.appendChild(document.createTextNode(this._text));
  80. var that = this;
  81. var arrow = this._arrow = document.createElement("div");
  82. arrow.style.background = "url(../../../static/images/home/blueSquare.png) no-repeat";
  83. arrow.style.position = "absolute";
  84. arrow.style.width = ".8rem";
  85. arrow.style.height = ".2rem";
  86. arrow.style.top = ".42rem";
  87. arrow.style.left = "50%";
  88. arrow.style.marginLeft = "-.1rem";
  89. arrow.style.overflow = "hidden";
  90. div.appendChild(arrow);
  91. mp.getPanes().labelPane.appendChild(div);
  92. return div;
  93. }
  94. // 实现绘制方法
  95. ComplexCustomOverlay.prototype.draw = function(){
  96. var map = this._map;
  97. // 根据地理坐标转换为像素坐标,并设置给容器
  98. var pixel = map.pointToOverlayPixel(this._point);
  99. this._div.style.left = pixel.x - parseInt(this._arrow.style.left) + "px";
  100. this._div.style.top = pixel.y - 30 + "px";
  101. }
  102. //在调用聚合方法时会将会调用标注的getPosition方法
  103. //获取该覆盖物的位置
  104. ComplexCustomOverlay.prototype.getPosition = function () {
  105. return this._point;
  106. };
  107. // 自定义覆盖物添加事件方法
  108. ComplexCustomOverlay.prototype.addEventListener = function (event, fun) {
  109. this._div['on' + event] = fun;
  110. }
  111. for (var i = 0; i < lnglats.length; i++) {
  112. //测试定位//开始自定义覆盖物
  113. var typeName;
  114. if(lnglats[i].projectType == 1){
  115. typeName = "销售";
  116. }else{
  117. typeName = "招商";
  118. }
  119. var myCompOverlay = new ComplexCustomOverlay(new BMap.Point(lnglats[i].lng,lnglats[i].lat), typeName+"-"+lnglats[i].projectName,lnglats[i].projectId);
  120. // console.log(myCompOverlay);
  121. mp.addOverlay(myCompOverlay); // 将标注添加到地图中
  122. //显示定位图标
  123. myCompOverlay.addEventListener("touchend", createClickEvent(lnglats[i].projectId,lnglats[i].projectType,lnglats[i].houseType)); //覆盖物点击事件
  124. }
  125. //不使用覆盖物,使用百度标注
  126. // var marker = new BMap.Marker(new BMap.Point(104.082042, 30.663608)); // 创建标注
  127. // mp.addOverlay(marker);
  128. // marker.addEventListener("touchend", createClickEvent(marker));
  129. function createClickEvent(id,type,houseType){
  130. return function (e) {
  131. if(type == 1){
  132. window.location.href = "./sellDetail?id="+id+"&url=mapSeekShop&type=1&houseType="+houseType;
  133. }else{
  134. window.location.href = "./merchantsDetail?id="+id+"&url=mapSeekShop&type=2&houseType="+houseType;
  135. }
  136. }
  137. }
  138. }).catch(err => {
  139. console.log(err)
  140. });
  141. },
  142. // 点击销售按钮
  143. sellBtn(){
  144. this.tab = 1;
  145. this.seekMapData(1);
  146. },
  147. // 点击招商按钮
  148. merchantsBtn(){
  149. this.tab = 0;
  150. this.seekMapData(2);
  151. }
  152. },
  153. mounted() {
  154. this.sessionCityId = sessionStorage.cityId;
  155. this.sessionProvinceId = sessionStorage.provinceId;
  156. //截取Url里面的参数
  157. function GetRequest() {
  158. var urlInfo = location.search; //获取url中"?"符后的字串
  159. var theRequest = new Object();
  160. if (urlInfo.indexOf("?") != -1) {
  161. var str = urlInfo.substr(1);
  162. var strs = str.split("&");
  163. for (var i = 0; i < strs.length; i++) {
  164. theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
  165. }
  166. }
  167. return theRequest;
  168. }
  169. //通过url取数
  170. var request = new Object();
  171. request = GetRequest();
  172. var typeIndex = request['type'];
  173. if(typeIndex){
  174. if(typeIndex == "1"){
  175. this.tab = 1;
  176. this.seekMapData(1);
  177. }else if(typeIndex == "2"){
  178. this.tab = 0;
  179. this.seekMapData(2);
  180. }
  181. }else{
  182. this.seekMapData(1);
  183. }
  184. },
  185. created(){
  186. }
  187. }
  188. </script>
  189. <style lang="scss" type="text/scss" scoped>
  190. @import "../../../static/css/commonNav.css";
  191. .mapSeekShop{
  192. width: 7.5rem;
  193. margin: 0 auto;
  194. }
  195. #container{
  196. width: 7.5rem;
  197. margin: 0 auto;
  198. }
  199. .containerTab{
  200. width: 2.3rem;
  201. height: .4rem;
  202. border: 1px solid #ebebeb;
  203. position: fixed;
  204. bottom: .72rem;
  205. left: .3rem;
  206. background: #fff;
  207. padding-top: .1rem;
  208. padding-bottom: .1rem;
  209. border-radius: 6px;
  210. box-shadow: 2px 0px 12px rgba(254,254,254,.6);
  211. li{
  212. width: 50%;
  213. color: #84C0F7;
  214. float: left;
  215. text-align: center;
  216. font-size: .28rem;
  217. }
  218. .lastLi{
  219. color: #666;
  220. border-left: 1px solid #ebebeb;
  221. box-sizing: border-box;
  222. }
  223. }
  224. </style>
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/276612
推荐阅读
相关标签
  

闽ICP备14008679号