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

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

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

vue引入高德地圖

1.首先在public文件夾下得index.html文件中的head里面通過(guò)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.在需要用到高德地圖的頁(yè)面準(zhǔn)備一個(gè)container容器,用來(lái)初始化地圖

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

3.在js里面寫(xiě)入初始化代碼函數(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,  //初始化地圖層級(jí)
                center: [114.01807, 34.72367]  //初始化地圖中心點(diǎn)
            });
            var toolBar = new AMap.ToolBar({
                position: {
                    top: '110px',
                    right: '30px'
                }
            })
            map.addControl(toolBar);
           	_this.map = map
        },
}
mounted(){
	//頁(yè)面渲染時(shí)回調(diào)執(zhí)行
	this.createMap()
}

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

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

addMarker(data) { //date表示傳進(jìn)來(lái)的數(shù)據(jù),包括坐標(biāo)、圖標(biāo)、文字等信息
            let _this = this 
            let x = data.title.length * 10 + 10  //文字標(biāo)注偏移量位置計(jì)算(優(yōu)化頁(yè)面)
            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)聽(tīng)事件
                //進(jìn)行監(jiān)聽(tīng)操作
            })
        },

2.添加一條線

addMarker(data) { //date表示傳進(jìn)來(lái)的數(shù)據(jù),包括坐標(biāo)、圖標(biāo)、文字等信息
            let _this = this 
            let x = data.title.length * 10 + 10  //文字標(biāo)注偏移量位置計(jì)算(優(yōu)化頁(yè)面)
            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)聽(tīng)事件
                //進(jìn)行監(jiān)聽(tīng)操作
            })
        },

3.添加一個(gè)多邊形

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)聽(tīng)點(diǎn)擊事件
                //監(jiān)聽(tīng)到的事件執(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在高德地圖中手動(dòng)繪制點(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)聽(tīng)繪制完成事件

//監(jiān)聽(tīng)draw事件可獲取畫(huà)好的覆蓋物
        _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)線面的所有方法,以及手動(dòng)繪制的一些操作,如果還有疑惑的小伙伴,請(qǐng)移步至高德地圖api中進(jìn)行查看

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

相關(guān)文章

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

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

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

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

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

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

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

    vue中使用$http.post請(qǐng)求傳參的錯(cuò)誤及解決

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

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

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

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

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

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

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

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

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

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

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

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

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

最新評(píng)論

临夏市| 彝良县| 保靖县| 阿克| 泽州县| 涞水县| 汨罗市| 克拉玛依市| 西宁市| 德化县| 信丰县| 西青区| 禄丰县| 登封市| 平谷区| 贵州省| 丹阳市| 喀喇| 罗山县| 吉木萨尔县| 宁安市| 麻栗坡县| 宜春市| 府谷县| 安吉县| 堆龙德庆县| 黄山市| 屏山县| 云林县| 厦门市| 康马县| 云霄县| 彭州市| 太仆寺旗| 鄂州市| 贞丰县| 屯留县| 宜春市| 隆安县| 噶尔县| 中西区|