vue使用高德地图点击下钻上浮效果的实现思路


Posted in Javascript onOctober 12, 2019

这里给使用高德地图下钻提供一个思路

先讲下我的思路,高德地图api有一个地图绘制区域,你只要提供区码,就可以绘制该区域。以浙江省为例,我一开给浙江省的区码就可以绘制出浙江省的区域,接下来我要进入杭州市,当我点击杭州市的时候我先清空地图上的覆盖层并且能获取到‘杭州市'这个字符串,通过对比这个字符串我就可以给出杭州市的区码,最后绘制出杭州市的覆盖层。
接下来看代码:

第一步

绘制地图:

//创建地图
  this.map = new AMap.Map("container", {
   cursor: "default",
   resizeEnable: true,
   expandZoomRange: true,
   gestureHandling: "greedy",
   // zooms: [8, 20],
   zoom: 12,
   defaultCursor: "pointer",
   mapStyle: "amap://styles/f6e3818366ba5268d50ea3f2296eb3eb",
   showLabel: true
  });

第二步(关键)

let that = this;
  AMapUI.loadUI(["geo/DistrictExplorer"], DistrictExplorer => {
   //创建一个实例
   that.districtExplorer = new DistrictExplorer({
   eventSupport: true,
   map: this.map
   });

   //设置绘制的子区域和父区域的自身属性(包括线颜色,透明度等)执行renderAreaNode()就可以开始绘制区域了
   function renderAreaNode(areaNode) {
   //绘制子级区划
   that.districtExplorer.renderSubFeatures(areaNode, function(
    feature,
    i
   ) {
    return {
    cursor: "default",
    bubble: true,
    // strokeColor: "#00a4ce", //线颜色
    strokeColor: "#03d7a1",
    strokeOpacity: 1, //线透明度
    strokeWeight: 1.5, //线宽
    // fillColor: "#09152a", //填充色
    fillColor: "#072942",
    fillOpacity: 0.1 //填充透明度
    };
   });
   //绘制父区域
   that.districtExplorer.renderParentFeature(areaNode, {
    cursor: "default",
    bubble: true,
    // strokeColor: "#00a4ce", //线颜色
    strokeColor: "#03d7a1",
    strokeOpacity: 1, //线透明度
    strokeWeight: 1.5, //线宽
    // fillColor: "#09152a", //填充色
    fillColor: "#072942",
    fillOpacity: 0.6 //填充透明度
   });
   }

   // var adcodes = [];
   // //根据角色来绘制不同的区域
   // that.adcodes = [
   // 330200 //浙江
   // ];
   that.map.clearMap(); //清空所有绘制物
   //绘制多区域
   that.districtExplorer.loadMultiAreaNodes(this.adcodes, function(
   error,
   areaNodes
   ) {
   //设置定位节点,支持鼠标位置识别
   //注意节点的顺序,前面的高优先级
   that.districtExplorer.setAreaNodesForLocating(areaNodes);
   //清除已有的绘制内容
   that.districtExplorer.clearFeaturePolygons();
   for (var i = 0, len = areaNodes.length; i < len; i++) {
    renderAreaNode(areaNodes[i]);
   }
   //更新地图视野
   that.map.setFitView(that.districtExplorer.getAllFeaturePolygons());
   });
   //添加点标记
   that.addMarker(data);
  });

this.adcodes是区码,这里的关键在于清空,利用好 that.map.clearMap(); //清空所有绘制物 再重新进行绘制,再通过 that.map.setFitView(that.districtExplorer.getAllFeaturePolygons()); 就可以达到下钻的效果,上浮也是同理。

区码以浙江省为例

if (data.result.rows[0].cities_name == "杭州市") {
   this.adcodes = [330100];
   } else if (data.result.rows[0].cities_name == "宁波市") {
   this.adcodes = [330200];
   } else if (data.result.rows[0].cities_name == "温州市") {
   this.adcodes = [330300];
   } else if (data.result.rows[0].cities_name == "嘉兴市") {
   this.adcodes = [330400];
   } else if (data.result.rows[0].cities_name == "湖州市") {
   this.adcodes = [330500];
   } else if (data.result.rows[0].cities_name == "绍兴市") {
   this.adcodes = [330600];
   } else if (data.result.rows[0].cities_name == "金华市") {
   this.adcodes = [330700];
   } else if (data.result.rows[0].cities_name == "衢州市") {
   this.adcodes = [330800];
   } else if (data.result.rows[0].cities_name == "舟山市") {
   this.adcodes = [330900];
   } else if (data.result.rows[0].cities_name == "台州市") {
   this.adcodes = [331000];
   } else if (data.result.rows[0].cities_name == "丽水市") {
   this.adcodes = [331100];
   }

总结

以上所述是小编给大家介绍的vue使用高德地图点击下钻上浮效果的实现思路,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

Javascript 相关文章推荐
Stop SQL Server
Jun 21 Javascript
dojo学习第一天 Tab选项卡 实现
Aug 28 Javascript
Bootstrap+jfinal退出系统弹出确认框的实现方法
May 30 Javascript
Javascript之Math对象详解
Jun 07 Javascript
JavaScript面试题(指针、帽子和女朋友)
Nov 23 Javascript
总结js中的一些兼容性易错的问题
Dec 18 Javascript
js中let和var定义变量的区别
Feb 08 Javascript
vue 自定义全局方法,在组件里面的使用介绍
Feb 28 Javascript
微信小程序用户授权弹窗 拒绝时引导用户重新授权实现
Jul 29 Javascript
基于Vue的商品主图放大镜方案详解
Sep 19 Javascript
Vue中图片Src使用变量的方法
Oct 30 Javascript
原生JS实现相邻月份日历
Oct 13 Javascript
Vue.js计算机属性computed和methods方法详解
Oct 12 #Javascript
微信小程序 导入图标实现过程详解
Oct 11 #Javascript
在vue中高德地图引入和轨迹的绘制的实现
Oct 11 #Javascript
vue实现点击按钮下载文件功能
Oct 11 #Javascript
浅谈TypeScript 用 Webpack/ts-node 运行的配置记录
Oct 11 #Javascript
详解vue 自定义组件使用v-model 及探究其中原理
Oct 11 #Javascript
JsonProperty 的使用方法详解
Oct 11 #Javascript
You might like
php实现webservice实例
2014/11/06 PHP
php header函数的常用http头设置
2015/06/25 PHP
php使用pecl方式安装扩展操作示例
2019/08/12 PHP
javascript 字符 Escape,encodeURI,encodeURIComponent
2009/07/09 Javascript
基于Jquery的文字滚动跑马灯插件(一个页面多个滚动区)
2010/07/26 Javascript
JS.findElementById()使用介绍
2013/09/21 Javascript
浅析用prototype定义自己的方法
2013/11/14 Javascript
jquery ajax 简单范例(界面+后台)
2013/11/19 Javascript
js子页面获取父页面数据示例
2014/05/15 Javascript
纯javascript模仿微信打飞机小游戏
2015/08/20 Javascript
非常酷炫的Bootstrap图片轮播动画
2016/05/27 Javascript
nodejs入门教程三:调用内部和外部方法示例
2017/04/24 NodeJs
浅谈原型对象的常用开发模式
2017/07/22 Javascript
JavaScript文本特效实例小结【3个示例】
2018/12/22 Javascript
echarts多条折线图动态分层的实现方法
2019/05/24 Javascript
扫微信小程序码实现网站登陆实现解析
2019/08/20 Javascript
vue实现导航标题栏随页面滚动渐隐渐显效果
2020/03/12 Javascript
JS中的继承操作实例总结
2020/06/06 Javascript
python求斐波那契数列示例分享
2014/02/14 Python
pyqt4教程之widget使用示例分享
2014/03/07 Python
python将ansible配置转为json格式实例代码
2017/05/15 Python
使用python爬虫实现网络股票信息爬取的demo
2018/01/05 Python
Selenium元素的常用操作方法分析
2018/08/10 Python
python_opencv用线段画封闭矩形的实例
2018/12/05 Python
Python Excel处理库openpyxl使用详解
2019/05/09 Python
Python程序打包工具py2exe和PyInstaller详解
2019/06/28 Python
python3实现斐波那契数列(4种方法)
2019/07/15 Python
python判断自身是否正在运行的方法
2019/08/08 Python
jupyter notebook 的工作空间设置操作
2020/04/20 Python
Opencv求取连通区域重心实例
2020/06/04 Python
python实现批处理文件
2020/07/28 Python
美国最大的珠宝商之一:Littman Jewelers
2016/11/13 全球购物
原来闭幕词是这样写的呀!
2019/07/01 职场文书
解决pycharm安装scrapy DLL load failed:找不到指定的程序的问题
2021/06/08 Python
python可视化大屏库big_screen示例详解
2021/11/23 Python
Python读写yaml文件
2022/03/20 Python