vue使用高德地圖點(diǎn)擊下鉆上浮效果的實(shí)現(xiàn)思路
這里給使用高德地圖下鉆提供一個(gè)思路
先講下我的思路,高德地圖api有一個(gè)地圖繪制區(qū)域,你只要提供區(qū)碼,就可以繪制該區(qū)域。以浙江省為例,我一開給浙江省的區(qū)碼就可以繪制出浙江省的區(qū)域,接下來我要進(jìn)入杭州市,當(dāng)我點(diǎn)擊杭州市的時(shí)候我先清空地圖上的覆蓋層并且能獲取到‘杭州市'這個(gè)字符串,通過對(duì)比這個(gè)字符串我就可以給出杭州市的區(qū)碼,最后繪制出杭州市的覆蓋層。
接下來看代碼:
第一步
繪制地圖:
//創(chuàng)建地圖
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
});
第二步(關(guān)鍵)
let that = this;
AMapUI.loadUI(["geo/DistrictExplorer"], DistrictExplorer => {
//創(chuàng)建一個(gè)實(shí)例
that.districtExplorer = new DistrictExplorer({
eventSupport: true,
map: this.map
});
//設(shè)置繪制的子區(qū)域和父區(qū)域的自身屬性(包括線顏色,透明度等)執(zhí)行renderAreaNode()就可以開始繪制區(qū)域了
function renderAreaNode(areaNode) {
//繪制子級(jí)區(qū)劃
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 //填充透明度
};
});
//繪制父區(qū)域
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 = [];
// //根據(jù)角色來繪制不同的區(qū)域
// that.adcodes = [
// 330200 //浙江
// ];
that.map.clearMap(); //清空所有繪制物
//繪制多區(qū)域
that.districtExplorer.loadMultiAreaNodes(this.adcodes, function(
error,
areaNodes
) {
//設(shè)置定位節(jié)點(diǎn),支持鼠標(biāo)位置識(shí)別
//注意節(jié)點(diǎn)的順序,前面的高優(yōu)先級(jí)
that.districtExplorer.setAreaNodesForLocating(areaNodes);
//清除已有的繪制內(nèi)容
that.districtExplorer.clearFeaturePolygons();
for (var i = 0, len = areaNodes.length; i < len; i++) {
renderAreaNode(areaNodes[i]);
}
//更新地圖視野
that.map.setFitView(that.districtExplorer.getAllFeaturePolygons());
});
//添加點(diǎn)標(biāo)記
that.addMarker(data);
});
this.adcodes是區(qū)碼,這里的關(guān)鍵在于清空,利用好 that.map.clearMap(); //清空所有繪制物 再重新進(jìn)行繪制,再通過 that.map.setFitView(that.districtExplorer.getAllFeaturePolygons()); 就可以達(dá)到下鉆的效果,上浮也是同理。
區(qū)碼以浙江省為例
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 == "臺(tái)州市") {
this.adcodes = [331000];
} else if (data.result.rows[0].cities_name == "麗水市") {
this.adcodes = [331100];
}
總結(jié)
以上所述是小編給大家介紹的vue使用高德地圖點(diǎn)擊下鉆上浮效果的實(shí)現(xiàn)思路,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
- vue+高德地圖實(shí)現(xiàn)地圖搜索及點(diǎn)擊定位操作
- 最全vue的vue-amap使用高德地圖插件畫多邊形范圍的示例代碼
- vue項(xiàng)目使用高德地圖的定位及關(guān)鍵字搜索功能的實(shí)例代碼(踩坑經(jīng)驗(yàn))
- 在vue中高德地圖引入和軌跡的繪制的實(shí)現(xiàn)
- vue 使用高德地圖vue-amap組件過程解析
- vue使用高德地圖根據(jù)坐標(biāo)定位點(diǎn)的實(shí)現(xiàn)代碼
- Vue組件之高德地圖地址選擇功能的實(shí)例代碼
- Vue-Cli 3.0 中配置高德地圖的兩種方式
- vue+高德地圖寫地圖選址組件的方法
- 在vue項(xiàng)目中引入高德地圖及其UI組件的方法
- 前端vue如何使用高德地圖
相關(guān)文章
vue自動(dòng)路由-單頁面項(xiàng)目(非build時(shí)構(gòu)建)
這篇文章主要介紹了vue自動(dòng)路由-單頁面項(xiàng)目(非build時(shí)構(gòu)建),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-04-04
基于Vue中this.$options.data()的this指向問題
這篇文章主要介紹了基于Vue中this.$options.data()的this指向問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-03-03
深入理解vue輸入框字符限制的優(yōu)化設(shè)計(jì)方案
限制輸入框字符是一項(xiàng)需要結(jié)合技術(shù)實(shí)現(xiàn)與用戶體驗(yàn)的綜合設(shè)計(jì),通過實(shí)時(shí)限制、提交校驗(yàn)與性能優(yōu)化,開發(fā)者可以高效解決輸入限制問題,同時(shí)提升用戶滿意度和數(shù)據(jù)安全性,本文給大家介紹vue輸入框字符限制的優(yōu)化設(shè)計(jì),感興趣的朋友跟隨小編一起看看吧2024-12-12
vue實(shí)現(xiàn)選項(xiàng)卡及選項(xiàng)卡切換效果
這篇文章主要介紹了vue實(shí)現(xiàn)選項(xiàng)卡選項(xiàng)卡切換效果,這里的Vue以單文件的形式引入,另外代碼在實(shí)現(xiàn)上會(huì)一步步的進(jìn)行優(yōu)化。需要的朋友可以參考下2018-04-04
vant-list組件觸發(fā)多次onload事件導(dǎo)致數(shù)據(jù)亂序的解決方案
這篇文章主要介紹了vant-list組件觸發(fā)多次onload事件導(dǎo)致數(shù)據(jù)亂序的解決方案2023-01-01
vue導(dǎo)航欄部分的動(dòng)態(tài)渲染實(shí)例
今天小編就為大家分享一篇vue導(dǎo)航欄部分的動(dòng)態(tài)渲染實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-11-11

