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 相关文章推荐
JS input文本框禁用右键和复制粘贴功能的代码
Apr 15 Javascript
js getElementsByTagName的简写方式
Jun 27 Javascript
利用百度地图JSAPI生成h7n9禽流感分布图实现代码
Apr 15 Javascript
JS实现图片高亮展示效果实例
Nov 24 Javascript
JavaScript实现各种排序的代码详解
Aug 28 Javascript
jquery实现倒计时小应用
Sep 19 jQuery
Angular4.0中引入laydate.js日期插件的方法教程
Dec 25 Javascript
纯JS实现出生日期[年月日]下拉菜单效果
Jun 01 Javascript
vue移动端城市三级联动组件使用详解
Jul 26 Javascript
为react组件库添加typescript类型提示的方法
Jun 15 Javascript
基于Vue3.0开发轻量级手机端弹框组件V3Popup的场景分析
Dec 30 Vue.js
如何管理Vue中的缓存页面
Feb 06 Vue.js
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源码之 ext/mysql扩展部分
2009/07/17 PHP
PHP 简单数组排序实现代码
2009/08/05 PHP
PHP 动态生成静态HTML页面示例代码
2014/01/15 PHP
ThinkPHP 模板substr的截取字符串函数详解
2017/01/09 PHP
浅谈php使用curl模拟多线程发送请求
2019/03/08 PHP
laravel框架实现敏感词汇过滤功能示例
2020/02/15 PHP
很多人都是用下面的js刷新站IP和PV
2008/09/05 Javascript
深入理解javascript学习笔记(一) 编写高质量代码
2012/08/09 Javascript
JS控件的生命周期介绍
2012/10/22 Javascript
js和as的稳定传值问题解决
2013/07/14 Javascript
JavaScript实现简单的时钟实例代码
2013/11/23 Javascript
基于bootstrap3和jquery的分页插件
2015/07/31 Javascript
深入学习JavaScript中的原型prototype
2015/08/13 Javascript
jQuery下拉菜单的实现代码
2016/11/03 Javascript
easyui form validate总是返回false的原因及解决方法
2016/11/07 Javascript
JS正则截取两个字符串之间及字符串前后内容的方法
2017/01/06 Javascript
微信小程序页面传值实例分析
2017/04/19 Javascript
微信禁止下拉查看URL的处理方法
2017/09/28 Javascript
vue中v-for加载本地静态图片方法
2018/03/03 Javascript
js实现贪吃蛇游戏 canvas绘制地图
2020/09/09 Javascript
深入解析Python中的__builtins__内建对象
2016/06/21 Python
Python实现统计文本文件字数的方法
2017/05/05 Python
解决Pycharm出现的部分快捷键无效问题
2018/10/22 Python
Python 从一个文件中调用另一个文件的类方法
2019/01/10 Python
Python 实现交换矩阵的行示例
2019/06/26 Python
一行python实现树形结构的方法
2019/08/09 Python
Django 请求Request的具体使用方法
2019/11/11 Python
python math模块的基本使用教程
2021/01/16 Python
优秀的自荐信要注意哪些
2014/01/03 职场文书
先进党支部事迹材料
2014/01/13 职场文书
超市重阳节活动方案
2014/02/10 职场文书
党员干部一句话承诺
2014/05/30 职场文书
高中教师先进事迹材料
2014/08/22 职场文书
少年的你:世界上没有如果,要在第一次就勇敢的反抗
2019/11/20 职场文书
pdf论文中python画的图Type 3 fonts字体不兼容的解决方案
2021/04/24 Python
python使用matplotlib绘制图片时x轴的刻度处理
2021/08/30 Python