VUE地图基础操作放大、缩小、测距、测面、复位、切换地图底图,清除作图痕迹,画矩形框圆形等自定义图案
VUE地图基础操作:放大、缩小、测距、测面、复位、切换地图底图,清除作图痕迹,画矩形框圆形等自定义图案
data() {
return {
map: null,
size: 7,
markerLayer: null, //地点图层
toolLayer: null,
layer: null, //绘图图层
coordinate: [ //地点经纬度坐标
{ x: 117, y: 37, name: "a" },
{ x: 118, y: 38, name: "b" },
{ x: 117.5, y: 37.5, name: "c" },
{ x: 116.5, y: 36.5, name: "d" },
{ x: 118, y: 37.5, name: "e" },
{ x: 117.5, y: 38, name: "f" }],
flag: false, //测距离标志
areaflag: false, //测面积标志
drawflag: false, //绘图标志
areaTool: null, //测面积工具
distanceTool: null, //测距离工具
tool:null, //绘图工具
drawTool:null,
detail: { //弹窗
dialogVisible: false,
model: {
}
},
}
},
mounted() {
this.init()
this.start()
this.drawpic()
}
init() {
this.map = new maptalks.Map('yzMap', {
center: [117.174955, 37.941390], //地图的初始中心
zoom: this.size, //地图的初试缩放
pitch: 45,
// zoomControl: true, // add zoom control
scaleControl: true, // add scale control
// overviewControl: true, // add overview control
dragPitch: true, //是否可以倾斜(Ctrl 鼠标操作实现)
dragRotate: true, //是否可以旋转
dragRotatePitch: false, //是否旋转倾斜可以同时操作
baseLayer: new maptalks.GroupTileLayer('yzMap', [
new WMTSTileLayer('WMTS', {
urlTemplate: 'https://t5.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=自己申请的',
subdomains: ["a", "b", "c", "d"],
}),
new maptalks.TileLayer("dark-map", {
urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
subdomains: [0, 1, 2],
visible: false,
}),
]),
});
},
start() {
// 测量距离
this.distanceTool = new maptalks.DistanceTool({
'symbol': {
'lineColor': '#34495e',
'lineWidth': 2
},
'vertexSymbol': {
'markerType': 'ellipse',
'markerFill': '#1bbc9b',
'markerLineColor': '#000',
'markerLineWidth': 3,
'markerWidth': 10,
'markerHeight': 10
},
'labelOptions': {
'textSymbol': {
'textFaceName': 'monospace',
'textFill': '#fff',
'textLineSpacing': 1,
'textHorizontalAlignment': 'right',
'textDx': 15,
'markerLineColor': '#b4b3b3',
'markerFill': '#000'
},
'boxStyle': {
'padding': [6, 2],
'symbol': {
'markerType': 'square',
'markerFill': '#000',
'markerFillOpacity': 0.9,
'markerLineColor': '#b4b3b3'
}
}
},
'clearButtonSymbol': [{
'markerType': 'square',
'markerFill': '#000',
'markerLineColor': '#b4b3b3',
'markerLineWidth': 2,
'markerWidth': 15,
'markerHeight': 15,
'markerDx': 20
}, {
'markerType': 'x',
'markerWidth': 10,
'markerHeight': 10,
'markerLineColor': '#fff',
'markerDx': 20
}],
'language': 'en-US',
// once: true
}).addTo(this.map);
this.distanceTool.disable()
// 测量面积
this.areaTool = new maptalks.AreaTool({
'symbol': {
'lineColor': '#1bbc9b',
'lineWidth': 2,
'polygonFill': '#fff',
'polygonOpacity': 0.3
},
'vertexSymbol': {
'markerType': 'ellipse',
'markerFill': '#34495e',
'markerLineColor': '#1bbc9b',
'markerLineWidth': 3,
'markerWidth': 10,
'markerHeight': 10
},
'labelOptions': {
'textSymbol': {
'textFaceName': 'monospace',
'textFill': '#fff',
'textLineSpacing': 1,
'textHorizontalAlignment': 'right',
'textDx': 15
},
'boxStyle': {
'padding': [6, 2],
'symbol': {
'markerType': 'square',
'markerFill': '#000',
'markerFillOpacity': 0.9,
'markerLineColor': '#b4b3b3'
}
}
},
'clearButtonSymbol': [{
'markerType': 'square',
'markerFill': '#000',
'markerLineColor': '#b4b3b3',
'markerLineWidth': 2,
'markerWidth': 15,
'markerHeight': 15,
'markerDx': 22
}, {
'markerType': 'x',
'markerWidth': 10,
'markerHeight': 10,
'markerLineColor': '#fff',
'markerDx': 22
}],
language: '',
// once: true
}).addTo(this.map);
this.areaTool.disable()
},
// 测量距离
distance() {
this.flag = !this.flag
if (this.flag) {
this.areaflag = false
this.drawflag = false
this.areaTool.disable()
this.tool.disable()
}
// this.toolLayer.addGeometry(this.distanceTool).addTo(this.map)
if (this.flag) {
this.distanceTool.enable()
console.log("距离3", this.flag);
console.log("面积3", this.areaflag);
} else {
this.distanceTool.disable()
this.distanceTool.clear() //不再测量距离的时候清除痕迹
console.log("距离4", this.flag);
console.log("面积4", this.areaflag);
}
console.log("添加");
},
// 测量面积
area() {
this.areaflag = !this.areaflag
if (this.areaflag) {
this.flag = false
this.drawflag = false
this.distanceTool.disable()
this.tool.disable()
}
if (this.areaflag) {
this.areaTool.enable()
console.log("面积1", this.areaflag);
console.log("距离1", this.flag);
} else {
this.areaTool.disable()
this.areaTool.clear() //不再测量面积的时候清除痕迹
console.log("面积2", this.areaflag);
console.log("距离2", this.flag);
}
},
// 放大地图
add() {
this.map.setZoom(this.size = 1)
console.log(this.size);
},
// 缩小地图
jian() {
this.map.setZoom(this.size -= 1)
console.log(this.size);
},
// 复位
reset() {
let view = {
center: [117.174955, 37.941390]
}
this.map.setView(view);
this.map.setZoom(7)
},
// 清除作图痕迹
clear() {
if (this.areaTool != null) {
this.areaTool.clear()
console.log("面积清除", typeof this.areaTool);
}
if (this.distanceTool != null) {
this.distanceTool.clear()
console.log("距离清除", this.distanceTool);
}
if (this.layer != null) {
this.layer.clear()
console.log("绘图清除");
}
},
// 切换地图底图
change() {
var baseLayer = this.map.getBaseLayer()
baseLayer.layers.forEach((layer) => {
if (layer.getId() === 'WMTS') {
layer.hide()
} else {
layer.show()
}
})
console.log(baseLayer);
},
// 详情弹窗
devDisplay(x, y, name) {
this.detail.model.name = name
this.detail.model.x = x
this.detail.model.y = y
this.detail.dialogVisible = true
// alert(this.detail.model.y)
// console.log(e);
},
// 按钮绘制图形1,与2联合使用
drawpic(){
var layer = new maptalks.VectorLayer('draw').addTo(this.map);
var resultList = [];
var drawTool = new maptalks.DrawTool({
mode: 'Polygon',
symbol: {
'lineColor': '#000',
'lineWidth': 2
}
}).addTo(this.map).disable();
drawTool.on('drawend', function (param) {
console.log("按钮画图", param.geometry.toGeoJSON().geometry.coordinates[0][2][0]); //获取坐标
resultList.push(param.geometry.toGeoJSON().geometry.coordinates);
console.log(resultList.length);
layer.addGeometry(param.geometry);
});
this.tool=drawTool
this.layer=layer
// layer.addGeometry(drawTool)
// layer.addGeometry(drawTool.setMode("Rectangle").enable());
// drawTool.setMode("Rectangle").enable();
},
// 按钮绘制图形2,与1联合使用
pic(){
this.drawflag=!this.drawflag
if (this.drawflag) {
this.areaflag = false
this.flag = false
this.distanceTool.disable()
this.areaTool.disable()
this.tool.setMode("Rectangle").enable();
}else{
this.tool.disable()
console.log("绘图:",this.drawflag);
}
}
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhfheehj
系列文章
更多
同类精品
更多
-
TypeScript接口、type关键字可读、只读属性、继承接口|类、规范类、函数|可索引|类|混合类型接口、ReadonlyArray、接口和amp;type、映射类型
-
typescript 使用 setTimeout 返回值类型 eslint 检查错误 ‘NodeJS‘ is not defined.eslintno-undef
-
antd ERROR in ./node_modules/antd/lib/button/style/index.less javascriptEnabled
-
typescript---配置类相关内容(十五)
-
TSTypeScript泛型 T 的用法
-
使用回调函数作为参数的函数改造为返回 Promise 的具体例子
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01 -
怎样阻止微信小程序自动打开
PHP中文网 06-13