1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| <template> <div id="map_canvas" style="width:500px;height:500px"></div> <button id="run" @click="run">开始</button> <button id="stop" @click="stop">停止</button> <button id="pause" @click="pause">暂停</button> <button id="hide" @click="hide">隐藏信息窗口</button> <button id="show" @click="show">展示信息窗口</button> </template> <script lang="ts" setup> import { ref, onMounted } from "vue"; import car from "@/assets/car.png"; const lushu = ref(null) as any; onMounted(() => { initMap(); }); function initMap() { const map = new BMap.Map("map_canvas"); map.enableScrollWheelZoom(true); map.centerAndZoom(new BMap.Point(116.404, 39.915), 13); var arrPois = [] as any; console.log(arrPois); arrPois = [ new BMap.Point(112.14267243359373, 45.081711957142886), new BMap.Point(121.10751618359373, 24.277571914059855), new BMap.Point(116.404844, 39.911836), new BMap.Point(116.308102, 40.056057), ]; console.log(arrPois); map.addOverlay(new BMap.Polyline(arrPois, { strokeColor: "#111" })); map.setViewport(arrPois); const customContent = [] as any; arrPois.forEach((element: any, index: any) => { customContent.push({ html: `<div> <div class="poi-name">${index}</div> <div class="poi-address">`, }); }); lushu.value = new BMapLib.LuShu(map, arrPois, { defaultContent: "", customContent: customContent, autoView: true, icon: new BMap.Icon(car, new BMap.Size(52, 26), { anchor: new BMap.Size(27, 13), }), speed: 450000, enableRotation: true, landmarkPois: [ { lng: 116.314782, lat: 39.913508, html: "加油站", pauseTime: 2 }, { lng: 121.10751618359373, lat: 24.277571914059855, html: '高速公路收费<div><img src="//map.baidu.com/img/logo-map.gif"/></div>', pauseTime: 3, }, { lng: 116.381476, lat: 39.974073, html: "肯德基早餐", pauseTime: 2 }, ], }); } function run() { lushu.value.start(); } function stop() { lushu.value.stop(); } function pause() { lushu.value.pause(); } function hide() { lushu.value.hideInfoWindow(); } function show() { lushu.value.showInfoWindow(); } </script>
|