import {getPolygonsDatas, isSelectPolygon} from './polygonsData.js' Component({ data: { longitude: 120.39053363, latitude: 36.29732416, mapScale: 15.5, // 地图缩放级别 polygons: [], markers: [] }, lifetimes: { attached: function() { console.log('map-polygons attached') this.setData({ polygons: getPolygonsDatas() }) this.addMarkers() }, detached: function() { console.log('map-polygons detached') }, }, methods: { // 添加聚合类点标记 addMarkers() { const marker = { id: 0, iconPath: '', width: 1, height: 2, // joinCluster: true, } this.data.polygons.forEach((markerPoint, index) => { const newMarker = Object.assign({}, marker, { id: markerPoint.id, longitude: markerPoint.marker[0], latitude: markerPoint.marker[1], iconPath: '../../images/pos.png', label: { content: markerPoint.label, color: '#fff', fontSize: 16, borderWidth: 1, borderRadius: 4, bgColor: markerPoint.labelFillColor, borderColor: "#cccccc00", padding: 4, display: "ALWAYS", textAlign: "center", }, }) this.data.markers.push(newMarker) }) this.setData({ markers: this.data.markers }) }, // 点击地图兴趣点事件 bindClickMap (e) { const selectItem = isSelectPolygon(e.detail) this.mapCtx = wx.createMapContext("device-map", this) const label = selectItem.label ? selectItem.label + '-' + e.detail.name : '' if (e.detail.name) { const destination = e.detail.name.indexOf('号楼') > -1 ? label : e.detail.name this.mapCtx.openMapApp({ longitude: e.detail.longitude, latitude: e.detail.latitude, destination: destination }) } // const selectItem = isSelectPolygon(e.detail) // if (selectItem.marker) { // this.mapCtx = wx.createMapContext("device-map", this) // this.mapCtx.openMapApp({ // longitude: selectItem.marker[0], // latitude: selectItem.marker[1], // destination: selectItem.label // }) // } }, } })