Commit 8da4f052 by 王志慧

地图功能

1 parent cd8bfcf6
......@@ -114,6 +114,17 @@ const addFlagparkingSpace = params => {
sign: true
})
}
// 删除车位标记
const deleteFlagparkingSpaceparams =params=> {
params.method = 'marketing.api.charge.parkingSpace.deleteFlag'
return http({
url: URL,
method: 'post',
data: params,
sign: true
})
}
export default {
getParkingSpaceListApi,
getHistoryListApi,
......@@ -124,5 +135,7 @@ export default {
getRadarListApi,
delParkingSpaceApi,
updateParkingSpaceApi,
saveParkingSpacePicApi
saveParkingSpacePicApi,
addFlagparkingSpace,
deleteFlagparkingSpaceparams
}
......@@ -18,7 +18,7 @@
.amap-info-content {
width: 314px;
height: 243px;
height: auto;
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;
......@@ -26,7 +26,7 @@
overflow: hidden!important;
}
.custom-infowindow {
.title {
width: 100%;
......@@ -44,7 +44,6 @@
.custom-item {
padding: 12px 20px;
box-sizing: border-box;
border-bottom: 1px solid #E5E5E5;
.item {
display: flex;
......@@ -71,6 +70,7 @@
align-items: center;
padding-right: 20px;
box-sizing: border-box;
border-top: 1px solid #E5E5E5;
div {
width: 44px;
......@@ -97,4 +97,3 @@
color: #FFFFFF;
}
}
}
\ No newline at end of file
......@@ -30,6 +30,7 @@ export default {
placeSearch: '',
map: '',
address: '',
markerData:{},
contextMenuPositon: '', //右键菜单位置
controlList: [
{
......@@ -71,7 +72,7 @@ export default {
}
},
mounted() {
this.initMap()
;(this.merchantId = this.$globalState.session.merchantId), this.initMap()
},
methods: {
initMap() {
......@@ -119,14 +120,17 @@ export default {
})
},
initMarket(marker) {
let { map, AMap, contextMenuPositon, address } = this,
let { map, AMap, contextMenuPositon, address,markerData } = this,
that = this,
infoWindowContent,
infoWindow
if (marker) {
marker.on('click', function (e) {
console.log('点击', e)
markerData=marker.getExtData()
that.contextMenuPositon = e.lnglat
that.getAddress()
infoWindowContent = `<div class="custom-infowindow input-card">
......@@ -142,7 +146,7 @@ export default {
</div>
<div class="item">
<span>车位编号</span>
<span class="item-text" >124.214.124</span>
<span class="item-text" >${markerData.parkingNumber}</span>
</div>
<div class="item">
<span>经纬度解析</span>
......@@ -257,20 +261,26 @@ export default {
AMap,
map,
id,
merchantId,
contextMenuPositon: { lng, lat }
} = this,
marker
let params = {
id,
parkingAddressLng: lng,
parkingAddressLat: lat
parkingAddressLat: lat,
merchantId
}
this.$apis.parkingSpace.addFlagparkingSpace(params).then(res => {
if (res) {
marker = new AMap.Marker({
icon: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
icon: require('@/assets/default.png'),
position: [lng, lat],
offset: new AMap.Pixel(-13, -30)
anchor: 'bottom-left',
extData: {
id
},
style: { width: '48px', height: '48px' }
})
marker.setMap(map)
this.initMarket(marker)
......@@ -402,8 +412,7 @@ export default {
let { map } = this
map.zoomOut()
}
},
}
}
</script>
......
......@@ -388,7 +388,10 @@ export default {
methods: {
//车位标记
sign(row){
this.$router.push(`/parkingPlace/sign/${row.id}`)
this.$router.push({
path:'/parkingPlace/sign',
query:row
})
},
openUploadDialog(row) {
this.curId = row.id
......
<template>
<map-container width="100%" height="100%" :id="id"></map-container>
<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: '100%', height: '100%' }"></div>
</div>
</template>
<script>
let content = [],
contextMenu
import AMapLoader from '@amap/amap-jsapi-loader' //按需引入依赖
export default {
data() {
return {
id: this.$route.params.id
input: [],
adrList: [],
placeSearch: '',
map: '',
address: '',
markerData: '',
contextMenuPositon: '', //右键菜单位置
controlList: [
{
icon: 'moon',
name: '卫星'
},
{
icon: 'ranging',
name: '测距'
},
{
icon: 'location',
name: '定位'
},
{
icon: 'magnify',
name: '放大'
},
{
icon: 'reduce',
name: '缩小'
}
],
activeIndex: ''
}
},
beforeCreate() {
console.log(contextMenu)
contextMenu && contextMenu.close()
},
mounted() {
this.merchantId = this.$globalState.session.merchantId
this.queryData = this.$route.query
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.getParkingSpaceList()
that.getContextMenu( that.map)
})
.catch(e => {
console.log(e)
})
},
getParkingSpaceList() {
let params = {
pageSize: 1000,
pageNum: 1,
locateFlag: 1
},
marker,
delFlag,
icon
let { AMap, map, queryData } = this
this.$apis.parkingSpace.getParkingSpaceListApi(params).then(res => {
if (res.list) {
for (let item of res.list) {
if (item.id === queryData.id) {
delFlag = 1
icon = 'select'
} else {
delFlag = 0
icon = 'default'
}
marker = new AMap.Marker({
icon: require(`@/assets/${icon}.png`),
position: [item.parkingAddressLng, item.parkingAddressLat],
anchor: 'bottom-left',
clickable: true,
extData: {
id: item.id,
parkingNumber: item.parkingNumber
},
style: { width: '48px', height: '48px' }
})
marker.setMap(map)
//是否可删除 1=》可以
this.initMarket(marker, delFlag)
}
}
})
},
initMarket(marker, delFlag) {
let { map, AMap } = this,
that = this,
infoWindowContent,
infoWindow
if (marker) {
marker.on('click', function (e) {
that.markerData = marker.getExtData()
that.contextMenuPositon = e.lnglat
that.getAddress()
infoWindowContent = `
<div class="title">新增标记</div>
<div class="custom-item">
<div class="item">
<span>经度</span>
<span class="item-text" >${that.contextMenuPositon.lng}</span>
</div>
<div class="item">
<span>纬度</span>
<span class="item-text" >${that.contextMenuPositon.lat}</span>
</div>
<div class="item">
<span>车位编号</span>
<span class="item-text" >${that.markerData.parkingNumber}</span>
</div>
<div class="item">
<span>经纬度解析</span>
<span class="item-text" >${that.address}</span>
</div>
</div>
<div>
`
if (delFlag == 1) {
infoWindowContent += ` <div class="footer">
<div class="cancel">取消</div>
<div class="del">删除</div>
</div>`
}
infoWindow = new AMap.InfoWindow({
content: infoWindowContent
})
infoWindow.open(map, that.contextMenuPositon)
that.bindEvent(infoWindow, marker)
})
}
},
initContent() {
let { AMap, } = 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('') })
},
// isOpen:1=>打开,0=>关闭,manipulator:操作物
getContextMenu(manipulator,isOpen) {
let that = this;
isOpen=isOpen||!this.queryData.parkingAddressFlag
this.initContent()
//地图绑定鼠标右击事件——弹出右键菜单
manipulator.on('rightclick', function (e) {
contextMenu.close()
if (isOpen) {
contextMenu.open(that.map, e.lnglat)
}
that.contextMenuPositon = e.lnglat //右键菜单位置
that.getAddress()
that.marketEvent()
})
},
marketEvent() {
let marker = document.getElementById('marker')
marker &&
marker.addEventListener('click', () => {
this.addMarkerMenu()
})
marker = null
},
addMarkerMenu() {
let { map, AMap, queryData, contextMenuPositon, address } = this,
infoWindow,
infoWindowContent
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" >${queryData.parkingNumber}</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, marker) {
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, marker)
})
confirmBtn = null
cancelBtn = null
delBtn = null
},
confirm(infoWindow) {
let {
AMap,
map,
queryData,
merchantId,
contextMenuPositon: { lng, lat }
} = this,
marker
let params = {
id: queryData.id,
parkingAddressLng: lng,
parkingAddressLat: lat,
merchantId
}
this.$apis.parkingSpace.addFlagparkingSpace(params).then(res => {
if (res) {
marker = new AMap.Marker({
icon: require('@/assets/select.png'),
position: [lng, lat],
anchor: 'bottom-left',
extData: {
id: queryData.id,
parkingNumber: queryData.parkingNumber
},
style: { width: '48px', height: '48px' }
})
marker.setMap(map)
this.initMarket(marker, 1)
infoWindow.close()
this.$message.success('车位标记成功')
this.getContextMenu(this.map,0)
}
})
},
cancel(infoWindow) {
infoWindow.close()
},
del(infoWindow, marker) {
let { markerData } = this,
params
params = {
id: markerData.id
}
this.$apis.parkingSpace.deleteFlagparkingSpaceparams(params).then(res => {
if (res) {
marker.hide()
infoWindow.close()
this.$message.success('删除成功')
this.getContextMenu(this.map,1)
}
})
},
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,
circle
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.getContextMenu(circle)
// this.shroudContextMenu(e.location)
} else {
//获取地址
geocoder = new AMap.Geocoder({
radius: 500 //范围,默认:500
})
geocoder.getAddress([contextMenuPositon.lng, contextMenuPositon.lat], function (status, result) {
if (status === 'complete' && result.regeocode) {
that.address = result.regeocode.formattedAddress
// console.log(result.regeocode,that.address)
}
})
}
},
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()
}
},
beforeDestroy() {
this.map.destroy()
}
}
</script>
<style>
<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
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!