diff --git a/src/apps/AppBuilding/components/searchMap.vue b/src/apps/AppBuilding/components/searchMap.vue index 6895feff..269c8aeb 100644 --- a/src/apps/AppBuilding/components/searchMap.vue +++ b/src/apps/AppBuilding/components/searchMap.vue @@ -68,6 +68,41 @@ + + @@ -93,7 +128,9 @@ export default { build: {} }, showPop: false, - retryMapCount: 0 + retryMapCount: 0, + building: {}, + buildPopup: false } }, computed: {...mapState(['user'])}, @@ -145,7 +182,8 @@ export default { enableDefaultStyle: false, // 关闭默认样式 geometries: points?.map(e => ({ position: new TMap.LatLng(e.lat, e.lng), - content: `${e.createAddress} | ${e.houseNum}户` + content: `${e.createAddress} | ${e.houseNum}户`, + properties: {...e} })) || [], zoomOnClick: true }) @@ -170,53 +208,60 @@ export default { }) } else { //点标记样式 - // 以下代码为基于DOMOverlay实现聚合点气泡 - function ClusterBubble(options) { - TMap.DOMOverlay.call(this, options); + // 创建气泡DOM元素 + class ClusterBubble extends TMap.DOMOverlay { + constructor(options) { + super(options); + } + + onInit(options) { + this.content = options.content; + this.position = options.position; + }; + + onDestroy() { + this.dom.removeEventListener('click', this.onClick); + this.removeAllListeners(); + } + + createDOM() { + let dom = document.createElement('div'); + dom.classList.add('marker'); + dom.innerText = this.content; + + // 监听点击事件,实现zoomOnClick + this.onClick = this.onClick.bind(this); + // pc端注册click事件,移动端注册touchend事件 + dom.addEventListener('click', this.onClick); + dom.addEventListener('touchend', this.onClick); + return dom; + }; + + updateDOM() { + if (!this.map) { + return; + } + // 经纬度坐标转容器像素坐标 + let pixel = this.map.projectToContainer(this.position); + + // 使文本框中心点对齐经纬度坐标点 + let left = pixel.getX() - this.dom.clientWidth / 2 + 'px'; + let top = pixel.getY() - this.dom.clientHeight / 2 + 'px'; + this.dom.style.transform = `translate(${left}, ${top})`; + this.emit('dom_updated'); + }; + + onClick() { + this.emit('click'); + } } - ClusterBubble.prototype = new TMap.DOMOverlay(); - ClusterBubble.prototype.onInit = function (options) { - this.content = options.content; - this.position = options.position; - }; - // 销毁时需要删除监听器 - ClusterBubble.prototype.onDestroy = function () { - this.dom.removeEventListener('click', this.onClick); - this.removeAllListeners(); - }; - ClusterBubble.prototype.onClick = function () { - this.emit('click'); - }; - // 创建气泡DOM元素 - ClusterBubble.prototype.createDOM = function () { - var dom = document.createElement('div'); - dom.classList.add('marker'); - dom.innerText = this.content; - - // 监听点击事件,实现zoomOnClick - this.onClick = this.onClick.bind(this); - // pc端注册click事件,移动端注册touchend事件 - dom.addEventListener('click', this.onClick); - return dom; - }; - ClusterBubble.prototype.updateDOM = function () { - if (!this.map) { - return; - } - // 经纬度坐标转容器像素坐标 - let pixel = this.map.projectToContainer(this.position); - - // 使文本框中心点对齐经纬度坐标点 - let left = pixel.getX() - this.dom.clientWidth / 2 + 'px'; - let top = pixel.getY() - this.dom.clientHeight / 2 + 'px'; - this.dom.style.transform = `translate(${left}, ${top})`; - this.emit('dom_updated'); - }; let {content} = item.geometries?.[0] || {}, overlay = new ClusterBubble({map, position: item.center, content}) overlay.on('click', () => { - map.fitBounds(item.bounds); + this.buildPopup = true + this.building = item.geometries?.[0]?.properties || {} + console.log(this.building) }) markers.push(overlay) } @@ -288,7 +333,7 @@ export default { }, getBuildingInfo(item) { this.$http.post(`/app/appcommunityhouseinfo/queryDetailByIdWithBuilding?buildId=${item.buildingId}&houseId=${item.id}`).then(res => { - if (res.code == 0) { + if (res?.data) { this.show = false this.showPop = true this.detailInfo = res.data