做涂鸦的网站,wordpress发文章后显示两篇,h5开发移动端app,昆山便宜做网站效果#xff1a;点击表格可实现选中地图点位#xff0c;删除按钮点击可删除对应点位并且重新绘制线段#xff0c;点击确定按钮 保存已经绘制的点位信息传给父组件 并且该组件已实现回显 完整的组件代码如下 文件名称为#xff1a; leafletMakePointYt !--* Descripti… 效果点击表格可实现选中地图点位删除按钮点击可删除对应点位并且重新绘制线段点击确定按钮 保存已经绘制的点位信息传给父组件 并且该组件已实现回显 完整的组件代码如下 文件名称为 leafletMakePointYt !--* Description: leaflet 地图选择点位 实现画线 页面* Author: mhf* Date: 2023-05-30 18:23:37
--
templateel-dialogwidth1300pxappend-to-bodyv-dialog-outv-ifdialogVisible:titletitle:visible.syncdialogVisible:close-on-click-modalfalse:before-closehideDialogdiv!-- 地图盒子 --div idmap/div!-- 左侧坐标展示框 --div classpoints-box!-- 顶部标题 --div classpoints-box-titlespan 线路坐标 /span/div!-- 坐标展示表 --div classpoints-box-tableel-tablehighlight-current-rowcurrent-changehandleCurrentChange:datapointsArrstylewidth: 100%:heighttableHeightel-table-column label# typeindex /el-table-column proplat label经度 width158 /el-table-column proplng label纬度 width158 /el-table-columnlabel操作width60fixedrightv-ifshowBtntemplate slot-scopescopeel-button typetext sizesmall clickdelRow(scope)删除/el-button/template/el-table-column/el-table/div!-- 坐标盒子 底部按钮组 --div v-ifshowBtn classpoints-box-btnel-button type size clickclearMapLine 清除/el-buttonel-button typeprimary size clickmakeMapLine开始/el-buttonel-button typeprimary size clickendMakeLine结束/el-button/div/div/div!-- 弹窗底部按钮组 --div v-ifshowBtn slotfooter classdialog-footerel-button clickhideDialog取 消/el-buttonel-button typeprimary clicksubmitPoints()确 定/el-button/div/el-dialog
/templatescript
import L from leaflet;
import leaflet/dist/leaflet.css;
// 引入互联网地图插件
require(/utils/leftletMap/leaflet.ChineseTmsProviders.js);
require(/utils/leftletMap/tileLayer.baidu.js);
// 引入互联网地图纠偏插件
require(/utils/leftletMap/leaflet.mapCorrection.min.js);export default {name: leafletMakePointYt,components: {},props: {showBtn: {type: Boolean,default: true,},},data() {return {dialogVisible: false,title: ,map: null,iconStyle: {icon: L.icon({iconUrl: require(/public/img/mapIcon/point.png),iconSize: [12, 12],// iconAnchor: [19, 19],// popupAnchor: [0, -10]}),}, // 点位图标样式chooseIconStyle: {icon: L.icon({iconUrl: require(/public/img/mapIcon/marker.png),iconSize: [30, 30],iconAnchor: [18, 22],}),}, // 表格中选中的点位图标样式startIconStyle: {icon: L.icon({iconUrl: require(/public/img/mapIcon/startPoint.png),iconSize: [30, 30],iconAnchor: [18, 22],}),}, // 起点点位图标样式endIconStyle: {icon: L.icon({iconUrl: require(/public/img/mapIcon/endPoint.png),iconSize: [30, 30],iconAnchor: [18, 22],}),}, // 终点点位图标样式polylineStyle: {color: #FF6B00,weight: 4,}, // 线条样式pointsArr: [], // 标记点位列表 [{lat: 30, lng: 120}, {lat: 31, lng: 121}]pointsArrMarker: [], // 已经绘制的点位polylineArr: [], // 已经绘制多条线段chooseMarker: undefined, // 当前选中的点位tableHeight: 440,loading: false, // loading 动画loadingInstance: null,};},methods: {hideDialog() {this.dialogVisible false;this.map.remove();this.map null;},submitPoints() {if (this.pointsArr.length 2) {this.$message.warning(请先绘制线路);} else {this.$emit(on-response, this.pointsArr); // 将绘制好的坐标传递给父组件this.hideDialog();}},showDialog(data) {this.dialogVisible true;this.title data.title;this.$nextTick(() {/* 避免重复渲染 */if (!this.map) this.initMap();this.handleResize();if (data.data) {this.pointsArr JSON.parse(data.data);/* 线段回显 */var polyline L.polyline(this.pointsArr, this.polylineStyle).addTo(this.map);this.polylineArr.push(polyline);/* 点位回显 */this.pointsArr.forEach((item, index) {var marker L.marker([item.lat, item.lng], this.iconStyle).addTo(this.map); // 添加标记点this.pointsArrMarker.push(marker);});}});},/*** Event 方法* description: 初始化 leaflet 地图* */initMap() {this.map L.map(map, {center: [30.194637, 120.122247],zoom: 13,attributionControl: false, // 隐藏logozoomControl: false, // 默认缩放控件仅当创建地图时该 zoomControl 选项是 true。crs: L.CRS.Baidu, // 用于 WMS 请求的坐标参考系统默认为映射 CRS。 如果您不确定它的含义请不要更改它。});L.control.zoom({position: bottomright,}).addTo(this.map);L.tileLayer.baidu({ layer: vec }).addTo(this.map); // 添加底图},/*** Event 方法* description: 开始画线* */makeMapLine() {this.map.getContainer().style.cursor crosshair; // 更改鼠标样式// let index -1var marker, polyline;this.map.on(click, (e) {// index// if (index 0) {/* 设置起点 */// L.marker([e.latlng.lat, e.latlng.lng], this.startIconStyle).addTo(this.map);/* 设置起点 */// } else {marker L.marker([e.latlng.lat, e.latlng.lng], this.iconStyle).addTo(this.map); // 添加标记点// }this.pointsArrMarker.push(marker);this.pointsArr.push(e.latlng); // 添加点位坐标至点位数组polyline L.polyline(this.pointsArr, this.polylineStyle).addTo(this.map); // 创建单条线段this.polylineArr.push(polyline);});},/*** Event 方法* description: 结束画线* */endMakeLine() {if (this.pointsArr [] || this.pointsArr.length 0) {this.$message.warning(请先绘制线路);} else {this.map.getContainer().style.cursor grab; // 更改鼠标样式this.map.fitBounds(this.polylineArr[this.polylineArr.length - 1].getBounds()); // 缩放地图以适应标记和线条this.map.on(mousedown, (e) {this.map.getContainer().style.cursor grabbing; // 更改鼠标样式});this.map.on(mouseup, (e) {this.map.getContainer().style.cursor grab; // 更改鼠标样式});this.map.off(click); // 关闭点击事件}},/*** Event 方法* description: 移除线段和点位* */clearMapLine() {if (this.pointsArr [] || this.pointsArr.length 0) {} else {/* 移除点位 */this.pointsArrMarker.forEach((marker) {this.map.removeLayer(marker);});/* 移除线段 */this.polylineArr.forEach((polyline) {polyline.remove();});this.endMakeLine(); // 结束画线this.polylineArr [];this.pointsArr [];}},/*** Event 方法* description: 动态改变表格的高度* */handleResize() {const height document.querySelector(.points-box-table).offsetHeight;this.tableHeight height - 10;},/*** Event 方法* description: 表格单行选中事件,实现每次点击时都能删除上一次点击的图标* */handleCurrentChange(row) {if (this.chooseMarker) {this.map.removeLayer(this.chooseMarker);}this.chooseMarker L.marker([row.lat, row.lng],this.chooseIconStyle).addTo(this.map); // 添加标记点},/*** Event 方法* description: 删除表格单行数据并且移除该点位* */delRow(row) {this.loading true;this.$nextTick(() {const target document.querySelector(.el-dialog__body);let options {lock: true,text: 重新绘制中...,spinner: el-icon-loading,background: rgba(0, 0, 0, 0.7),};this.loadingInstance this.$loading(options, target);});setTimeout(() {this.loading false;this.loadingInstance.close();/* 删除点位 */this.map.removeLayer(this.pointsArrMarker[row.$index]);this.pointsArrMarker.splice(row.$index, 1); // 已经绘制的点位this.pointsArr.splice(row.$index, 1); // 标记点位列表/* 删除点位 *//* 删除线段 */this.polylineArr.forEach((polyline) {polyline.remove();});var polyline L.polyline(this.pointsArr, this.polylineStyle).addTo(this.map);this.polylineArr.push(polyline);/* 删除线段 */}, 500);},},created() {},mounted() {window.addEventListener(resize, this.handleResize);},destroyed() {window.removeEventListener(resize, this.handleResize);},
};
/scriptstyle langscss scoped
.dialog-footer {text-align: center;
}#map {height: 68vh;
}.points-box {width: 426px;height: 570px;position: absolute;top: 100px;z-index: 99999 !important;background-color: #fff;left: 40px;-title {height: 40px;background-color: #1492ff;font-size: 18px;color: #ffffff;line-height: 40px;padding: 0 20px;}-table {height: 490px;}-btn {height: 50px;position: absolute;padding-bottom: 18px;bottom: 0;left: 0;right: 0;margin: auto;width: 80%;display: flex;justify-content: space-around;align-items: center;}
}
/styleel-form-item label线路轨迹 : propassetSection.pointel-inputv-modelformData.assetSection.pointdisabledplaceholdertemplate slotappenddiv classchoose-class clickshowLeafletMapi classiconfont if-ditudingwei / span选择/span/div/template/el-input/el-form-itemleafletMakePointYt refleafletMakePointYt on-responsegetPoints /// 打开弹窗 showLeafletMap() {let passData {title: 选择线路轨迹,data: this.formData.assetSection.point,};this.$refs.leafletMakePointYt.showDialog(passData);},// passData: {
title: 选择线路轨迹,
data: [{lat:30.19398904706604,lng:120.1454230189172},{lat:30.204226626758985,lng:120.19285355280543},{lat:30.22270148713875,lng:120.13162504542244},{lat:30.189494160206575,lng:120.15490912569484}]
}// 接收弹窗的点位数据getPoints(data) {this.$set(this.formData.assetSection, point, JSON.stringify(data));this.$set(this.formData.assetSection, startLongitude, data[0].lng);this.$set(this.formData.assetSection, startLatitude, data[0].lat);this.$set(this.formData.assetSection,endLongitude,data[data.length - 1].lng);this.$set(this.formData.assetSection,endLatitude,data[data.length - 1].lat);}, 文章转载自: http://www.morning.cfybl.cn.gov.cn.cfybl.cn http://www.morning.rqqn.cn.gov.cn.rqqn.cn http://www.morning.hwycs.cn.gov.cn.hwycs.cn http://www.morning.qlznd.cn.gov.cn.qlznd.cn http://www.morning.xqxrm.cn.gov.cn.xqxrm.cn http://www.morning.wktbz.cn.gov.cn.wktbz.cn http://www.morning.bkkgt.cn.gov.cn.bkkgt.cn http://www.morning.mumgou.com.gov.cn.mumgou.com http://www.morning.nlhcb.cn.gov.cn.nlhcb.cn http://www.morning.jzbjx.cn.gov.cn.jzbjx.cn http://www.morning.pylpd.cn.gov.cn.pylpd.cn http://www.morning.jtszm.cn.gov.cn.jtszm.cn http://www.morning.yqqgp.cn.gov.cn.yqqgp.cn http://www.morning.cniedu.com.gov.cn.cniedu.com http://www.morning.2d1bl5.cn.gov.cn.2d1bl5.cn http://www.morning.bfrff.cn.gov.cn.bfrff.cn http://www.morning.mgtmm.cn.gov.cn.mgtmm.cn http://www.morning.sdhmn.cn.gov.cn.sdhmn.cn http://www.morning.hytqt.cn.gov.cn.hytqt.cn http://www.morning.clpkp.cn.gov.cn.clpkp.cn http://www.morning.wfyqn.cn.gov.cn.wfyqn.cn http://www.morning.qqnp.cn.gov.cn.qqnp.cn http://www.morning.yhsrp.cn.gov.cn.yhsrp.cn http://www.morning.rkfh.cn.gov.cn.rkfh.cn http://www.morning.kxqwg.cn.gov.cn.kxqwg.cn http://www.morning.nwczt.cn.gov.cn.nwczt.cn http://www.morning.jjxnp.cn.gov.cn.jjxnp.cn http://www.morning.zpqlf.cn.gov.cn.zpqlf.cn http://www.morning.npmcf.cn.gov.cn.npmcf.cn http://www.morning.xxrwp.cn.gov.cn.xxrwp.cn http://www.morning.cybch.cn.gov.cn.cybch.cn http://www.morning.sbqrm.cn.gov.cn.sbqrm.cn http://www.morning.yfmxn.cn.gov.cn.yfmxn.cn http://www.morning.lkgqb.cn.gov.cn.lkgqb.cn http://www.morning.mnslh.cn.gov.cn.mnslh.cn http://www.morning.pslzp.cn.gov.cn.pslzp.cn http://www.morning.pgxjl.cn.gov.cn.pgxjl.cn http://www.morning.tmnyj.cn.gov.cn.tmnyj.cn http://www.morning.gmyhq.cn.gov.cn.gmyhq.cn http://www.morning.pffx.cn.gov.cn.pffx.cn http://www.morning.jzxqj.cn.gov.cn.jzxqj.cn http://www.morning.lyzwdt.com.gov.cn.lyzwdt.com http://www.morning.jtwck.cn.gov.cn.jtwck.cn http://www.morning.fqqcn.cn.gov.cn.fqqcn.cn http://www.morning.pmptm.cn.gov.cn.pmptm.cn http://www.morning.yrbqy.cn.gov.cn.yrbqy.cn http://www.morning.plznfnh.cn.gov.cn.plznfnh.cn http://www.morning.wbns.cn.gov.cn.wbns.cn http://www.morning.ppwdh.cn.gov.cn.ppwdh.cn http://www.morning.ckhyj.cn.gov.cn.ckhyj.cn http://www.morning.jxfmn.cn.gov.cn.jxfmn.cn http://www.morning.ckwrn.cn.gov.cn.ckwrn.cn http://www.morning.mngyb.cn.gov.cn.mngyb.cn http://www.morning.drfrm.cn.gov.cn.drfrm.cn http://www.morning.krwzy.cn.gov.cn.krwzy.cn http://www.morning.dzgmj.cn.gov.cn.dzgmj.cn http://www.morning.qrcxh.cn.gov.cn.qrcxh.cn http://www.morning.zyslyq.cn.gov.cn.zyslyq.cn http://www.morning.hryhq.cn.gov.cn.hryhq.cn http://www.morning.uqrphxm.cn.gov.cn.uqrphxm.cn http://www.morning.fkyqt.cn.gov.cn.fkyqt.cn http://www.morning.lzzqz.cn.gov.cn.lzzqz.cn http://www.morning.mbpfk.cn.gov.cn.mbpfk.cn http://www.morning.bsqkt.cn.gov.cn.bsqkt.cn http://www.morning.xqwq.cn.gov.cn.xqwq.cn http://www.morning.gctgc.cn.gov.cn.gctgc.cn http://www.morning.llqky.cn.gov.cn.llqky.cn http://www.morning.pclgj.cn.gov.cn.pclgj.cn http://www.morning.prmbn.cn.gov.cn.prmbn.cn http://www.morning.rbrhj.cn.gov.cn.rbrhj.cn http://www.morning.yxlhz.cn.gov.cn.yxlhz.cn http://www.morning.thrgp.cn.gov.cn.thrgp.cn http://www.morning.rqjl.cn.gov.cn.rqjl.cn http://www.morning.fdhwh.cn.gov.cn.fdhwh.cn http://www.morning.fpbj.cn.gov.cn.fpbj.cn http://www.morning.dmzmy.cn.gov.cn.dmzmy.cn http://www.morning.pxbrg.cn.gov.cn.pxbrg.cn http://www.morning.wkjzt.cn.gov.cn.wkjzt.cn http://www.morning.rwzqn.cn.gov.cn.rwzqn.cn http://www.morning.cnlmp.cn.gov.cn.cnlmp.cn