首页 > 其他分享 >百度地图区域绘制面

百度地图区域绘制面

时间:2022-12-02 10:00:29浏览次数:40  
标签:map assets 地图 let lat import lng 绘制 百度

<template>
  <div class="mapContainer">
    <!-- <div id="tMap" /> -->
    <div id="tMap" ref="tMap" />
  </div>
</template>

<script>
import { TDIMap, BaiduMap } from "@/utils/map.js";
import marki1 from "@/assets/map/i-1.png";
import marki2 from "@/assets/map/i-2.png";
import marki3 from "@/assets/map/i-3.png";
import marki4 from "@/assets/map/i-4.png";
import marki5 from "@/assets/map/i-5.png";
import marki6 from "@/assets/map/i-6.png";
import marki7 from "@/assets/map/i-7.png";
import markBg1 from "@/assets/map/m-t-bg1.png";
import markBg2 from "@/assets/map/m-t-bg2.png";
import markBg3 from "@/assets/map/m-t-bg3.png";
import markBg4 from "@/assets/map/m-t-bg4.png";
import markBg5 from "@/assets/map/m-t-bg5.png";
import markBg6 from "@/assets/map/m-t-bg6.png";
import markBg7 from "@/assets/map/m-t-bg7.png";
import mapdbg from "@/assets/dzdl/mapdbg.png";
import drawjson from "@/assets/json/1.json";
const $tdMap = null;

export default {
  name: "TdMap",
  props: {
    dataList: {
      type: Array,
      default: () => {
        return [
          {
            lat: "118.174014",
            lng: "30.732226",
            name: "这里是景区名称",
          },
        ];
      },
    },
  },
  data() {
    return {
      // lat: 30.930916,
      // lng: 118.344438,
      //118.17193,30.727538
      // lat: 30.927928,
      // lng: 118.194855,
      lat: 30.679277,
      lng: 118.140187,
      mapLevel: 14,
    };
  },
  watch: {
    dataList: {
      handler() {
        // this.initBaiDu();
        this.bgMark();
      },
      deep: true,
    },
  },
  mounted() {
    this.initBaiDu();
  },
  created() {},
  methods: {
    initBaiDu() {
      const _this = this;
      BaiduMap.init().then((BMap) => {
        _this.map = new BMapGL.Map(_this.$refs.tMap);
        _this.map.centerAndZoom(
          new BMapGL.Point(_this.lng, _this.lat),
          _this.mapLevel
        );
        // _this.map.addControl(
        //   new BMapGL.MapTypeControl({
        //     // mapTypes: [BMAP_NORMAL_MAP, BMAP_HYBRID_MAP], //图层类型+混合
        //     // mapTypes: [BMAP_NORMAL_MAP], //图层类型
        //     // anchor: BMAP_ANCHOR_TOP_LEFT, //切换按钮位置
        //   })
        // );
        _this.map.enableScrollWheelZoom();
        let zoomCtrl = new BMapGL.ZoomControl(); // 添加缩放控件
        _this.map.addControl(zoomCtrl);
        //地图个性化
        _this.map.setMapStyleV2({
          styleId: "2ab34170567eb610404d09569833f505",
        });
        //划区域
        _this.getBoundary();
      });
    },
    getBoundary() {
      const _this = this;
      // 绘制面-埃里村
      let mapArrys = [
        [
          // { lat: 118.11290981010475, lng: 30.63750677209448 },
          // { lat: 118.15085423484622, lng: 30.632037879849108 },
          // { lat: 118.18247458879745, lng: 30.661367374559234 },
          // { lat: 118.192248152746, lng: 30.69963133168712 },
          // { lat: 118.16465220747949, lng: 30.713044936540303 },
          // { lat: 118.12670778273801, lng: 30.70459955311886 },
          // { lat: 118.11233489457837, lng: 30.680252799658575 },
          [118.12474856744029, 30.703262278578094],
          [118.13063583662012, 30.70209411456956],
          [118.12859793573688, 30.69800543137113],
          [118.12225779965485, 30.69411128631431],
          [118.11727626416166, 30.686322524858355],
          [118.11840843132046, 30.68087001794811],
          [118.11501192984616, 30.676780435722165],
          [118.11003039435514, 30.676585689391388],
          [118.09961445650652, 30.660030816288184],
          [118.09508578787558, 30.65886212983648],
          [118.09372718728673, 30.656524714539245],
          [118.09667082189662, 30.651070525711418],
          [118.09463292101333, 30.641330137502294],
          [118.10187879081991, 30.64230422047129],
          [118.10527529229205, 30.647758903799797],
          [118.10912466062854, 30.650486130086406],
          [118.11093612807963, 30.65068092902024],
          [118.11569123014061, 30.65262889677608],
          [118.11795556445605, 30.65321327944926],
          [118.11840843132046, 30.651070525711418],
          [118.11999346533935, 30.65068092902024],
          [118.12135206592825, 30.648732922018326],
          [118.120899199066, 30.64347310708439],
          [118.12723933514798, 30.64834331590812],
          [118.12927723603133, 30.650875727561598],
          [118.1374288395644, 30.657303859252266],
          [118.1367495393099, 30.65886213046639],
          [118.14376897568638, 30.6668478728957],
          [118.14625974343198, 30.66606880512373],
          [118.1539584801028, 30.671522147616216],
          [118.15712854814484, 30.68612779840045],
          [118.16029861618489, 30.68632252548808],
          [118.16369511765703, 30.68749087976775],
          [118.16709161912917, 30.68671197848586],
          [118.16935595344461, 30.687296155036634],
          [118.16912952001451, 30.69430599792814],
          [118.16120434991143, 30.706571998012762],
          [118.14535400970743, 30.70832415645178],
          [118.12474856744029, 30.703262278578094],
        ],
      ];
      for (let i = 0; i < mapArrys.length; i++) {
        let mapAreas = [];
        for (let j = 0; j < mapArrys[i].length; j++) {
          mapAreas.push(new BMapGL.Point(mapArrys[i][j][0], mapArrys[i][j][1]));
        }
        console.log("mapAreas", mapAreas);
        let polygon = new BMapGL.Polygon(mapAreas, {
          strokeWeight: 3,
          strokeColor: "#13EBFF",
          strokeStyle: "dashed",
          fillColor: "#08304B",
          fillOpacity: 0.2,
        });
        _this.map.addOverlay(polygon);
      }
      //地图标点=========================
      _this.bgMark();
    },
    //坐标点标记
    bgMark() {
      let _this = this;
      const marArr = _this.dataList;
      let mark = "";
      let markBg = "";
      let colorBg = "";
      _this.removeMarkets();
      for (var i = 0; i < marArr.length; i++) {
        let type = marArr[i].type;
        switch (type) {
          case "1":
            mark = marki1;
            markBg = markBg1;
            colorBg = "#43E185";
            break;
          case "2":
            mark = marki2;
            markBg = markBg2;
            colorBg = "#FF9F2C";
            break;
          case "3":
            mark = marki3;
            markBg = markBg3;
            colorBg = "#44ACFF";
            break;
          case "4":
            mark = marki4;
            markBg = markBg4;
            colorBg = "#BD7AF2";
            break;
          case "5":
            mark = marki5;
            markBg = markBg5;
            colorBg = "#FF91E2";
            break;
          case "6":
            mark = marki6;
            markBg = markBg6;
            colorBg = "#1EE8FB";
            break;
          case "7":
            mark = marki7;
            markBg = markBg7;
            colorBg = "#FF6459";
            break;
          default:
            mark = marki1;
            markBg = markBg1;
            colorBg = "#43E185";
        }

        if (marArr[i].lat && marArr[i].lng) {
          _this.myIcon = new BMapGL.Icon(mark, new BMapGL.Size(42, 50));
          let marker = new BMapGL.Marker(
            new BMapGL.Point(marArr[i].lat, marArr[i].lng),
            {
              icon: _this.myIcon,
            }
          );
          _this.map.addOverlay(marker);
          // marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
          // 创建信息窗口
          let scont =
            "<div class='tcont' style='background-image:url(" +
            markBg +
            ");color:" +
            colorBg +
            "'>" +
            marArr[i].name +
            "</div>";
          let opts = {
            width: 150,
          };
          let infoWindow = new BMapGL.InfoWindow(scont, opts);
          // 点标记添加点击事件
          let point = new BMapGL.Point(marArr[i].lat, marArr[i].lng);
          marker.addEventListener("click", function () {
            _this.map.openInfoWindow(infoWindow, point); // 开启信息窗口
          });
        }
      }
    },
    //删除坐标
    removeMarkets() {
      let _this = this;
      let markers_gis = _this.map.getOverlays();
      if (markers_gis.length > 0) {
        for (let i = 0; i < markers_gis.length; i++) {
          _this.map.removeOverlay(markers_gis[i]);
        }
      }
      //清楚标点后再添加行政区域
      // 绘制面-埃里村
      let mapArrys = [
        [
          // { lat: 118.11290981010475, lng: 30.63750677209448 },
          // { lat: 118.15085423484622, lng: 30.632037879849108 },
          // { lat: 118.18247458879745, lng: 30.661367374559234 },
          // { lat: 118.192248152746, lng: 30.69963133168712 },
          // { lat: 118.16465220747949, lng: 30.713044936540303 },
          // { lat: 118.12670778273801, lng: 30.70459955311886 },
          // { lat: 118.11233489457837, lng: 30.680252799658575 },
          [118.12474856744029, 30.703262278578094],
          [118.13063583662012, 30.70209411456956],
          [118.12859793573688, 30.69800543137113],
          [118.12225779965485, 30.69411128631431],
          [118.11727626416166, 30.686322524858355],
          [118.11840843132046, 30.68087001794811],
          [118.11501192984616, 30.676780435722165],
          [118.11003039435514, 30.676585689391388],
          [118.09961445650652, 30.660030816288184],
          [118.09508578787558, 30.65886212983648],
          [118.09372718728673, 30.656524714539245],
          [118.09667082189662, 30.651070525711418],
          [118.09463292101333, 30.641330137502294],
          [118.10187879081991, 30.64230422047129],
          [118.10527529229205, 30.647758903799797],
          [118.10912466062854, 30.650486130086406],
          [118.11093612807963, 30.65068092902024],
          [118.11569123014061, 30.65262889677608],
          [118.11795556445605, 30.65321327944926],
          [118.11840843132046, 30.651070525711418],
          [118.11999346533935, 30.65068092902024],
          [118.12135206592825, 30.648732922018326],
          [118.120899199066, 30.64347310708439],
          [118.12723933514798, 30.64834331590812],
          [118.12927723603133, 30.650875727561598],
          [118.1374288395644, 30.657303859252266],
          [118.1367495393099, 30.65886213046639],
          [118.14376897568638, 30.6668478728957],
          [118.14625974343198, 30.66606880512373],
          [118.1539584801028, 30.671522147616216],
          [118.15712854814484, 30.68612779840045],
          [118.16029861618489, 30.68632252548808],
          [118.16369511765703, 30.68749087976775],
          [118.16709161912917, 30.68671197848586],
          [118.16935595344461, 30.687296155036634],
          [118.16912952001451, 30.69430599792814],
          [118.16120434991143, 30.706571998012762],
          [118.14535400970743, 30.70832415645178],
          [118.12474856744029, 30.703262278578094],
        ],
      ];
      for (let i = 0; i < mapArrys.length; i++) {
        let mapAreas = [];
        for (let j = 0; j < mapArrys[i].length; j++) {
          mapAreas.push(new BMapGL.Point(mapArrys[i][j][0], mapArrys[i][j][1]));
        }
        console.log("mapAreas", mapAreas);
        let polygon = new BMapGL.Polygon(mapAreas, {
          strokeWeight: 3,
          strokeColor: "#13EBFF",
          strokeStyle: "dashed",
          fillColor: "#08304B",
          fillOpacity: 0.2,
        });
        _this.map.addOverlay(polygon);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.mapContainer {
  width: 100%;
  z-index: 4;
  height: 100%;
}
#tMap {
  width: 100%;
  height: 100%;
}
</style>

 

标签:map,assets,地图,let,lat,import,lng,绘制,百度
From: https://www.cnblogs.com/Byme/p/16943519.html

相关文章

  • 百度地图手绘标点
    <template><divclass="mapContainer"><!--<divid="tMap"/>--><divid="tMap"ref="tMap"/></div></template><script>import{TDIMap,BaiduM......
  • origin绘制倒立双y轴图
    1,先选中正向表示的数据,画成柱状图 2.画倒立的第二张,选中数据,画图   更改成倒立形式,右键图2的y坐标,在刻度>>>>反转>>>>勾选反转 3.合并两张图,在右边工具栏......
  • 腾讯、阿里、百度等互联网巨头究竟如何布局元宇宙的?
                  元宇宙这个新兴概念空降2021,相关概念股一路高涨,并且还成为了“汉语盘点2021”年度词与2021年度十大网络用语词汇,而元宇宙不仅仅激发了大家的好......
  • (电商中需要定位需求)百度地图定位sdk集成,及城市列表展示,选择,搜索,26字母快速定位
    (电商中需要定位需求)百度地图定位sdk集成,及城市列表展示,选择,搜索,26字母快速定位下面集成步骤:主要还是依靠百度定位文档一步一步1,先去百度开发者平台,创建你的应用,根据你的......
  • 遗传算法可视化项目(7):地图装饰
    前天讲了用PyQt5实现数据可视化,也已经基本讲完整个项目了,没有看之前文章或者今天才关注的可以看一下历史消息或者点击这里:​​遗传算法可视化项目(1):概述​​​​遗传算法可视......
  • 快速绘制流程图「GitHub 热点速览 v.22.47」
    画流程图一直是研发的一个难题,如何画得通俗易懂已经够让人头疼了,还要美观大方。用d2的语法描述下流程,d2会自动帮你生成一张配色极佳的流程图。说到研发的选择,本周特推......
  • Golang实现小型CMS内容管理功能(二):前端接入百度ueditor富文本编辑器
    当我们把接口都做好以后,我们需要去开发前端界面。添加文章功能里面,最重要的就是文章内容部分,需要配置上富文本编辑器,这样才能给我们的内容增加样式。 下载ueditor代码......
  • echarts中国地图
    initMap(){echarts.registerMap('china',JSON.stringify(this.china));varopeChars1=echarts.init(document.querySelector("#mapBox"));......
  • ArcObjects SDK开发 008 从mxd地图文件说起
    1、Mxd文件介绍ArcGIS的地图文件为.mxd扩展名。Mxd文件的是有版本的,和ArcGIS的版本对应。可以在ArcMap中的File-SaveACopy,保存一个地图拷贝的时候选择Mxd文件的版本,支持......
  • 使用百度ai制作动漫头像
    1、在百度上申请注册属于自己的idhttps://ai.baidu.com/tech/imageprocess/selfie_anime2、在控制台中的「免费尝鲜」领取全部福利。如果不领取,程序会报错「Openapichar......