最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue引入高德地圖并繪制點(diǎn)線面的方法

 更新時間:2024年03月12日 10:53:53   作者:阿鈞1018  
這篇文章主要介紹了vue引入高德地圖并繪制點(diǎn)線面的實(shí)例代碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧

vue引入高德地圖

1.首先在public文件夾下得index.html文件中的head里面通過src引入高德api文件

<script src="https://webapi.amap.com/maps?v=2.0&key=你的ak"></script>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=你的ak&plugin=AMap.MouseTool,AMap.Geolocation,AMap.ControlBar,Map3D,AMap.DistrictSearch,AMap.RangingTool,AMap.PolyEditor,AMap.ToolBar"></script> //鼠標(biāo)繪制插件資源

2.在需要用到高德地圖的頁面準(zhǔn)備一個container容器,用來初始化地圖

<div class="container" id="container" ref="container">

3.在js里面寫入初始化代碼函數(shù),并在mounted函數(shù)中進(jìn)行回調(diào)

methods:{
    //初始化地圖方法
	createMap() {
            var _this = this
            const map = new AMap.Map('container', {
                viewMode: '2D',  // 默認(rèn)使用 2D 模式
                zoom: 15,  //初始化地圖層級
                center: [114.01807, 34.72367]  //初始化地圖中心點(diǎn)
            });
            var toolBar = new AMap.ToolBar({
                position: {
                    top: '110px',
                    right: '30px'
                }
            })
            map.addControl(toolBar);
           	_this.map = map
        },
}
mounted(){
	//頁面渲染時回調(diào)執(zhí)行
	this.createMap()
}

vue在高德地圖中渲染點(diǎn),線,面

1.添加一個點(diǎn)

addMarker(data) { //date表示傳進(jìn)來的數(shù)據(jù),包括坐標(biāo)、圖標(biāo)、文字等信息
            let _this = this 
            let x = data.title.length * 10 + 10  //文字標(biāo)注偏移量位置計(jì)算(優(yōu)化頁面)
            data.markGaodeLocation = _this.filterPoint(data.markGaodeLocation)
            const icon = new AMap.Icon({
                size: new AMap.Size(30, 30),    // 圖標(biāo)尺寸
                image: data.iconUrl,  // Icon的圖像
                imageSize: new AMap.Size(30, 30)   // 根據(jù)所設(shè)置的大小拉伸或壓縮圖片
            });
            const marker = new AMap.Marker({
                icon: icon,
                position: new AMap.LngLat(data.markGaodeLocation[0].markLongitude, data.markGaodeLocation[0].markLatitude),
                // content:data.title
            });
            marker.setLabel({
                offset: new AMap.Pixel(-x, 30),  //設(shè)置文本標(biāo)注偏移量
                content: `<span>${data.title}</span>`, //設(shè)置文本標(biāo)注內(nèi)容
                direction: 'right' //設(shè)置文本標(biāo)注方位
            });
            _this.map.add(marker);
            marker.on('click', function () { //添加監(jiān)聽事件
                //進(jìn)行監(jiān)聽操作
            })
        },

2.添加一條線

addMarker(data) { //date表示傳進(jìn)來的數(shù)據(jù),包括坐標(biāo)、圖標(biāo)、文字等信息
            let _this = this 
            let x = data.title.length * 10 + 10  //文字標(biāo)注偏移量位置計(jì)算(優(yōu)化頁面)
            data.markGaodeLocation = _this.filterPoint(data.markGaodeLocation)
            const icon = new AMap.Icon({
                size: new AMap.Size(30, 30),    // 圖標(biāo)尺寸
                image: data.iconUrl,  // Icon的圖像
                imageSize: new AMap.Size(30, 30)   // 根據(jù)所設(shè)置的大小拉伸或壓縮圖片
            });
            const marker = new AMap.Marker({
                icon: icon,
                position: new AMap.LngLat(data.markGaodeLocation[0].markLongitude, data.markGaodeLocation[0].markLatitude),
                // content:data.title
            });
            marker.setLabel({
                offset: new AMap.Pixel(-x, 30),  //設(shè)置文本標(biāo)注偏移量
                content: `<span>${data.title}</span>`, //設(shè)置文本標(biāo)注內(nèi)容
                direction: 'right' //設(shè)置文本標(biāo)注方位
            });
            _this.map.add(marker);
            marker.on('click', function () { //添加監(jiān)聽事件
                //進(jìn)行監(jiān)聽操作
            })
        },

3.添加一個多邊形

addGon(data) {
            let _this = this
            let array = [] //計(jì)算中心點(diǎn)需要的數(shù)據(jù)
            data.markGaodeLocation = _this.filterPoint(data.markGaodeLocation)
            var lineArray = [] // 線的點(diǎn)的集合
            data.markGaodeLocation.forEach(item => {
                lineArray.push(new AMap.LngLat(item.markLongitude, item.markLatitude))
            })
            data.markGaodeLocation.forEach((item) => {
                array.push([item.markLatitude, item.markLongitude])
            })
            let latArray = _this.mapGetCenter(array) //計(jì)算出中心點(diǎn)
            var polygon = new AMap.Polygon({
                path: lineArray,
                opacity:0.1,
                fillOpacity:0.3,
                fillColor: '#fff', // 多邊形填充顏色
                borderWeight: 2, // 線條寬度,默認(rèn)為 1
                strokeColor: 'blue', // 線條顏色
            });
            _this.map.add(polygon)
            _this.addLabel01(latArray,data.title) //在多邊形中心點(diǎn)添加文字標(biāo)注
            polygon.on('click', function () { //監(jiān)聽點(diǎn)擊事件
                //監(jiān)聽到的事件執(zhí)行操作
            })
        },

4.添加文字標(biāo)注

addLabel(data, title) {
            let _this = this
            var text = new AMap.Text({
                text: title,
                anchor: 'center', // 設(shè)置文本標(biāo)記錨點(diǎn)
                draggable: false,
                cursor: 'pointer',
                angle: 10,
                style: {
                    // 'padding': '.75rem 1.25rem',
                    'margin-bottom': '1rem',
                    'border-radius': '.25rem',
                    'background-color': 'transparent',
                    // 'width': '15rem',
                    'border-width': 0,
                    'box-shadow': '0 2px 6px 0 rgba(114, 124, 245, .5)',
                    'text-align': 'center',
                    'font-size': '12px',
                    'color': 'blue'
                },
                position: [data[0], data[1]]
            });
            text.setMap(_this.map)
        },

vue在高德地圖中手動繪制點(diǎn),線,面

1.創(chuàng)建繪制工具

draw(type) {
            switch (type) {
                case 'marker': {
                    this.mouseTool.marker({})
                    break;
                }
                case 'polyline': {
                    this.mouseTool.polyline({
                        strokeColor: '#80d8ff'
                        //同Polyline的Option設(shè)置
                    });
                    break;
                }
                case 'polygon': {
                    this.mouseTool.polygon({
                        fillColor: '#00b0ff',
                        strokeColor: '#80d8ff'
                        //同Polygon的Option設(shè)置
                    });
                    break;
                }
            }
        },

2.監(jiān)聽繪制完成事件

//監(jiān)聽draw事件可獲取畫好的覆蓋物
        _this.mouseTool.on('draw', function (e) {
            if (e.obj.CLASS_NAME == "AMap.Marker") {
                console.log(e.obj.w.position.lat) //繪制完成后點(diǎn)的緯度
                console.log(e.obj.w.position.lng) //繪制完成后點(diǎn)的經(jīng)度
            } else if (e.obj.CLASS_NAME == "AMap.Polyline") {
                let locat = e.obj.getPath() //獲取繪制完成后的線的所有坐標(biāo)點(diǎn)
            } else if (e.obj.CLASS_NAME == "AMap.Polygon") {
                let locat = e.obj.getPath() //獲取繪制完成后的多邊形的所有坐標(biāo)點(diǎn)
            }
            _this.mouseTool.close(true) //最后關(guān)閉繪制工具
        })	 

以上內(nèi)容就是在vue中添加點(diǎn)線面的所有方法,以及手動繪制的一些操作,如果還有疑惑的小伙伴,請移步至高德地圖api中進(jìn)行查看

到此這篇關(guān)于vue引入高德地圖并繪制點(diǎn)線面的文章就介紹到這了,更多相關(guān)vue引入高德地圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue實(shí)現(xiàn)多級菜單效果

    vue實(shí)現(xiàn)多級菜單效果

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)多級菜單效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-10-10
  • Vue和Flask通信的實(shí)現(xiàn)

    Vue和Flask通信的實(shí)現(xiàn)

    最近新做了個項(xiàng)目,前端使用的是目前很流行的前端框架,對于后端,本項(xiàng)目選擇的是比較好上手、輕量級的python后臺框架:Flask。感興趣的可以了解一下
    2021-05-05
  • uniapp模仿微信實(shí)現(xiàn)聊天界面的示例代碼

    uniapp模仿微信實(shí)現(xiàn)聊天界面的示例代碼

    這篇文章主要介紹了如何利用uniapp模仿微信,實(shí)現(xiàn)一個聊天界面。文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)Vue有一定的幫助,感興趣的可以了解一下
    2022-01-01
  • vue中使用$http.post請求傳參的錯誤及解決

    vue中使用$http.post請求傳參的錯誤及解決

    這篇文章主要介紹了vue中使用$http.post請求傳參的錯誤及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • element-ui如何防止重復(fù)提交的方法步驟

    element-ui如何防止重復(fù)提交的方法步驟

    這篇文章主要介紹了element-ui如何防止重復(fù)提交的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • el-tree懶加載的實(shí)現(xiàn)以及局部刷新方式

    el-tree懶加載的實(shí)現(xiàn)以及局部刷新方式

    這篇文章主要介紹了el-tree懶加載的實(shí)現(xiàn)以及局部刷新方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • vue+elementUI組件tree如何實(shí)現(xiàn)單選加條件禁用

    vue+elementUI組件tree如何實(shí)現(xiàn)單選加條件禁用

    這篇文章主要介紹了vue+elementUI組件tree如何實(shí)現(xiàn)單選加條件禁用,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • vue如何實(shí)現(xiàn)未登錄不能訪問某些頁面

    vue如何實(shí)現(xiàn)未登錄不能訪問某些頁面

    這篇文章主要介紹了vue如何實(shí)現(xiàn)未登錄不能訪問某些頁面問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • Vue中Vue.extend()的使用及解析

    Vue中Vue.extend()的使用及解析

    這篇文章主要介紹了Vue中Vue.extend()的使用及解析,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • vue3+vite assets動態(tài)引入圖片的三種方法及解決打包后圖片路徑錯誤不顯示的問題

    vue3+vite assets動態(tài)引入圖片的三種方法及解決打包后圖片路徑錯誤不顯示的問題

    這篇文章主要介紹了vue3+vite assets動態(tài)引入圖片的幾種方式,解決打包后圖片路徑錯誤不顯示的問題,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-03-03

最新評論

基隆市| 胶州市| 根河市| 佛坪县| 来安县| 台山市| 横峰县| 五莲县| 微山县| 清远市| 泸州市| 沛县| 奈曼旗| 棋牌| 阿勒泰市| 穆棱市| 江华| 娄底市| 襄汾县| 平江县| 荃湾区| 嵊州市| 韩城市| 洮南市| 溧水县| 遂平县| 公安县| 玉树县| 正镶白旗| 建始县| 新化县| 贺州市| 南宫市| 溧水县| 三明市| 乡宁县| 溆浦县| 肥城市| 镇沅| 泾阳县| 唐河县|