Commit f11056559d409b900cee3564724b1e3709758f51
1 parent
a3e443aa
map
Showing
5 changed files
with
94 additions
and
3 deletions
src/components/VMap.vue
| 1 | <template> | 1 | <template> |
| 2 | - <div>地图</div> | 2 | + <div class="map-wrap" id="map"></div> |
| 3 | </template> | 3 | </template> |
| 4 | 4 | ||
| 5 | <script> | 5 | <script> |
| 6 | +import busyCar from '../images/content/busy-status.png'; //以import的方式导入图片文件 | ||
| 7 | +import normalCar from '../images/content/normal-status.png'; //以import的方式导入图片文件 | ||
| 8 | +import idleCar from '../images/content/idle-status.png'; //以import的方式导入图片文件 | ||
| 9 | + | ||
| 6 | export default { | 10 | export default { |
| 7 | - name: 'VMap' | 11 | + name: 'VMap', |
| 12 | + mounted(){ | ||
| 13 | + this.drawMap() | ||
| 14 | + }, | ||
| 15 | + methods:{ | ||
| 16 | + drawMap(){ | ||
| 17 | + let data = [ | ||
| 18 | + {Name:'万达停车场1',lonId:'111.742579',latId:'40.818675',status:0,free:30,total:1000}, | ||
| 19 | + {Name:'万达停车场2',lonId:'111.622579',latId:'40.878675',status:1,free:40,total:800}, | ||
| 20 | + {Name:'万达停车场333333',lonId:'111.782579',latId:'40.778675',status:2,free:300,total:500} | ||
| 21 | + ]; | ||
| 22 | + var map = new BMap.Map('map', {enableMapClick: false}) | ||
| 23 | + var point = new BMap.Point(data[0].lonId, data[0].latId) | ||
| 24 | + map.centerAndZoom(point, 15) | ||
| 25 | + var mapStyle={ style : "midnight" } | ||
| 26 | + map.enableScrollWheelZoom(false); | ||
| 27 | + map.setMapStyle(mapStyle); | ||
| 28 | + // var marker = new BMap.Marker(point) // 创建标注 | ||
| 29 | + // map.addOverlay(marker) // 将标注添加到地图中 | ||
| 30 | + | ||
| 31 | + map.clearOverlays(); | ||
| 32 | + var i = 0; | ||
| 33 | + var points = []; | ||
| 34 | + for (var item in data) { | ||
| 35 | + (function (x) { | ||
| 36 | + var itemthat = item; | ||
| 37 | + //创建标注 | ||
| 38 | + var pt = new BMap.Point(data[item].lonId, data[item].latId); | ||
| 39 | + points[i] = pt; | ||
| 40 | + if(data[item].freeBrethNum/data[item].plBerthNum == 0){ | ||
| 41 | + var myIcon = new BMap.Icon(busyCar, | ||
| 42 | + new BMap.Size(29, 40), { | ||
| 43 | + offset: new BMap.Size(10, 40), | ||
| 44 | + textColor: '#fff' | ||
| 45 | + }); | ||
| 46 | + var marker = new BMap.Marker(pt,{icon:myIcon}); | ||
| 47 | + } else if(data[item].freeBrethNum/data[item].plBerthNum <= 0.3){ | ||
| 48 | + var myIcon = new BMap.Icon(normalCar, | ||
| 49 | + new BMap.Size(29, 40), { | ||
| 50 | + offset: new BMap.Size(10, 40), | ||
| 51 | + textColor: '#fff' | ||
| 52 | + }); | ||
| 53 | + var marker = new BMap.Marker(pt,{icon:myIcon}); | ||
| 54 | + } else { | ||
| 55 | + var myIcon = new BMap.Icon(idleCar, | ||
| 56 | + new BMap.Size(29, 40), { | ||
| 57 | + offset: new BMap.Size(10, 40), | ||
| 58 | + textColor: '#fff' | ||
| 59 | + }); | ||
| 60 | + var marker = new BMap.Marker(pt,{icon:myIcon}); | ||
| 61 | + } | ||
| 62 | + var myIcon = new BMap.Icon(busyCar, | ||
| 63 | + new BMap.Size(29, 40), { | ||
| 64 | + offset: new BMap.Size(10, 40), | ||
| 65 | + textColor: '#fff' | ||
| 66 | + }); | ||
| 67 | + | ||
| 68 | + marker.setTop(true,27000000); | ||
| 69 | + map.addOverlay(marker); | ||
| 70 | + var myLabel; | ||
| 71 | + | ||
| 72 | + marker.addEventListener("mouseover", (e)=> { | ||
| 73 | + map.removeOverlay(myLabel); | ||
| 74 | + var that = this; | ||
| 75 | + let tmpHtml = ''; | ||
| 76 | + for(let i=0;i<JSON.parse(data[itemthat].plRate).length;i++){ | ||
| 77 | + //console.log(data[itemthat].plRate) | ||
| 78 | + tmpHtml += "<li>"+JSON.parse(data[itemthat].plRate)[i].standard+"</li>" | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + | ||
| 82 | + }); | ||
| 83 | + marker.addEventListener("mouseout", function (e) { | ||
| 84 | + map.removeOverlay(myLabel); | ||
| 85 | + }); | ||
| 86 | + i++; | ||
| 87 | + })(i); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + } | ||
| 93 | + | ||
| 8 | } | 94 | } |
| 9 | </script> | 95 | </script> |
| 10 | 96 | ||
| 11 | <style scoped lang="scss"> | 97 | <style scoped lang="scss"> |
| 12 | - | 98 | + .map-wrap{ |
| 99 | + width: 100%; | ||
| 100 | + height: 100%; | ||
| 101 | + } | ||
| 13 | </style> | 102 | </style> |
src/images/content/busy-status.png
0 → 100644
1.06 KB
src/images/content/idle-status.png
0 → 100644
1.2 KB
src/images/content/normal-status.png
0 → 100644
1.17 KB