|
@@ -1,30 +1,22 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <el-container>
|
|
|
|
|
- <el-header height="60">
|
|
|
|
|
- <el-button style="float: right; padding: 5px" type="text" @click="drawCircle">绘制圆形</el-button>
|
|
|
|
|
- <el-button style="float: right; padding: 5px" type="text" @click="onPathNavigator">路径巡航</el-button>
|
|
|
|
|
- </el-header>
|
|
|
|
|
- <el-main>
|
|
|
|
|
- <div id="container" class="text item amap-wrapper" />
|
|
|
|
|
- </el-main>
|
|
|
|
|
-
|
|
|
|
|
|
|
+ <div id="container" class="amap-wrapper">
|
|
|
<el-dialog :visible.sync="showPositionDialog" width="30%" center>
|
|
<el-dialog :visible.sync="showPositionDialog" width="30%" center>
|
|
|
<el-card class="box-card" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
|
|
<el-card class="box-card" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
|
|
|
<div slot="header" class="clearfix">
|
|
<div slot="header" class="clearfix">
|
|
|
<span>选中的坐标</span>
|
|
<span>选中的坐标</span>
|
|
|
- <el-button style="float: right; padding: 10px" type="text" @click="onSavePosition">保存坐标</el-button>
|
|
|
|
|
|
|
+ <el-button style="float: right; padding: 10px" type="text" @click="onSavePosition1">保存坐标</el-button>
|
|
|
</div>
|
|
</div>
|
|
|
<div class="text item">
|
|
<div class="text item">
|
|
|
<span style="color: red">({{ positionForm.lng }}, {{ positionForm.lat }})</span>
|
|
<span style="color: red">({{ positionForm.lng }}, {{ positionForm.lat }})</span>
|
|
|
</div>
|
|
</div>
|
|
|
</el-card>
|
|
</el-card>
|
|
|
</el-dialog>
|
|
</el-dialog>
|
|
|
- </el-container>
|
|
|
|
|
|
|
+ </div>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
import AMapLoader from '@amap/amap-jsapi-loader'
|
|
import AMapLoader from '@amap/amap-jsapi-loader'
|
|
|
-import { addGeoPoint, getGeoPoint } from '@/api/map'
|
|
|
|
|
|
|
+import { addGeoPoint, getMapMarkers } from '@/api/map'
|
|
|
|
|
|
|
|
export default {
|
|
export default {
|
|
|
name: 'Map',
|
|
name: 'Map',
|
|
@@ -32,22 +24,10 @@ export default {
|
|
|
return {
|
|
return {
|
|
|
amap: null,
|
|
amap: null,
|
|
|
plugins: ['Scale'],
|
|
plugins: ['Scale'],
|
|
|
- mapCenter: [114.0000, 30.0000],
|
|
|
|
|
// zoom=6 的比例尺为 100km
|
|
// zoom=6 的比例尺为 100km
|
|
|
- zoom: 6,
|
|
|
|
|
- province: '',
|
|
|
|
|
- provinces: [],
|
|
|
|
|
- city: '',
|
|
|
|
|
- citys: [],
|
|
|
|
|
- district: '',
|
|
|
|
|
- districts: [],
|
|
|
|
|
- path1: [{
|
|
|
|
|
- path: [
|
|
|
|
|
- [116.361904, 39.913423],
|
|
|
|
|
- [116.367904, 39.913423]
|
|
|
|
|
- ]
|
|
|
|
|
- }],
|
|
|
|
|
- path: [],
|
|
|
|
|
|
|
+ zoom: 5,
|
|
|
|
|
+ mapCenter: [108.337237, 33.881985],
|
|
|
|
|
+ markers: [],
|
|
|
showPositionDialog: false,
|
|
showPositionDialog: false,
|
|
|
positionForm: {
|
|
positionForm: {
|
|
|
lng: null,
|
|
lng: null,
|
|
@@ -87,155 +67,53 @@ export default {
|
|
|
// 设置地图容器id
|
|
// 设置地图容器id
|
|
|
this.map = new AMap.Map('container', {
|
|
this.map = new AMap.Map('container', {
|
|
|
viewMode: '2D', // 是否为3D地图模式
|
|
viewMode: '2D', // 是否为3D地图模式
|
|
|
- zoom: 6, // 初始化地图级别
|
|
|
|
|
- center: [104.065753, 30.657462] // 初始化地图中心点位置
|
|
|
|
|
|
|
+ zoom: this.zoom, // 初始化地图级别
|
|
|
|
|
+ center: this.mapCenter // 初始化地图中心点位置
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ // 点击地图事件(获取经纬度)
|
|
|
this.map.on('click', (e) => {
|
|
this.map.on('click', (e) => {
|
|
|
- // 获取经纬度
|
|
|
|
|
this.positionForm.lng = e.lnglat.getLng()
|
|
this.positionForm.lng = e.lnglat.getLng()
|
|
|
this.positionForm.lat = e.lnglat.getLat()
|
|
this.positionForm.lat = e.lnglat.getLat()
|
|
|
this.showPositionDialog = true
|
|
this.showPositionDialog = true
|
|
|
})
|
|
})
|
|
|
- }).catch((e) => {
|
|
|
|
|
- console.log(e)
|
|
|
|
|
- })
|
|
|
|
|
- },
|
|
|
|
|
- zoomchange(e) {
|
|
|
|
|
- console.log('当前缩放级别: ' + this.amap.getZoom())
|
|
|
|
|
- },
|
|
|
|
|
- // 轨迹巡航
|
|
|
|
|
- loadPathSimplifier() {
|
|
|
|
|
- AMapUI.load(['ui/misc/PathSimplifier'], (PathSimplifier) => {
|
|
|
|
|
- if (!PathSimplifier.supportCanvas) {
|
|
|
|
|
- alert('当前环境不支持 Canvas!')
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- // 创建组件实例
|
|
|
|
|
- var pathSimplifierIns = new PathSimplifier({
|
|
|
|
|
- map: this.map,
|
|
|
|
|
- zIndex: 100, // 图层叠加顺序
|
|
|
|
|
- data: this.path, // 巡航路径
|
|
|
|
|
- // 获取巡航路径中的路径坐标数组
|
|
|
|
|
- getPath: (pathData, pathIndex) => {
|
|
|
|
|
- return pathData.path
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- // 创建巡航器
|
|
|
|
|
- var pathNavigator = pathSimplifierIns.createPathNavigator(0, {
|
|
|
|
|
- loop: false, // 是否循环
|
|
|
|
|
- speed: 2000 // 速度(km/h)
|
|
|
|
|
- })
|
|
|
|
|
- pathNavigator.start()
|
|
|
|
|
- })
|
|
|
|
|
- },
|
|
|
|
|
- getDistrict(map) {
|
|
|
|
|
- // 创建行政区查询对象
|
|
|
|
|
- var district = new AMap.DistrictSearch({
|
|
|
|
|
- // 返回行政区边界坐标等具体信息
|
|
|
|
|
- extensions: 'all',
|
|
|
|
|
- // 设置查询行政区级别为 区
|
|
|
|
|
- level: 'street',
|
|
|
|
|
- subdistrict: 3
|
|
|
|
|
- })
|
|
|
|
|
|
|
|
|
|
- this.zoom = 11
|
|
|
|
|
- const area = '双流'
|
|
|
|
|
- district.search(area, function(status, result) {
|
|
|
|
|
- var bounds = result.districtList[0].boundaries
|
|
|
|
|
- var polygons = []
|
|
|
|
|
- if (bounds) {
|
|
|
|
|
- for (var i = 0, l = bounds.length; i < l; i++) {
|
|
|
|
|
- // 生成行政区划polygon
|
|
|
|
|
- var polygon = new AMap.Polygon({
|
|
|
|
|
- map: map,
|
|
|
|
|
- strokeWeight: 1,
|
|
|
|
|
- path: bounds[i],
|
|
|
|
|
- fillOpacity: 0.7,
|
|
|
|
|
- fillColor: '#CCF3FF',
|
|
|
|
|
- strokeColor: '#CC66CC'
|
|
|
|
|
|
|
+ getMapMarkers(1).then(res => {
|
|
|
|
|
+ if (res.code === 0) {
|
|
|
|
|
+ this.$notify({
|
|
|
|
|
+ message: '加载了 ' + res.data.length + ' 条数据',
|
|
|
|
|
+ type: 'warning',
|
|
|
|
|
+ duration: 1000
|
|
|
})
|
|
})
|
|
|
- polygons.push(polygon)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 地图自适应
|
|
|
|
|
- map.setFitView()
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- },
|
|
|
|
|
- drawCircle1() {
|
|
|
|
|
- this.$message.info('加载路径')
|
|
|
|
|
- getGeoPoint().then(resp => {
|
|
|
|
|
- if (resp.code === 0) {
|
|
|
|
|
- const pathList = resp.data
|
|
|
|
|
- if (pathList.length === 0) {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- this.path = pathList
|
|
|
|
|
- AMapUI.load(['ui/misc/PathSimplifier'], (PathSimplifier) => {
|
|
|
|
|
- if (!PathSimplifier.supportCanvas) {
|
|
|
|
|
- alert('当前环境不支持 Canvas!')
|
|
|
|
|
- return
|
|
|
|
|
|
|
+ for (const item of res.data) {
|
|
|
|
|
+ this.markers.push(new AMap.Marker({
|
|
|
|
|
+ position: new AMap.LngLat(item.position.lng, item.position.lat),
|
|
|
|
|
+ label: { content: item.title, offset: [0, 0] },
|
|
|
|
|
+ extData: { id: item.id }
|
|
|
|
|
+ }))
|
|
|
}
|
|
}
|
|
|
- // 创建组件实例
|
|
|
|
|
- var pathSimplifierIns = new PathSimplifier({
|
|
|
|
|
- map: this.map,
|
|
|
|
|
- zIndex: 100, // 图层叠加顺序
|
|
|
|
|
- data: this.path, // 巡航路径
|
|
|
|
|
- // 获取巡航路径中的路径坐标数组
|
|
|
|
|
- getPath: (pathData, pathIndex) => {
|
|
|
|
|
- return pathData.path
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- // 创建巡航器
|
|
|
|
|
- var pathNavigator = pathSimplifierIns.createPathNavigator(0, {
|
|
|
|
|
- loop: false, // 是否循环
|
|
|
|
|
- speed: 2000 // 速度(km/h)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // this.map.add(this.markers)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.$notify({
|
|
|
|
|
+ message: res.msg,
|
|
|
|
|
+ type: 'warning',
|
|
|
|
|
+ duration: 3000
|
|
|
})
|
|
})
|
|
|
- pathNavigator.start()
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ }).catch(error => {
|
|
|
|
|
+ this.$notify({
|
|
|
|
|
+ message: error.message,
|
|
|
|
|
+ type: 'warning',
|
|
|
|
|
+ duration: 3000
|
|
|
})
|
|
})
|
|
|
- }
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+ }).catch((e) => {
|
|
|
|
|
+ this.$message.error(e)
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
- drawCircle() {
|
|
|
|
|
- // 设置圆形位置
|
|
|
|
|
- var center = new AMap.LngLat(104.065753, 30.657462)
|
|
|
|
|
- // 设置圆的半径大小
|
|
|
|
|
- var radius = 1000
|
|
|
|
|
- // 创建圆形 Circle 实例
|
|
|
|
|
- var circle = new AMap.Circle({
|
|
|
|
|
- center: center, // 圆心
|
|
|
|
|
- radius: radius, // 半径
|
|
|
|
|
- borderWeight: 3, // 描边的宽度
|
|
|
|
|
- strokeColor: '#ff3333', // 轮廓线颜色
|
|
|
|
|
- strokeOpacity: 1, // 轮廓线透明度
|
|
|
|
|
- strokeWeight: 1, // 轮廓线宽度
|
|
|
|
|
- fillOpacity: 0.4, // 圆形填充透明度
|
|
|
|
|
- strokeStyle: 'line', // 轮廓线样式
|
|
|
|
|
- strokeDasharray: [10, 10],
|
|
|
|
|
- fillColor: '#1791fc', // 圆形填充颜色
|
|
|
|
|
- zIndex: 50 // 圆形的叠加顺序
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- // 圆形 Circle 对象添加到 Map
|
|
|
|
|
- this.map.add(circle)
|
|
|
|
|
- // 根据覆盖物范围调整视野
|
|
|
|
|
- this.map.setFitView([circle])
|
|
|
|
|
-
|
|
|
|
|
- // 鼠标移入事件
|
|
|
|
|
- circle.on('mouseover', function() {
|
|
|
|
|
- console.log('鼠标移入')
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- var that = this.map
|
|
|
|
|
- // 引入圆形编辑器插件
|
|
|
|
|
- this.map.plugin(['AMap.CircleEditor'], function() {
|
|
|
|
|
- // 实例化圆形编辑器,传入地图实例和要进行编辑的圆形实例
|
|
|
|
|
- var circleEditor = new AMap.CircleEditor(that, circle)
|
|
|
|
|
- // 开启编辑模式
|
|
|
|
|
- circleEditor.open()
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ onSavePosition1() {
|
|
|
},
|
|
},
|
|
|
onSavePosition() {
|
|
onSavePosition() {
|
|
|
this.showPositionDialog = false
|
|
this.showPositionDialog = false
|
|
@@ -244,40 +122,6 @@ export default {
|
|
|
this.$message.info('添加坐标失败')
|
|
this.$message.info('添加坐标失败')
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
- },
|
|
|
|
|
- onPathNavigator() {
|
|
|
|
|
- getGeoPoint().then(resp => {
|
|
|
|
|
- if (resp.code === 0) {
|
|
|
|
|
- const pathList = resp.data
|
|
|
|
|
- if (pathList.length === 0) {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- this.path = pathList
|
|
|
|
|
- AMapUI.load(['ui/misc/PathSimplifier'], (PathSimplifier) => {
|
|
|
|
|
- if (!PathSimplifier.supportCanvas) {
|
|
|
|
|
- alert('当前环境不支持 Canvas!')
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- // 创建组件实例
|
|
|
|
|
- var pathSimplifierIns = new PathSimplifier({
|
|
|
|
|
- map: this.map,
|
|
|
|
|
- zIndex: 100, // 图层叠加顺序
|
|
|
|
|
- data: this.path, // 巡航路径
|
|
|
|
|
- // 获取巡航路径中的路径坐标数组
|
|
|
|
|
- getPath: (pathData, pathIndex) => {
|
|
|
|
|
- return pathData.path
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- // 创建巡航器
|
|
|
|
|
- var pathNavigator = pathSimplifierIns.createPathNavigator(0, {
|
|
|
|
|
- loop: false, // 是否循环
|
|
|
|
|
- speed: 2000 // 速度(km/h)
|
|
|
|
|
- })
|
|
|
|
|
- pathNavigator.start()
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -288,10 +132,4 @@ export default {
|
|
|
width: 100%;
|
|
width: 100%;
|
|
|
height: 600px;
|
|
height: 600px;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-.movie-list {
|
|
|
|
|
- padding-top: 15px;
|
|
|
|
|
- padding-left: 3%;
|
|
|
|
|
- padding-right: 3%;
|
|
|
|
|
-}
|
|
|
|
|
</style>
|
|
</style>
|