这里给使用高德地图下钻提供一个思路
先讲下我的思路,高德地图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使用高德地图点击下钻上浮效果的实现思路,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 战锤40K星际战士2狙击职业介绍|狙击职业技能效果一览
- RobertSaxtonTheResurrectionoftheSoldiers(2024)[24Bit-192kHz]FLAC
- 唐成杨东哥弹唱《情若真HQ》头版限量编号[WAV+CUE]
- 柏菲·HIFI风情1《一杯香茶》限量开盘母带ORMCD[WAV+CUE]
- 发糖了!《黑神话》动画导演绘制八戒紫蛛儿中秋贺图
- “时光系列”新作《时光3:永耀之境》首曝:画风更真实的恋爱模拟RPG
- 《战地》游戏主管:始终认为《战地》未来销量能超越《使命召唤》
- 《伤感民谣 值得收藏的音乐极品 2CD》[WAV/分轨][1.2GB]
- 《邓紫棋 巨肺唱将小天后有心人 2CD》[WAV/分轨][1.2GB]
- 《迪克牛仔 坛奇精选 2CD台首版》 [WAV+CUE][600MB]
- 陈明.1998-为了爱影视歌曲+新歌【中唱】【WAV+CUE】
- 黄小琥.2009-简单/不简单【华纳】【WAV+CUE】
- 洪卓立.2010-TASTE.OF.LOVE新曲+精丫英皇娱乐】【WAV+CUE】
- 战锤40K星际战士2职业强度排行
- 交错战线PVE国家队成员以及常用角色推荐