diff --git a/src/App.vue b/src/App.vue index 4467e80..9403afb 100644 --- a/src/App.vue +++ b/src/App.vue @@ -23,12 +23,14 @@ } .BMap_bubble_pop{ color: #fff !important; - height:220px !important; + max-width: 3.67rem; + height:2.2rem !important; padding:0 !important; background-image: url(@/assets/images/infowindow_bg.png) !important; background-color: transparent !important; background-repeat: no-repeat; border: 0 !important; + background-size: 100% 100% !important; img{ display: none !important; } diff --git a/src/views/components/pathMap.vue b/src/views/components/pathMap.vue index 789d596..918561e 100644 --- a/src/views/components/pathMap.vue +++ b/src/views/components/pathMap.vue @@ -48,73 +48,83 @@ export default { this.baiduMap.centerAndZoom(point, 11); }, initMap() { - this.baiduMap = new BMapGL.Map('container'); var point = new BMapGL.Point(118.880278, 35.649947); - this.baiduMap.centerAndZoom(point, 11); - this.baiduMap.enableScrollWheelZoom(true); - // this.baiduMap.setMapStyleV2({ - // styleId: 'ec6ebc8ad35bcfbd56a424a29f325360'//'ef4f05652d24d0f23332710fbacad245'// - // }); - this.baiduMap.setMapStyleV2({ - styleJson - }) - // this.view = new mapvgl.View({ - // map: this.baiduMap - // }); - var bdary = new BMapGL.Boundary(); - bdary.get("日照市莒县", rs => { - var count = rs.boundaries.length; - for (var i = 0; i < count; i++) { - var xyArr = rs.boundaries[i].split(';'); - var ptArr = []; - for (var j = 0; j < xyArr.length; j++) { - var tmp = xyArr[j].split(','); - var pt = new BMapGL.Point(tmp[0], tmp[1]); - ptArr.push(pt); + if (this.baiduMap) { + this.baiduMap.centerAndZoom(point, 11); + } + else { + this.baiduMap = new BMapGL.Map('container'); + this.baiduMap.centerAndZoom(point, 11); + this.baiduMap.enableScrollWheelZoom(true); + // this.baiduMap.setMapStyleV2({ + // styleId: 'ec6ebc8ad35bcfbd56a424a29f325360'//'ef4f05652d24d0f23332710fbacad245'// + // }); + this.baiduMap.setMapStyleV2({ + styleJson: styleJson + }) + alert('自定义样式') + // this.view = new mapvgl.View({ + // map: this.baiduMap + // }); + var bdary = new BMapGL.Boundary(); + bdary.get("日照市莒县", rs => { + var count = rs.boundaries.length; + for (var i = 0; i < count; i++) { + var xyArr = rs.boundaries[i].split(';'); + var ptArr = []; + for (var j = 0; j < xyArr.length; j++) { + var tmp = xyArr[j].split(','); + var pt = new BMapGL.Point(tmp[0], tmp[1]); + ptArr.push(pt); + } + // var mapmask = new BMapGL.MapMask(ptArr, { + // isBuildingMask: true, + // isPoiMask: true, + // isMapMask: true, + // showRegion: 'inside', + // topFillColor: '#5679ea', + // topFillOpacity: 0.5, + // sideFillColor: '#5679ea', + // sideFillOpacity: 0.9 + // }); + // this.baiduMap.addOverlay(mapmask); + var border = new BMapGL.Polyline(ptArr, { + strokeColor: '#0e94eb', + strokeWeight: 3, + strokeOpacity: 1 + }); + this.baiduMap.addOverlay(border); + // var ply = new BMapGL.Polygon(rs.boundaries[i], { strokeWeight: 2, strokeColor: "#0e94eb", fillColor: '', fillOpacity: 0, }); //建立多边形覆盖物 + // this.baiduMap.addOverlay(ply); //添加覆盖物 } - // var mapmask = new BMapGL.MapMask(ptArr, { - // isBuildingMask: true, - // isPoiMask: true, - // isMapMask: true, - // showRegion: 'inside', - // topFillColor: '#5679ea', - // topFillOpacity: 0.5, - // sideFillColor: '#5679ea', - // sideFillOpacity: 0.9 - // }); - // this.baiduMap.addOverlay(mapmask); - var border = new BMapGL.Polyline(ptArr, { - strokeColor: '#0e94eb', - strokeWeight: 3, - strokeOpacity: 1 - }); - this.baiduMap.addOverlay(border); - // var ply = new BMapGL.Polygon(rs.boundaries[i], { strokeWeight: 2, strokeColor: "#0e94eb", fillColor: '', fillOpacity: 0, }); //建立多边形覆盖物 - // this.baiduMap.addOverlay(ply); //添加覆盖物 - } - }) - this.baiduMap.addEventListener('tilesloaded', () => { - this.carList.map((item, index) => { - this.markList.map(mark => { - this.baiduMap.removeOverlay(mark); - }) - this.markList = []; - this.queryLunz(item.deviceId, item.key, item.cardNo, index); }) - this.setInterval = setInterval(() => { - // this.view.removeAllLayers(); - this.markList.map(mark => { - this.baiduMap.removeOverlay(mark); - }) - this.markList = []; - // this.viewData = []; - this.carList.map((item, index) => { - this.queryLunz(item.deviceId, item.key, item.cardNo, index); + this.baiduMap.removeEventListener('tilesloaded', this.handleEvent); + console.log('removeEventListener'); + this.baiduMap.addEventListener('tilesloaded', this.handleEvent); + } - }) - }, 20 * 1000) + }, + handleEvent() { + console.log('addEventListener'); + this.carList.map((item, index) => { + this.markList.map(mark => { + this.baiduMap.removeOverlay(mark); + }) + this.markList = []; + this.queryLunz(item.deviceId, item.key, item.cardNo, index); }) + this.setInterval = setInterval(() => { + // this.view.removeAllLayers(); + this.markList.map(mark => { + this.baiduMap.removeOverlay(mark); + }) + this.markList = []; + // this.viewData = []; + this.carList.map((item, index) => { + this.queryLunz(item.deviceId, item.key, item.cardNo, index); + }) + }, 20 * 1000) }, //单个设备定位聚焦放大 queryDingwei(deviceId) { @@ -150,17 +160,17 @@ export default { // objdata: { carNo: carNo, deviceId: key, resData: res.Data, res2Data: res2.Data } // }) this.markList.push(marker); - let sContent = `