Commit 4e9f4c0d by 王志慧

车位标记

1 parent a072e991
......@@ -9,6 +9,7 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"@amap/amap-jsapi-loader": "^1.0.1",
"bignumber.js": "^9.1.1",
"core-js": "^3.4.4",
"dayjs": "^1.10.7",
......
.marker {
height: 36px;
background: #5850ff;
border-radius: 4px;
font-size: 14px;
color: #ffffff;
display: flex;
align-items: center;
padding: 0 16px;
box-sizing: border-box;
font-weight: 400;
span {
margin-right: 8px;
font-size: 18px;
}
}
.amap-info-content {
width: 314px;
height: 243px;
background: #FFFFFF !important;
box-shadow: 0 3px 6px -4px #0000001f, 0 6px 16px 0 #00000014, 0 9px 28px 8px #0000000d !important;
border-radius: 4px !important;
padding: 12px 0 !important;
overflow: hidden!important;
}
.custom-infowindow {
.title {
width: 100%;
font-weight: 600;
font-size: 16px;
color: #333333;
border-bottom: 1px solid #E5E5E5;
padding-left: 20px;
padding-bottom: 12px;
box-sizing: border-box;
}
.custom-item {
padding: 12px 20px;
box-sizing: border-box;
border-bottom: 1px solid #E5E5E5;
.item {
display: flex;
align-items: center;
justify-content: space-between;
padding-bottom: 12px;
span {
font-size: 14px;
color: #999999;
}
.item-text {
color: #000000a6;
}
}
}
.footer {
height: 48px;
width: 100%;
display: flex;
justify-content: flex-end;
align-items: center;
padding-right: 20px;
box-sizing: border-box;
div {
width: 44px;
height: 24px;
border: 1px solid #D1D1D1;
border-radius: 4px;
text-align: center;
line-height: 24px;
}
.cancel {
font-size: 14px;
color: #666666;
margin-right: 12px;
}
.confirm {
background: #5850FF;
color: #FFFFFF;
}
.del{
background: #5850FF;
color: #FFFFFF;
}
}
}
\ No newline at end of file
......@@ -29,3 +29,4 @@ html {
display:flex;
// align-items: center;
}
......@@ -10,6 +10,8 @@
import Vue from 'vue'
import glsxDialog from '@/components/glsx-dialog/index.vue'
import GlsxCombiForm from '@/components/glsx-combi-form/index.vue'
import MapContainer from '@/components/map-container/index.vue'
Vue.component('glsx-dialog', glsxDialog)
Vue.component('GlsxCombiForm', GlsxCombiForm)
\ No newline at end of file
Vue.component('GlsxCombiForm', GlsxCombiForm)
Vue.component('MapContainer', MapContainer)
\ No newline at end of file
<template>
<div class="map-container">
<div class="map-box">
<el-select v-model="input" class="map-input" filterable remote reserve-keyword placeholder="请输入" :remote-method="remoteMethod" @change="handleChangeAdr" :loading="loading">
<el-option v-for="item in adrList" :key="item.id" :label="item.address" :value="item.id"></el-option>
</el-select>
<div class="icon-card">
<div class="icon-item" v-for="(ctr, index) in controlList" @click="controlHandle(index, ctr.icon)" :key="index">
<img class="control-icon" :src="require(`@/assets/${ctr.icon}.png`)" />
{{ ctr.name }}
</div>
</div>
</div>
<!-- 地图 -->
<div id="container" :style="{ width: width, height: height }"></div>
</div>
</template>
<script>
let content = [],
contextMenu,
circle
import AMapLoader from '@amap/amap-jsapi-loader' //按需引入依赖
export default {
data() {
return {
input: [],
adrList: [],
placeSearch: '',
map: '',
address: '',
contextMenuPositon: '', //右键菜单位置
controlList: [
{
icon: 'moon',
name: '卫星'
},
{
icon: 'ranging',
name: '测距'
},
{
icon: 'location',
name: '定位'
},
{
icon: 'magnify',
name: '放大'
},
{
icon: 'reduce',
name: '缩小'
}
],
activeIndex: ''
}
},
props: {
width: {
type: String,
default: '100%'
},
height: {
type: String,
default: '100%'
}
},
mounted() {
this.initMap()
},
methods: {
initMap() {
AMapLoader.load({
key: '44cc16e43ad7ed3358df507bd0618181', // 申请好的Web端开发者Key,首次调用 load 时必填
version: '2.0', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
plugins: [
//需要使用的插件
'AMap.ToolBar',
'AMap.Scale',
'AMap.Geolocation',
'AMap.PlaceSearch',
'AMap.AutoComplete',
'AMap.Geocoder',
'AMap.CitySearch',
'AMap.RangingTool'
],
resizeEnable: true
})
.then(AMap => {
const that = this
that.AMap = AMap
that.map = new AMap.Map('container', {
//设置地图容器id
viewMode: '3D', //是否为3D地图模式
zoom: 12,
autoFitView: true,
resizeEnable: true,
cursor: 'move' //初始化地图级别
})
//构造地点查询类
that.placeSearch = new AMap.PlaceSearch({
pageSize: 8, // 单页显示结果条数
pageIndex: 1, // 页码
citylimit: false, //是否强制限制在设置的城市内搜索
// panel: "panel", // 结果列表将在此容器中进行展示。
autoFitView: true, // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围
renderStyle: 'default'
})
// that.map.on('click', this.getAddress)
that.getContextMenu()
})
.catch(e => {
console.log(e)
})
},
initMarket(marker) {
let { map, AMap, contextMenuPositon, address } = this,
that = this,
infoWindowContent,
infoWindow
if (marker) {
marker.on('click', function (e) {
console.log('点击', e)
that.contextMenuPositon = e.lnglat
that.getAddress()
infoWindowContent = `<div class="custom-infowindow input-card">
<div class="title">新增标记</div>
<div class="custom-item">
<div class="item">
<span>经度</span>
<span class="item-text" >${contextMenuPositon.lng}</span>
</div>
<div class="item">
<span>纬度</span>
<span class="item-text" >${contextMenuPositon.lat}</span>
</div>
<div class="item">
<span>车位编号</span>
<span class="item-text" >124.214.124</span>
</div>
<div class="item">
<span>经纬度解析</span>
<span class="item-text" >${address}</span>
</div>
</div>
<div>
<div class="footer">
<div class="cancel">取消</div>
<div class="del">删除</div>
</div>
</div>`
infoWindow = new AMap.InfoWindow({
content: infoWindowContent
})
infoWindow.open(map, contextMenuPositon)
that.bindEvent(infoWindow)
})
}
// marker = new AMap.Marker({
// map: map,
// clickable:true
// })
},
getContextMenu() {
let { map, AMap } = this,
that = this
content.push("<div class='info context_menu'>")
content.push(" <p class='marker' id='marker'><span>+</span>新增车位标记</p>")
content.push('</div>')
//通过content自定义右键菜单内容
contextMenu = new AMap.ContextMenu({ isCustom: true, content: content.join('') })
//地图绑定鼠标右击事件——弹出右键菜单
map.on('rightclick', function (e) {
contextMenu.open(map, e.lnglat)
that.contextMenuPositon = e.lnglat //右键菜单位置
that.getAddress()
that.marketEvent()
})
},
marketEvent() {
let marker = document.getElementById('marker')
marker.addEventListener('click', () => {
this.addMarkerMenu()
})
},
addMarkerMenu() {
let { map, AMap, contextMenuPositon, address } = this,
infoWindow,
infoWindowContent,
geocoder
infoWindowContent = `<div class="custom-infowindow input-card">
<div class="title">新增标记</div>
<div class="custom-item">
<div class="item">
<span>经度</span>
<span class="item-text" >${contextMenuPositon.lng}</span>
</div>
<div class="item">
<span>纬度</span>
<span class="item-text" >${contextMenuPositon.lat}</span>
</div>
<div class="item">
<span>车位编号</span>
<span class="item-text" >124.214.124</span>
</div>
<div class="item">
<span>经纬度解析</span>
<span class="item-text" >${address}</span>
</div>
</div>
<div>
<div class="footer">
<div class="cancel">取消</div>
<div class="confirm">确定</div>
</div>
</div>`
infoWindow = new AMap.InfoWindow({
content: infoWindowContent
})
contextMenu.close()
infoWindow.open(map, contextMenuPositon)
this.bindEvent(infoWindow)
},
bindEvent(infoWindow) {
let confirmBtn = document.getElementsByClassName('confirm')[0],
cancelBtn = document.getElementsByClassName('cancel')[0],
delBtn = document.getElementsByClassName('del')[0]
confirmBtn &&
confirmBtn.addEventListener('click', () => {
this.confirm(infoWindow)
})
cancelBtn &&
cancelBtn.addEventListener('click', () => {
this.cancel(infoWindow)
})
delBtn &&
delBtn.addEventListener('click', () => {
this.del(infoWindow)
})
},
confirm(infoWindow) {
let {
AMap,
map,
contextMenuPositon: { lng, lat }
} = this,
marker
marker = new AMap.Marker({
icon: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
position: [lng, lat],
offset: new AMap.Pixel(-13, -30)
})
marker.setMap(map)
this.initMarket(marker)
infoWindow.close()
},
cancel(infoWindow) {
infoWindow.close()
},
del(infoWindow){
infoWindow.close()
},
remoteMethod(query) {
if (query == '') {
return true
}
let _this = this
_this.placeSearch.search(query, function (status, result) {
if (status === 'complete' && result.poiList.pois.length) {
_this.adrList = result.poiList.pois
console.log(_this.adrList)
}
})
},
getAddress(e) {
let { map, AMap, contextMenuPositon } = this,
that = this,
geocoder
console.log(e)
if (e) {
circle = new AMap.Circle({
map: map,
center: e.location,
radius: 10, //半径
borderWeight: 1,
// 线样式还支持 'dashed'
fillColor: '#1791fc',
zIndex: 50
})
circle.setMap(map)
// 缩放地图到合适的视野级别
map.setFitView([circle])
this.shroudContextMenu(e.location)
} else {
//获取地址
geocoder = new AMap.Geocoder({
radius: 1000 //范围,默认:500
})
geocoder.getAddress([contextMenuPositon.lng, contextMenuPositon.lat], function (status, result) {
if (status === 'complete' && result.regeocode) {
that.address = result.regeocode.formattedAddress
}
})
}
},
shroudContextMenu(lnglat) {
let { map, AMap } = this,
that = this
//绑定鼠标右击事件——弹出右键菜单
circle.on('rightclick', function (e) {
contextMenu.open(map, e.lnglat)
that.contextMenuPositon = e.lnglat
that.getAddress()
that.marketEvent()
})
},
handleChangeAdr(val) {
if (val) {
var location = this.adrList.find(item => item.id == val)
this.getAddress(location)
this.input = ''
this.adrList = []
}
},
controlHandle(index, event) {
this[event + 'Handle'](index)
this.activeIndex = index
},
//卫星
moonHandle(index) {
let { AMap, map, activeIndex } = this
if (activeIndex === index) {
new AMap.TileLayer({
map
})
return
}
new AMap.TileLayer.Satellite({
map
})
},
//测距
rangingHandle(index) {
let { AMap, map, activeIndex } = this,
ruler
ruler = new AMap.RangingTool(map)
if (activeIndex === index) {
ruler.turnOff()
return
}
ruler.turnOn()
},
//定位
locationHandle() {
let { AMap, map } = this,
geolocation
geolocation = new AMap.Geolocation({
enableHighAccuracy: true, //是否使用高精度定位,默认:true
timeout: 10000, //超过10秒后停止定位,默认:5s
position: 'RB', //定位按钮的停靠位置
offset: [10, 20], //定位按钮与设置的停靠位置的偏移量,默认:[10, 20]
zoomToAccuracy: true,
showButton: false //定位成功后是否自动调整地图视野到定位点
})
map.addControl(geolocation)
},
//放大
magnifyHandle() {
let { map } = this
map.zoomIn()
},
//缩小
reduceHandle() {
let { map } = this
map.zoomOut()
}
}
}
</script>
<style scoped lang="scss">
.map-container {
position: relative;
width: 100%;
height: calc(100vh - 80px);
.map-box {
width: 100%;
position: absolute;
top: 20px;
display: flex;
align-items: center;
padding: 0 18%;
box-sizing: border-box;
}
.map-input {
width: 40%;
z-index: 2;
margin-right: 16px;
}
#container {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 1;
width: 100%;
}
.icon-card {
z-index: 2;
// width: 100%;
height: 38px;
background: #ffffff;
box-shadow: 0 3px 6px -4px #0000001f, 0 6px 16px 0 #00000014, 0 9px 28px 8px #0000000d;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 10px;
box-sizing: border-box;
cursor: pointer;
.icon-item {
font-size: 14px;
color: #666666;
display: flex;
align-items: center;
justify-items: center;
line-height: 22px;
border-right: 1px solid #f0f1f7;
padding-right: 10px;
box-sizing: border-box;
&:last-child {
border-right: none;
}
img {
width: 18px;
height: 18px;
margin: 0 6px 0 10px;
}
}
}
}
</style>
\ No newline at end of file
export default function ContextMenu(map) {
var me = this
//地图中添加鼠标工具MouseTool插件
this.mouseTool = new AMap.MouseTool(map)
this.contextMenuPositon = null
var content = []
content.push("<div class='info context_menu'>")
content.push(" <p onclick='menu.addMarkerMenu()'>新增车位标记</p>")
content.push('</div>')
//通过content自定义右键菜单内容
this.contextMenu = new AMap.ContextMenu({ isCustom: true, content: content.join('') })
//地图绑定鼠标右击事件——弹出右键菜单
map.on('rightclick', function(e) {
me.contextMenu.open(map, e.lnglat)
me.contextMenuPositon = e.lnglat //右键菜单位置
})
}
ContextMenu.prototype.zoomMenu = function zoomMenu(tag) {
//右键菜单缩放地图
if (tag === 0) {
map.zoomOut()
}
if (tag === 1) {
map.zoomIn()
}
this.contextMenu.close()
}
ContextMenu.prototype.distanceMeasureMenu = function() {
//右键菜单距离量测
this.mouseTool.rule()
this.contextMenu.close()
}
ContextMenu.prototype.addMarkerMenu = function() {
//右键菜单添加Marker标记
this.mouseTool.close()
var marker = new AMap.Marker({
map: map,
position: this.contextMenuPositon || map.getCenter() //基点位置
})
this.contextMenu.close()
}
......@@ -11,6 +11,7 @@ import Vue from 'vue'
import apis from './api'
import './public-path'
import '@/assets/css/public.scss'
import '@/assets/css/marker.scss'
import '@/components'
import { start } from '@/setup'
Vue.config.productionTip = false
......
......@@ -7,6 +7,11 @@ const staticRoutes = Object.freeze([{
path: '/Radar/index',
component: resolve => require([`@/views/Radar/index.vue`], resolve),
meta: {}
},
}, {
name: 'radar',
path: '/Map/index',
component: resolve => require([`@/views/Map/index.vue`], resolve),
meta: {}
}
])
export default staticRoutes
\ No newline at end of file
<template>
<map-container width="100%" height='100%'></map-container>
</template>
<script>
export default {}
</script>
<style>
</style>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!