当前位置: 首页 > news >正文

精品课网站建设html模板网

精品课网站建设,html模板网,现在那个网站做宣传有效果,做网站基本要求最近接到一个新需要#xff0c;要求如下#xff1a; 当我点击选择地址时#xff0c;弹出百度地图#xff0c; 效果如下图#xff1a; 实现方法#xff1a; 1、首先要在百度地图开放平台去申请一个账号和key 2、申请好之后#xff0c;在项目的index.html中引入 3、…最近接到一个新需要要求如下 当我点击选择地址时弹出百度地图 效果如下图 实现方法 1、首先要在百度地图开放平台去申请一个账号和key 2、申请好之后在项目的index.html中引入 3、我写了一个组件方便项目中任何地方可以调用 这里一定要设置一个宽高容器才能更好的适应不然显示出来达不到想要的效果如果没有设置高度还可能显示不出来 4、接下来就是开始初始化地图设置了我的是在弹窗里面用所有我写在watch里面的当监测到弹窗打开时即开始初始化地图页面 5、具体方法如下 直接附上源码 template langhtmlel-dialog v-dialogDrag title选择地点 append-to-body width800px :visible.syncmvisible :close-on-click-modalfalseclosecanceldiv idamap-containerel-rowel-col :span14formatForm refbasicInfoForm classbasicForm :form-listbasicInfoList :form-validatebasicFormValidate //el-colel-col :span10el-inputidsearch-inputv-modelsearchValueclassinput-withplaceholder请输入详细地址clearableclearhandelclearInputkeyup.native.enteronhandelSearchel-buttonslotappendsizesmalltypeprimaryiconel-icon-searchclickonhandelSearch搜索/el-button/el-input/el-col/el-rowel-row classmargin-top-10 address当前地址是 {{ addressName }}{{ searchValue }}/el-rowdiv idmapBox //divdiv slotfooter classdialog-footerel-button typeprimary clickhandelSave保 存/el-buttonel-button clickcancel取 消/el-button/div/el-dialog /templatescript import { cleanChildrenEmpty } from /utils/filterArrayData import { getAddressName } from /utils/getAddressName import { selectRequired } from /utils/formRules // import AMapLoader from amap/amap-jsapi-loader import region from /static/json/region.json import formatForm from /components/formatForm/index // import { BMap } from vue-baidu-map/types // const BMapGL require(vue-baidu-map/types/map) let BMapGL {} let map {} const addressOption cleanChildrenEmpty(region, children) export default {name: AMap,components: { formatForm },props: {businessProvinceId: {type: Array,default: () []},defaultValue: {type: String,default: },visible: {type: Boolean,default: false}},data() {const that thisreturn {mvisible: false,defaultCity: ,// 地址对应的经纬度信息lat: ,lng: ,// 检索关键字searchValue: ,// 地址名称adcode: ,basicInfoList: {span: 24,title: ,labelWidth: 70px,isColon: true,list: [{type: cascader,exist: true,fieldName: 省市区,fieldEName: businessProvinceId,expandTrigger: hover,label: name,value: id,placeholder: 请选择省市区,options: addressOption,rules: [selectRequired],change: res {this.addressName res.length ? getAddressName(res, addressOption).name : this.onhandelSearch()}}]},basicFormValidate: {businessProvinceId: []},addressName: ,district: ,newDistrict: }},watch: {defaultValue() {this.searchValue this.defaultValue},visible() {this.mvisible this.visiblethis.searchValue this.defaultValueconsole.log(this.businessProvinceId.length, this.defaultValue)this.basicFormValidate.businessProvinceId this.businessProvinceId || []this.addressName this.businessProvinceId.length !this.defaultValue ? getAddressName(this.businessProvinceId, addressOption).name : const oldDistrict this.businessProvinceId.length !this.defaultValue ? (getAddressName(this.businessProvinceId, addressOption).name2).split(-) : []this.district oldDistrict.length ? oldDistrict[oldDistrict.length - 1] : this.$nextTick(() {// 初始化地图页面this.initMap()})}},beforeDestroy() {// 销毁地图// this.map.destroy()},methods: {initMap() {BMapGL window.BMapGLmap new BMapGL.Map(mapBox) // 创建Map实例map.centerAndZoom(new BMapGL.Point(116.404, 39.915), 12) // 初始化地图,设置中心点坐标和地图级别map.enableScrollWheelZoom(true) // 开启鼠标滚轮缩放console.log(this.addressName, this.addressName)const center this.addressNamemap.setCenter(center)this.getPoint()this.getClickMapIp()// // 添加maker// this.setMaker()// // 添加鼠标点选地图选择地址// this.addAmapGeocoder()// this.onhandelSearch()},getPoint() {const center this.addressName || this.searchValueconst myGeo new BMapGL.Geocoder()myGeo.getPoint(center, (point) {if (point) {map.centerAndZoom(point, 12)map.addOverlay(new BMapGL.Marker(point, { title: center }))} else {alert(您选择的地址没有解析到结果)}}, this.addressName)},getClickMapIp() {map.addEventListener(click, (e) {console.log(e----, e)this.lat e.latlng.latthis.lng e.latlng.lngconst point new BMapGL.Point(this.lng, this.lat)map.centerAndZoom(point, 12) // 初始化地图,设置中心点坐标和地图级别this.setMarker(point)// 指定经纬度获取地址this.getLocation(point)})},// 添加markersetMarker(new_point) {map.clearOverlays()const marker new BMapGL.Marker(new_point)map.addOverlay(marker) // 将标注添加到地图中map.panTo(new_point)},// 获取地址getLocation(pt) {// 创建地理编码实例const myGeo new BMapGL.Geocoder()console.log(myGeo, myGeo)myGeo.getLocation(pt, (re) {const { province, city, district, street, streetNumber } re.addressComponents || {}this.newDistrict districtthis.addressName ${province || }${city || }${district || }this.searchValue ${street || }${streetNumber || }console.log(getLocation, re)// this.getCityCode(district)})},getCityCode(city) {console.log(city, city)const myCity new BMapGL.Geolocation()console.log(myCity, myCity)myCity.getCityCode(city, res {console.log(getCurrentPosition, res)})},// 按钮触发检索onhandelSearch() {const local new BMapGL.LocalSearch(map, {renderOptions: { map: map }})const address this.addressName this.searchValuelocal.search(address)},handelclearInput() {this.searchValue },// 保存当前选择的地址,分发事件handelSave() {const { newDistrict, district, lat, lng } thisconst { businessProvinceId } this.basicFormValidateconsole.log(businessProvinceId, businessProvinceId)const s district ? district newDistrict : trueif (businessProvinceId.length 3 lat lng s) {const x_pi 3.14159265358979324 * 3000.0 / 180.0const x lng - 0.0065const y lat - 0.006const z Math.sqrt(x * x y * y) - 0.00002 * Math.sin(y * x_pi)const theta Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi)const lngs z * Math.cos(theta)const lats z * Math.sin(theta)const data {name: this.name,businessProvinceId,// 地址名称address: this.formattedAddress,// 纬度latlat: lats,// 经度lnglng: lngs}this.$emit(getPosition, true, data)} else {this.$message.error(当前地址不在省市区范围内请重新选择)}},cancel() {this.$emit(getPosition, false)}} } /scriptstyle scoped langscss #amap-container {margin: 20px;.el-input__clear {line-height: 34px;/*top: 20px;*/}#mapBox {height: 35vh;width: 100%;margin-top: 10px;border: 1px solid #ccc;}.input-with {/*position: fixed;*//*top: 40px;*/z-index: 1;width: 580px;}.address {color: #373737;}}.amap-sug-result {z-index: 99999; }.baseForm.format_form {margin: 0 !important; } /style 根据项目需求做调整即可。 好了就这样吧助人达已爱分享爱学习做一个快乐的前端小姐姐 如有更好的方法欢迎交流
http://www.tj-hxxt.cn/news/231210.html

相关文章:

  • 网站开发国际化具有价值的做pc端网站
  • 开源程序做网站建站行业的乱象
  • 网站建设论文的部首济南行知网网站建设
  • 东莞厚街做网站新郑市住房建设局网站
  • c 网站开发案例详解光盘网站推广神器
  • 营销型网站 开源程序天眼查企业查询下载
  • 深圳营销型网站公司电话网站制度建设情况
  • 诚信通开了网站谁给做网店怎么经营才能好啊
  • 电子商务网站建设心得体会具有价值的网站建设平台
  • 太原做网站页面的唯样商城
  • 电商网站设计与开发精致的网站
  • 北京的网站设计泰安网络电视
  • 做网站挣钱么如何安装字体wordpress
  • 诸城网站优化在百度上做网站推广怎么弄
  • 做网店好还是网站蚌埠网络推广
  • 商城网站模版代码济南营销型网站
  • 网站建设四个阶段的流程域名注册查询软件
  • 网站建设 成都今网科技海南营销型网站建设
  • 移动网站建设案例网站开发用的那些语言
  • dw做网站字体 别人 电脑Wordpress禁止搜索内容
  • 建设网站请示宣传wordpress 扫描工具
  • 有没有免费制作网站的免费的cms有哪些平台
  • 3合1网站建设哪家好网站开发工具是什么
  • 企业网站建设存在的典型问题有哪些?制作一个网站代码
  • 佛山企业网站建设咨询wordpress企业文化模板
  • 上海网站制作顾长沙网站建设公司有哪些
  • 加盟什么网站建设个人博客网站开发背景论文
  • 网站程序开发的基本步骤快速的宝安网站建设
  • php做的网站模板下载在线看网站源码
  • 静态网站开发实验报告快速学习网站建设