vue前端开发仿钉图系列(3)右侧画点线面的开发详解
项目开发是完全仿照钉图的功能,参照钉图的逻辑和高德地图的参考手册以及aip文档,一点点的把功能做出来并呈现最后的效果。选中画点,在地图上获取经纬度并进行反地理编码,添加marker并弹出右侧编辑页面,选择绑定所属图层,获取相应的动态标签列表,最后保存数据到数据列表。整理总结不易,如需全部代码,请联系我15098950589(微信同号)。和以往一样,先上一下效果图。
点线面工具的核心代码
that.mouseTool = new AMap.MouseTool(that.map);
//监听draw事件可获取画好的覆盖物
that.overlays = [];
that.mouseTool.on('draw', function(e) {
that.overlays.push(e.obj);
console.log('绘图信息', e.obj)
let poly = e.obj // 绘制完多边形实力对象
console.log('绘制图形顶点信息列表--------> ', poly.getOptions())
console.log('绘制图形的自定义属性--------> ', poly.getOptions().path)
that.isFromEdit = false;
//折线
if (that.layerType === 1) {
//实例化折线对象
let polyline = new AMap.Polyline({
map: that.map, //初始化的地图变量
path: poly.getOptions()
.path //折线的存放数组,很重中。一般是好多经纬度组成的数组。
});
that.lineLength = parseFloat(polyline.getLength(false) / 1000)
.toFixed(2) + ''
that.lineMarkers = poly.getOptions().path;
console.log('折线长度', that.lineLength)
}
//面
else if (that.layerType === 2) {
//实例化面对象
let polygon = new AMap.Polygon({
map: that.map, //初始化的地图变量
path: poly.getOptions()
.path //面的存放数组,很重中。一般是好多经纬度组成的数组。
});
that.surArea = parseFloat(polygon.getArea(false) / 1000000)
.toFixed(2) + ''
that.polygonMarkers = poly.getOptions().path;
console.log('面积', that.surArea, poly.getOptions().path)
}
})
var radios = document.getElementsByName('func');
for (let i = 0; i < radios.length; i += 1) {
radios[i].onchange = function(e) {
console.log('点击我了', e.target.value)
that.operatetype = e.target.value
that.isFromEdit = false;
that.isEditedEnabled = true;
//点停止距离和面积,线绘制距离,面显示面积
if (e.target.value === 'marker') {
that.draw(e.target.value)
} else if (e.target.value === 'polyline') {
that.rageAndMeasureDraw('rule')
} else {
that.rageAndMeasureDraw('measureArea')
}
}
}
//this.draw('marker')
//获取当前选中点的经纬度信息
const geocoder = new AMap.Geocoder({
city: '全国'
});
console.log('地图对象')
console.log('地图对象', that.map)
//为地图注册click事件获取鼠标点击出的经纬度坐标
that.map.on('click', function(e) {
if (!that.isEditedEnabled) {
return;
}
//反地理编码
geocoder.getAddress([e.lnglat.getLng(), e.lnglat.getLat()], function(
status,
result) {
if (status === 'complete' && result.regeocode) {
that.locationAddress = result.regeocode
.formattedAddress;
that.lng = e.lnglat.getLng()
that.lat = e.lnglat.getLat()
console.log('位置信息', e.lnglat.getLng(), e.lnglat
.getLat(), that
.locationAddress, that.overlays)
//只在画点的时候,单击弹出右侧编辑框,其他情况在双击结束的时候弹出编辑框
if (that.operatetype === 'marker') {
console.log('显示右侧列表')
//画点
that.layerType = 0;
//显示右侧编辑列表,并关闭绘图工具
that.rightEditVisible = true;
that.isFromEdit = false;
setTimeout(() => {
that.$refs.rightEdit.initData();
}, 1)
} else if (that.operatetype === 'polyline') {
that.layerType = 1;
} else if (that.operatetype === 'polygon') {
that.layerType = 2;
}
} else {
log.error('根据经纬度查询地址失败')
}
});
});
//关闭绘图工具
closeMouseToulDraw() {
this.mouseTool.close(true)
this.isEditedEnabled = false;
var radios = document.getElementsByName('func');
for (var i = 0; i < radios.length; i += 1) {
radios[i].checked = false;
}
setTimeout(() => {
this.$refs.dataList.initData()
this.$refs.layerList.initData()
}, 1)
this.map.remove(this.overlays)
this.overlays = [];
this.map.clearMap();
},
//关闭绘图工具
closeMouseToul() {
this.mouseTool.close(false)
var radios = document.getElementsByName('func');
for (var i = 0; i < radios.length; i += 1) {
radios[i].checked = false;
}
},
//使用MouseTool封装了RagingTool的测距功能,同时提供了 measureArea 面积测量功能
rageAndMeasureDraw(type) {
switch (type) {
case 'rule': {
this.mouseTool.rule({
startMarkerOptions: { //可缺省
icon: new AMap.Icon({
size: new AMap.Size(19, 31), //图标大小
imageSize: new AMap.Size(19, 31),
image: "//webapi.amap.com/theme/v1.3/markers/b/start.png"
}),
offset: new AMap.Pixel(-9, -31)
},
endMarkerOptions: { //可缺省
icon: new AMap.Icon({
size: new AMap.Size(19, 31), //图标大小
imageSize: new AMap.Size(19, 31),
image: "//webapi.amap.com/theme/v1.3/markers/b/end.png"
}),
offset: new AMap.Pixel(-9, -31)
},
midMarkerOptions: { //可缺省
icon: new AMap.Icon({
size: new AMap.Size(19, 31), //图标大小
imageSize: new AMap.Size(19, 31),
image: "//webapi.amap.com/theme/v1.3/markers/b/mid.png"
}),
offset: new AMap.Pixel(-9, -31)
},
lineOptions: { //可缺省
strokeStyle: "solid",
strokeColor: "#FF33FF",
strokeOpacity: 1,
strokeWeight: 2
}
//同 RangingTool 的 自定义 设置,缺省为默认样式
});
break;
}
case 'measureArea': {
this.mouseTool.measureArea({
strokeColor: '#80d8ff',
fillColor: '#80d8ff',
fillOpacity: 0.3
//同 Polygon 的 Option 设置
});
break;
}
}
},
draw(type) {
switch (type) {
case 'marker': {
this.mouseTool.marker({
//同Marker的Option设置
});
break;
}
case 'polyline': {
this.mouseTool.polyline({
strokeColor: '#80d8ff'
//同Polyline的Option设置
});
break;
}
case 'polygon': {
this.mouseTool.polygon({
fillColor: '#00b0ff',
strokeColor: '#80d8ff'
//同Polygon的Option设置
});
break;
}
case 'rectangle': {
this.mouseTool.rectangle({
fillColor: '#00b0ff',
strokeColor: '#80d8ff'
//同Polygon的Option设置
});
break;
}
case 'circle': {
this.mouseTool.circle({
fillColor: '#00b0ff',
strokeColor: '#80d8ff'
//同Circle的Option设置
});
break;
}
}
整理总结不易,如需全部代码,请联系我15098950589(微信同号)。
vue前端开发仿钉图系列(3)右侧画点线面的开发详解的更多相关文章
- 前端html、CSS快速编写代码插件-Emmet使用方法技巧详解
前端html.CSS快速编写代码插件-Emmet使用方法技巧详解 Emmet的前身是大名鼎鼎的Zen coding,如果你从事Web前端开发的话,对该插件一定不会陌生.它使用仿CSS选择器的语法来 ...
- FFmpeg开发笔记(五):ffmpeg解码的基本流程详解(ffmpeg3新解码api)
若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/ar ...
- [js高手之路]深入浅出webpack系列2-配置文件webpack.config.js详解
接着上文,重新在webpack文件夹下面新建一个项目文件夹demo2,然后用npm init --yes初始化项目的package.json配置文件,然后安装webpack( npm install ...
- [js高手之路]深入浅出webpack教程系列3-配置文件webpack.config.js详解(下)
本文继续接着上文,继续写下webpack.config.js的其他配置用法. 一.把两个文件打包成一个,entry怎么配置? 在上文中的webpack.dev.config.js中,用数组配置entr ...
- [js高手之路]深入浅出webpack教程系列2-配置文件webpack.config.js详解(上)
[js高手之路]深入浅出webpack教程系列索引目录: [js高手之路]深入浅出webpack教程系列1-安装与基本打包用法和命令参数 [js高手之路]深入浅出webpack教程系列2-配置文件we ...
- SpringBoot系列教程JPA之query使用姿势详解之基础篇
前面的几篇文章分别介绍了CURD中的增删改,接下来进入最最常见的查询篇,看一下使用jpa进行db的记录查询时,可以怎么玩 本篇将介绍一些基础的查询使用姿势,主要包括根据字段查询,and/or/in/l ...
- SpringBoot系列教程JPA之delete使用姿势详解
原文: 190702-SpringBoot系列教程JPA之delete使用姿势详解 常见db中的四个操作curd,前面的几篇博文分别介绍了insert,update,接下来我们看下delete的使用姿 ...
- web标准 浏览器介绍 开发工具介绍 HTML介绍 HTML颜色介绍 规范 HTML结构详解 {前端之前端初识}
前端之前端初识 前端初识 本节目录 一 web标准 二 浏览器介绍 三 开发工具介绍 四 HTML介绍 五 HTML颜色介绍 六 规范 七 HTML结构详解 一 web标准 web准备介绍: 1. ...
- Spring Boot2 系列教程 (二) | 第一个 SpringBoot 工程详解
微信公众号:一个优秀的废人 如有问题或建议,请后台留言,我会尽力解决你的问题. 前言 哎呦喂,按照以往的惯例今天周六我的安排应该是待在家学学猫叫啥的.但是今年这种日子就可能一去不复返了,没法办法啊.前 ...
- Docker系列10—容器编排工具Docker Compose详解
本文收录在容器技术学习系列文章总目录 1.Docker Compose 概述 Compose是一个用于定义和运行多容器Docker应用程序的工具.使用Compose,您可以使用Compose文件来配置 ...
随机推荐
- 【Java】File 文件类
File 文件类 File类的一个对象,代表了一个文件和一个文件目录/文件夹 File类所属在java.io 的包下 构造器部分 - 以parent为父文件,child为子路径创建File对象,可以理 ...
- 【AJAX】Asynchronous JavaScript And XML (非同步的JS & XML)
什么是AJAX? 按照使用的感觉来看 说到底就是一个可以不刷新网页就能发送POST & GET请求的技术 AJAX 即"Asynchronous Javascript And XML ...
- 论文写作:test 和 testing 使用的区别
"test" 和 "testing" 的区别主要在于它们在句子中的用途和语法功能: Test: 名词: 指的是一次测试或考试.例如: "The stu ...
- 计算机类的短周期的SCI期刊
<Human-centric Computing and Information Sciences> 韩国人办的,Open Access,周期短,费用高,SCI二区,水毕业可用. 以下引自 ...
- baselines算法库baselines/bench/monitor.py模块分析
baselines算法库baselines/bench/monitor.py模块代码: __all__ = ['Monitor', 'get_monitor_files', 'load_results ...
- Linux嵌入式所有知识点-思维导图-【一口君吐血奉献】
一.前言 很多粉丝问我,我的Linux和嵌入式当初是如何学习的? 其实彭老师在最初学习的过程中,走了相当多的弯路: 有些可以不学的花了太多的时间去啃 有些作为基础必须优先学习的,却忽略了, 结果工作中 ...
- Diskpart 操作
DiskPart 是 Windows 操作系统中的一个命令行工具,用于管理磁盘分区.它可以创建.删除.格式化和调整分区大小,还可以设置活动分区等.以下是一些常用的 DiskPart 命令和操作步骤. ...
- 【测试平台开发】——01Vue前端框架实操
一.VScode官网地址 https://code.visualstudio.com/ 但是官网下载贼慢,需要修改下国内地址: 原地址:https://az764295.vo.msecnd.net/s ...
- 【Jmeter】之进行单接口批量压力测试
目录: 一.安装Jmeter 二.接口压力测试 p.p1 { margin: 0; font: 14px ".PingFang SC"; color: rgba(17, 31, 4 ...
- .NET 摄像头采集
本文主要介绍摄像头(相机)如何采集数据,用于类似摄像头本地显示软件,以及流媒体数据传输场景如传屏.视讯会议等. 摄像头采集有多种方案,如AForge.NET.WPFMediaKit.OpenCvSha ...