成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

VUE 記一次高德地圖和Echarts(中國地圖)

KoreyLee / 4112人閱讀

摘要:效果圖準(zhǔn)備工作高德地圖申請(qǐng)安裝中國地圖高德地圖官方點(diǎn)我進(jìn)入創(chuàng)建動(dòng)態(tài)創(chuàng)建標(biāo)簽后的是需要的插件中國地圖安裝開始使用創(chuàng)建組件寫入需要的分布指數(shù)高低寫入高德地圖需要的

效果圖

準(zhǔn)備工作

高德地圖申請(qǐng)key

安裝Echarts 中國地圖

高德地圖

官方API:點(diǎn)我進(jìn)入

創(chuàng)建AMap.js

export default function MapLoader () {
    return new Promise((resolve, reject) => {
      if (window.AMap) {
        resolve(window.AMap)
      } else {
      // 動(dòng)態(tài)創(chuàng)建script標(biāo)簽
        var script = document.createElement("script")
        script.type = "text/javascript"
        script.async = true
        script.src = "https://webapi.amap.com/maps");;
        // plugin后的是需要的插件
        script.onerror = reject
        document.head.appendChild(script)
      }
      window.initAMap = () => {
        resolve(window.AMap)
      }
    })
}

Echarts 中國地圖

安裝Echarts

npm install echarts -S

開始使用

創(chuàng)建組件 distribution.vue

寫入Echarts 需要的DOM

    

分布指數(shù)

寫入高德地圖需要的DOM

    

引入高德地圖、Echarts

    import "echarts/map/js/china"; //中國地圖js
    import MapLoader from "components/home/AMap"

Echarts方法

generateEcharts() {
    var echarts = require("echarts");
    var myChart = echarts.init(this.$refs.main);  // 基于準(zhǔn)備好的dom,初始化echarts實(shí)例
    this.$ajax.get(this.HOST + "/redesign/home/findEnterpriseistribution").then( (res) => {
        // 數(shù)據(jù)格式
        // [
        //   {name: "北京", value: 3, ranking: 1},
        //   {name: "河北", value: 2, ranking: 2},
        //   {name: "上海", value: 1, ranking: 3},
        //   {name: "廣東", value: 1, ranking: 4}
        //   ...
        // ]
        this.homebution = res.data.resultObject;
        var data = [];
        for (let i = 0; i < res.data.resultObject.length; i++) {
            this.homebutionnum += res.data.resultObject[i].value;
            let classnum = ""
            // 排名顯示樣式
            if(res.data.resultObject[i].ranking == 1) { 
                classnum = "#1669e6"
            }else if(res.data.resultObject[i].ranking > 1 && res.data.resultObject[i].ranking <= 4) {
                classnum = "#31a4ed"
            }else if(res.data.resultObject[i].ranking > 4 && res.data.resultObject[i].ranking <= 10) {
                classnum = "#2cccfd"
            }else if(res.data.resultObject[i].ranking > 10 && res.data.resultObject[i].ranking <= 20) {
                classnum = "#7fe2fd"
            }else {
                classnum = "#d9f4fe"
            }
            data.push(
                {
                    name: res.data.resultObject[i].name,
                    itemStyle: {
                        normal: {
                            areaColor: classnum,
                            // borderWidth: 2
                        },
                        emphasis: {//高亮狀態(tài)下的多邊形和標(biāo)簽樣式
                            borderWidth: 1,
                            // borderColor: "#d9f4fe",
                            areaColor: "#d9f4fe",
                            label: {
                                shadowColor: "#d9f4fe", //默認(rèn)透明
                                shadowBlur: 10,
                                show: true,
                                textStyle: {
                                    fontSize: 12,
                                    color: "#3db77f"
                                }
                            }
                        }
                    },
                    label: {
                        normal: {
                            show: true,
                            textStyle: {
                                fontSize: 12,
                                color: "#0d6fb8"
                            }
                        },
                        emphasis: {
                            show: true,
                            color: "#3db77f"
                        }
                    },
                    value: res.data.resultObject[i].value ");"",
                    ranking: res.data.resultObject[i].ranking ");""
                }
            )
        }
        // 準(zhǔn)備提示數(shù)據(jù)
        var option = {
            tooltip: {
                formatter:  (params) => {
                    var info = "";
                        if(params.data) {
                            info = `

${ params.name }

${ params.data.value }

排名:${ params.data.ranking }

`
}else { info = `

${ params.name }

`
} return info; }, backgroundColor: "rgba(0,0,0,.6)",//提示標(biāo)簽背景顏色 textStyle: { color: "#fff" } //提示標(biāo)簽字體顏色 }, //配置屬性 series: [{ name: "數(shù)據(jù)", type: "map", mapType: "china", roam: true, label: { normal: { show: false //省份名稱 }, emphasis: { show: false } }, data: data //數(shù)據(jù) }], }; //使用制定的配置項(xiàng)和數(shù)據(jù)顯示圖表 myChart.setOption(option); }) }

高德地圖方法

Scottmap() {
    let that = this;
    that.map = "";
    MapLoader().then(AMap => {
        console.log("地圖加載成功")
        that.map = new AMap.Map("container", {
            center: [116.05438, 38.98065],
            // center: [116.397428, 39.90923],
            zoom: 5
        })
        // 由于項(xiàng)目是按雄安地區(qū)使用 API暫時(shí)還未把雄安劃分 所以決定把安新縣、雄縣、容城縣(三縣合一就是雄安)繪制成高亮
        // 繪制高亮
        var district = new AMap.DistrictSearch({
            // 返回行政區(qū)邊界坐標(biāo)等具體信息
            extensions: "all",
            // 設(shè)置查詢行政區(qū)級(jí)別為 區(qū) 
            level: "district"
        })
        var polygons=[];
        var polygons2=[];
        var polygons3=[];
        district.search("安新縣", (status, result) => {
            if(polygons) {
                that.map.remove(polygons)//清除上次結(jié)果
            }
            polygons = [];
            let bounds = result.districtList[0].boundaries;
            if (bounds) {
                for (let i = 0; i < bounds.length; i++) {
                    //生成行政區(qū)劃polygon
                    var polygon = new AMap.Polygon({
                        strokeWeight: 1,
                        path: bounds[i],
                        fillOpacity: 0.4,
                        fillColor: "#80d8ff",
                        strokeColor: "#0091ea"
                    });
                    polygons.push(polygon);
                }
            }
            that.map.add(polygons);
        });
        district.search("雄縣", (status2, result2) => {
            if(polygons2) {
                that.map.remove(polygons2)//清除上次結(jié)果
            }
            polygons2 = [];
            let bounds = result2.districtList[0].boundaries;
            if (bounds) {
                for (let i = 0; i < bounds.length; i++) {
                    //生成行政區(qū)劃polygon
                    var polygon = new AMap.Polygon({
                        strokeWeight: 1,
                        path: bounds[i],
                        fillOpacity: 0.4,
                        fillColor: "#80d8ff",
                        strokeColor: "#0091ea"
                    });
                    polygons2.push(polygon);
                }
            }
            that.map.add(polygons2)
        })
        district.search("容城縣", (status2, result2) => {
            if(polygons3) {
                that.map.remove(polygons2)//清除上次結(jié)果
            }
            polygons3 = [];
            let bounds = result2.districtList[0].boundaries;
            if (bounds) {
                for (let i = 0; i < bounds.length; i++) {
                    //生成行政區(qū)劃polygon
                    var polygon = new AMap.Polygon({
                        strokeWeight: 1,
                        path: bounds[i],
                        fillOpacity: 0.4,
                        fillColor: "#80d8ff",
                        strokeColor: "#0091ea"
                    });
                    polygons3.push(polygon);
                }
            }
            that.map.add(polygons3)
        })
        // 構(gòu)造矢量圓形(圓)
        let circle = new AMap.Circle({
            center:  [116.05438, 38.98065], // 雄安的中心點(diǎn)
            radius: that.distance * 1000,  //半徑
            strokeColor: "#ffffff",  //線顏色
            strokeOpacity: 1,  //線透明度
            strokeWeight: 3,  //線粗細(xì)度
            fillColor: "#276cd4",  //填充顏色
            fillOpacity: 0.2 //填充透明度
        });
        that.map.add(circle);
        that.map.setFitView(circle);
        let lnglat = new AMap.LngLat(116.05438, 38.98065) // lng, lat 替換成傳入的坐標(biāo) 
        let polylinePath = [
            new AMap.LngLat(116.05438, 38.98065),
            new AMap.LngLat(lnglat.offset(that.distance * 1000,0).lng,38.98065)
        ];
        // 創(chuàng)建線覆蓋物
        let polyline = new AMap.Polyline({
            path: polylinePath,
            strokeColor: "#ffffff", //線顏色
            strokeOpacity: 1,       //線透明度
            strokeWeight: 2,        //線寬
            strokeStyle: "solid",   //線樣式
            strokeDasharray: [10, 5] //補(bǔ)充線樣式
        });
        that.map.add(polyline);
        // 繪制字
        let textPos = lnglat.offset(that.distance * 500,that.distance * 50);
        let text = new AMap.Text({
            text: `${ that.distance }公里`,
            position: textPos,
            map: this.map,
            style:{
                    "background": "transparent",
                    "border": "0 none",
                    "color": "#276cd4",
                    "font-size":"14px"}
        })
        that.map.add(text);
        // 測(cè)試距離
        let Centralpoint = [116.05438, 38.98065];
        let targetpoint = this.region
        // debugger
        // 轉(zhuǎn)經(jīng)緯度
        let geocoder = new AMap.Geocoder({
            city: "全國", //城市設(shè)為北京,默認(rèn):“全國”
        });
        let markernum = 0
        for (let i = 0; i < targetpoint.length; i++) {
            geocoder.getLocation(targetpoint[i], (status, result) => {
                if (status === "complete"&& result.geocodes.length) {
                    let dis = AMap.GeometryUtil.distance(Centralpoint,result.geocodes[0].location);
                    // 繪制點(diǎn)標(biāo)記顯示內(nèi)容,HTML要素字符串
                    if(dis <= that.distance * 1000) {
                        markernum++;
                        let markerContent = "" +
                            "
" + " " + "
"+ markernum +"
"
+ "
"
; this.$ajax.get(this.HOST + "/redesign/home/findCompanyAll").then( (res) => { this.matchingenterpriseList.push(res.data.resultObject[i]) }) let marker = new AMap.Marker({ content: markerContent, position: result.geocodes[0].location, offset: new AMap.Pixel(-13, -30), extData:{ id: markernum } }); that.markers.push(marker); marker.setMap(this.map); } } }) } that.matchingenterpriseState = true; }, e => { console.log("地圖加載失敗" ,e) }) },

左側(cè)企業(yè)列表

// 企業(yè)鼠標(biāo)經(jīng)過
matchingenterprisemouseenter(item,index) {
    this.activemetchmouseenter = index;
    let targetMarker = {};
    for (let i = 0; i < this.markers.length; i++) {
        let id = this.markers[i].getExtData().id;
        if(id == index){
            targetMarker = this.markers[i];
            break;
        }
    }
    // 重新替換樣式
    let markerContent = "" +
        "
" + " " + "
"+ index +"
"
+ "
"
; // targetMarker.setIcon("http://a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png"); targetMarker.setContent(markerContent) let position = targetMarker.getPosition(); this.infoWindow = new AMap.InfoWindow({ position: position, offset: new AMap.Pixel(0, -35), content: item.companyName }); this.infoWindow.open(this.map); },
// 企業(yè)鼠標(biāo)離開
matchingenterprisemouseleave(item,index) {
    this.activemetchmouseenter = "";
    let targetMarker = {};
    for (let i = 0; i < this.markers.length; i++) {
        let id = this.markers[i].getExtData().id;
        if(id == index){
            targetMarker = this.markers[i];
            break;
        }
    }
    let markerContent = "" +
        "
" + " " + "
"+ index +"
"
+ "
"
; // targetMarker.setIcon("http://a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png"); targetMarker.setContent(markerContent) this.map.remove(this.infoWindow); },
// 企業(yè)點(diǎn)擊
matchingenterpriseclick(item,index) {
    this.activeState3 = true;
    this.activeState1 = false;
    this.activeState = false;
    this.itemList = item;
    // this.map.remove(overlayGroups);
    let geocoder = new AMap.Geocoder({
        city: "全國", //城市設(shè)為北京,默認(rèn):“全國”
    });
    geocoder.getLocation(item.address, (status, result) => {
        this.map.setCenter(result.geocodes[0].location); //設(shè)置地圖中心點(diǎn)
        this.map.setZoom(30); // 縮放級(jí)別
    })
},

具體代碼

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/7867.html

相關(guān)文章

  • vuevuex,echarts,地圖,ueditor的使用

    摘要:獲取富文本內(nèi)容地圖我是使用高德地圖在全局導(dǎo)入為我申請(qǐng)的也可以自己去申請(qǐng)高德地圖官網(wǎng)案例 前言 今天是個(gè)好日子,大家六一快樂;vue-cli生成的template還需要配置axios,vuex,element等插件,該項(xiàng)目中將這些常用插件進(jìn)行了配置;項(xiàng)目開發(fā)中template可以快速復(fù)用,也是可以快速上手vue的一個(gè)demo; 1.動(dòng)態(tài)效果圖 showImg(https://segmen...

    Cheriselalala 評(píng)論0 收藏0
  • echarts結(jié)合高德API進(jìn)行地圖下鉆

    摘要:廣告開始最近做了表格數(shù)據(jù)轉(zhuǎn)成圖表展示的一個(gè)組件,地址如下整合地圖的時(shí)候發(fā)現(xiàn)針對(duì)地級(jí)市的一些文件太多了,全部引入后有將近,所以就用了下高德老爺給的組件和接口,然后弄完在這記錄一下雖然這種例子在社區(qū)里有很多這個(gè)組件文件放在了中,樣式奇丑,請(qǐng)?jiān)? /——————廣告開始——————/ 最近做了表格數(shù)據(jù)轉(zhuǎn)成圖表展示的一個(gè)react組件,地址如下: https://github.com/Lyla...

    happen 評(píng)論0 收藏0
  • vue地圖可視化 ArcGIS篇(3)

    摘要:不建議底圖選擇中存在兩種不同坐標(biāo)體系,如下圖坐標(biāo)存在明顯的偏差,火星坐標(biāo)在采用坐標(biāo)系的地圖上位置偏上彩色中國天地圖全球衛(wèi)星地圖例如我們使用的類進(jìn)行查找,返回的數(shù)據(jù)都是國際坐標(biāo),因此必須進(jìn)行偏差糾正。 ArcGIS for javascript開發(fā)心得 本次實(shí)例中采用ArcGIS for javascript3.24版本,由于版本3與4在API等存在較大區(qū)別,就不一一列舉,詳細(xì)區(qū)別看官方...

    oogh 評(píng)論0 收藏0
  • 開發(fā)一個(gè)基于 Vue2.0 的個(gè)人天氣預(yù)報(bào)

    摘要:本場(chǎng)是一個(gè)基于的個(gè)人天氣預(yù)報(bào)項(xiàng)目,就是興趣所致,做來玩玩。本項(xiàng)目會(huì)采用高德地圖,可視化庫和相關(guān)的技術(shù)來開發(fā)本項(xiàng)目。本場(chǎng)你將學(xué)到如下內(nèi)容學(xué)會(huì)制作自己的天氣預(yù)報(bào)學(xué)會(huì)使用部分高德地圖的學(xué)會(huì)使用的部分相關(guān)的一些技術(shù)。有興趣的請(qǐng)到查看效果圖如下 本場(chǎng) Chat 是一個(gè)基于 Vue 的個(gè)人天氣預(yù)報(bào)項(xiàng)目,就是興趣所致,做來玩玩。順便擴(kuò)展一下知識(shí)面。 本項(xiàng)目會(huì)采用高德地圖 API,Echarts 可視...

    mushang 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<