vue實(shí)現(xiàn)高德地圖添加多個(gè)點(diǎn)標(biāo)記
新建文件 amap.vue:
<template> <div id="amapcontainer" style="width: 1000px; height: 720px"></div> </template> <script> import AMapLoader from '@amap/amap-jsapi-loader'; window._AMapSecurityConfig = { securityJsCode: '' // '「申請(qǐng)的安全密鑰」', } export default { data () { return { map: null, markerList: [], mapList: [ { name: '小王', address: '廣東省廣州市海珠區(qū)', lnglats: [113.312566, 23.085073] }, { name: '小張', address: '廣東省廣州市黃埔區(qū)', lnglats: [113.480794, 23.177896] }, { name: '小李', address: '廣東省廣州市荔灣區(qū)', lnglats: [113.220556, 23.10718] }, { name: '小趙', address: '廣東省廣州市天河區(qū)', lnglats: [113.365438, 23.124231] } ] } }, mounted () { // DOM初始化完成進(jìn)行地圖初始化 this.initAMap() }, methods: { initAMap () { AMapLoader.load({ key: "", // 申請(qǐng)好的Web端開(kāi)發(fā)者Key,首次調(diào)用 load 時(shí)必填 version: "2.0", // 指定要加載的 JSAPI 的版本,缺省時(shí)默認(rèn)為 1.4.15 plugins: ["AMap.Scale", "AMap.ToolBar", "AMap.ControlBar", 'AMap.Geocoder', 'AMap.Marker', 'AMap.CitySearch', 'AMap.Geolocation', 'AMap.AutoComplete', 'AMap.InfoWindow'], // 需要使用的的插件列表,如比例尺'AMap.Scale'等 }).then((AMap) => { // 獲取到作為地圖容器的DOM元素,創(chuàng)建地圖實(shí)例 this.map = new AMap.Map("amapcontainer", { //設(shè)置地圖容器id resizeEnable: true, zoom: this.zoom, // 地圖顯示的縮放級(jí)別 viewMode: "3D", // 使用3D視圖 zoomEnable: true, // 地圖是否可縮放,默認(rèn)值為true dragEnable: true, // 地圖是否可通過(guò)鼠標(biāo)拖拽平移,默認(rèn)為true doubleClickZoom: true, // 地圖是否可通過(guò)雙擊鼠標(biāo)放大地圖,默認(rèn)為true zoom: 11, //初始化地圖級(jí)別 center: [113.370824, 23.131265], // 初始化中心點(diǎn)坐標(biāo) 廣州 // mapStyle: "amap://styles/darkblue", // 設(shè)置顏色底層 }) this.setMapMarker() }).catch(e => { console.log(e) }) }, // 增加點(diǎn)標(biāo)記 setMapMarker () { // 創(chuàng)建 AMap.Icon 實(shí)例 let icon = new AMap.Icon({ size: new AMap.Size(36, 36), // 圖標(biāo)尺寸 image: "http://a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-red.png", // Icon的圖像 imageSize: new AMap.Size(24, 30), // 根據(jù)所設(shè)置的大小拉伸或壓縮圖片 imageOffset: new AMap.Pixel(0, 0) // 圖像相對(duì)展示區(qū)域的偏移量,適于雪碧圖等 }); let makerList = [] this.mapList.forEach((item) => { // 遍歷生成多個(gè)標(biāo)記點(diǎn) let marker = new AMap.Marker({ map: this.map, zIndex: 9999999, icon: icon, // 添加 Icon 實(shí)例 offset: new AMap.Pixel(-13, -30), //icon中心點(diǎn)的偏移量 position: item.lnglats // 經(jīng)緯度對(duì)象new AMap.LngLat(x, y),也可以是經(jīng)緯度構(gòu)成的一維數(shù)組[116.39, 39.9] }); makerList.push(marker) }); this.map.add(makerList) // 自動(dòng)適應(yīng)顯示想顯示的范圍區(qū)域 this.map.setFitView(); } } } </script> <style lang="less"> </style>
在需要使用的組件中引入 amap.vue:
<template> <div> <map-container></map-container> </div> </template> <script> import MapContainer from "@/components/amap"; export default { name: "purchannel", components: { MapContainer }, data () { return { } }, watch: {}, created () { }, mounted () { }, methods: { } } </script> <style lang="less" scoped> </style>
頁(yè)面效果:
總結(jié)
到此這篇關(guān)于vue實(shí)現(xiàn)高德地圖添加多個(gè)點(diǎn)標(biāo)記的文章就介紹到這了,更多相關(guān)vue高德地圖添加點(diǎn)標(biāo)記內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue設(shè)置導(dǎo)航欄、側(cè)邊欄為公共頁(yè)面的例子
今天小編就為大家分享一篇vue設(shè)置導(dǎo)航欄、側(cè)邊欄為公共頁(yè)面的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-11-11VUE3+TS遞歸組件實(shí)現(xiàn)TreeList設(shè)計(jì)實(shí)例詳解
這篇文章主要為大家介紹了VUE3+TS遞歸組件實(shí)現(xiàn)TreeList設(shè)計(jì)實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09Antd的Table組件嵌套Table以及選擇框聯(lián)動(dòng)操作
這篇文章主要介紹了Antd的Table組件嵌套Table以及選擇框聯(lián)動(dòng)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10vuejs移動(dòng)端實(shí)現(xiàn)div拖拽移動(dòng)
這篇文章主要為大家詳細(xì)介紹了vuejs移動(dòng)端實(shí)現(xiàn)div拖拽移動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07element-ui中select組件綁定值改變,觸發(fā)change事件方法
今天小編就為大家分享一篇element-ui中select組件綁定值改變,觸發(fā)change事件方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08可控制緩存銷毀的?keepAlive?組件實(shí)現(xiàn)詳解
這篇文章主要為大家介紹了可控制緩存銷毀的?keepAlive?組件實(shí)現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10