修改中心点定位

master
doublekou 1 year ago
parent 08c30cac9c
commit a649860501

@ -223,14 +223,21 @@
<!-- 高德地图 -->
<script>
window._AMapSecurityConfig = {
securityJsCode: 'ac1232036e1e20026f1e3e95338fc9c4'
securityJsCode: 'f811546a61cb67e8bbac45b371931323'
}
// window._AMapSecurityConfig = {
// securityJsCode: 'bfba507dd2b87770ba82019567e5bd4b'
// }
</script>
<!--引入高德地图JSAPI -->
<script
type="text/javascript"
src="https://webapi.amap.com/maps?v=2.0&key=df6e9416230b57f3c7f48be57dd2f813&plugin=AMap.Autocomplete,AMap.PlaceSearch,AMap.SearchNearBy,AMap.Geocoder,AMap.Geolocation,AMap.Marker"
src="https://webapi.amap.com/maps?v=2.0&key=1d3839a0fe4ad113f7d88ec3775107b7&plugin=AMap.Autocomplete,AMap.PlaceSearch,AMap.SearchNearBy,AMap.Geocoder,AMap.Geolocation,AMap.Marker"
></script>
<!-- <script
type="text/javascript"
src="https://webapi.amap.com/maps?v=2.0&key=69f36fd863068da639e2c7db66b437bf&plugin=AMap.Autocomplete,AMap.PlaceSearch,AMap.SearchNearBy,AMap.Geocoder,AMap.Geolocation,AMap.Marker"
></script> -->
<!--引入UI组件库1.1版本) -->
<!-- <script src="https://webapi.amap.com/ui/1.1/main.js"></script> -->
</body>

@ -189,6 +189,8 @@ export interface CustomerDTO {
distinguish?: string
//详细地址
detailAddress?: any
//门牌号
otherAddressesInfo?: string
//半径
radius?: any
//报名状态

@ -109,15 +109,22 @@
</a-col>
<a-col :xl="10" :md="10" :sm="10">
<a-form-item
:rules="[{ required: true, message: '请输入小区名称', trigger: 'blur' }]"
:rules="[{ required: true, message: '请输入小区名称', trigger: 'change' }]"
name="detailAddress"
>
<a-input
id="tipinput"
v-model:value="formModel.detailAddress"
autocomplete="off"
placeholder="请输入小区名称"
:disabled="title === '编辑预约'"
:readonly="title === '详情' || title === '分发'"
:disabled="title === '编辑预约' || title === '编辑'"
class="custom-tooltip"
:title="formModel.address && formModel.address.length === 0 ? '请先选择省市区' : ''"
:readonly="
title === '详情' ||
title === '分发' ||
(formModel.address && formModel.address.length === 0)
"
/>
</a-form-item>
</a-col>
@ -142,7 +149,7 @@
<a-button
v-if="title === '新建预约' || title === '编辑预约' || title === '编辑'"
type="primary"
@click="match"
@click="match(formModel.detailAddress)"
>匹配</a-button
>
<a-button
@ -448,6 +455,12 @@ const addressChange = (value: any) => {
formModel.economize = value[0]
formModel.market = value[1]
formModel.distinguish = value[2]
city.value = value[1].slice(0, -1)
cityAnddistinguish.value = value[1] + value[2]
console.log(cityAnddistinguish.value, 'cityAnddistinguish.value')
auto()
// console.log(city.value, 'city.value')
// formModel.detailAddress = value.toString() + formModel.detailAddress
}
}
@ -521,14 +534,14 @@ const infoWindows = ref<any>({})
//id
let previousId: any = null
//
const pagingQuery = () => {
const pagingQuery = (lng: number, lat: number) => {
if (circle.value) {
map.value.remove(circle.value)
}
const color = '#DFEBF3'
//
circle.value = new AMap.Circle({
center: [lng.value, lat.value], //
center: [lng, lat], //
radius: formModel.radius, //
fillColor: color, //
strokeColor: '#a1ceeb', //
@ -537,92 +550,89 @@ const pagingQuery = () => {
//
map.value.add(circle.value)
doRequest(
getStoreData({ longitude: lng.value, latitude: lat.value, distance: formModel.radius }),
{
onSuccess: (result: any) => {
if (result.code === 200) {
if (result.data.length === 0) {
message.info('当前位置附近暂无相关门店')
} else {
const ids = formModel.customStoreEntities.map(item => item.storeId)
listData.value.length = 0
result.data &&
result.data.forEach((item: any) => {
const disabled = ids.includes(Number(item.id))
listData.value.push({
title: item.storeName,
description: item.address,
content: item.nid ? item.nid : '',
disabled: disabled,
lat: item.latitude,
lng: item.longitude,
id: item.id,
index: item.index,
tel: item.nid ? item.nid : '',
reservationDate: item.reservationDate,
option: generateTimeSlots(item.tradeStartTime, item.tradeEndTime)
})
})
pois.push(...listData.value)
// ,
const targetZoom = 12
//
const placeSearch_CallBack = (data: any) => {
const poiArr = data
infoWindows.value = new AMap.InfoWindow({
autoMove: true,
isCustom: true,
offset: { x: 0, y: -30 } //
doRequest(getStoreData({ longitude: lng, latitude: lat, distance: formModel.radius }), {
onSuccess: (result: any) => {
if (result.code === 200) {
if (result.data.length === 0) {
message.info('当前位置附近暂无相关门店')
} else {
const ids = formModel.customStoreEntities.map(item => item.storeId)
listData.value.length = 0
result.data &&
result.data.forEach((item: any) => {
const disabled = ids.includes(Number(item.id))
listData.value.push({
title: item.storeName,
description: item.address,
content: item.nid ? item.nid : '',
disabled: disabled,
lat: item.latitude,
lng: item.longitude,
id: item.id,
index: item.index,
tel: item.nid ? item.nid : '',
reservationDate: item.reservationDate,
option: generateTimeSlots(item.tradeStartTime, item.tradeEndTime)
})
//marker
const markers = new AMap.Marker({
map: map.value,
position: [poiArr.lng, poiArr.lat],
// clickable: true,//,true
// offset: new AMap.Pixel(-90, -70), //
zIndex: 0, // 1000
extData: {
id: `${poiArr.id}`
// ...
}
})
markers.on('click', function (data: any) {
const currentId = data.target.getExtData().id
if (
infoWindows.value.getIsOpen() &&
(currentId === previousId || currentId === currentStoreId.value)
) {
// ,
currentStoreId.value = currentId
previousId = currentId
return false
}
infoWindows.value.open(map.value, markers.getPosition()) //
map.value.setZoomAndCenter(targetZoom, [data.lnglat.lng, data.lnglat.lat]) // 使
map.value.setCenter(markers.getPosition()) //
infoWindows.value.setContent(createContent(poiArr)) //
// ID
})
pois.push(...listData.value)
// ,
const targetZoom = 12
//
const placeSearch_CallBack = (data: any) => {
const poiArr = data
infoWindows.value = new AMap.InfoWindow({
autoMove: true,
isCustom: true,
offset: { x: 0, y: -30 } //
})
//marker
const markers = new AMap.Marker({
map: map.value,
position: [poiArr.lng, poiArr.lat],
// clickable: true,//,true
// offset: new AMap.Pixel(-90, -70), //
zIndex: 0, // 1000
extData: {
id: `${poiArr.id}`
// ...
}
})
markers.on('click', function (data: any) {
const currentId = data.target.getExtData().id
if (
infoWindows.value.getIsOpen() &&
(currentId === previousId || currentId === currentStoreId.value)
) {
// ,
currentStoreId.value = currentId
previousId = currentId
})
}
for (let i = 0; i < pois.length; i++) {
placeSearch_CallBack(pois[i])
}
return false
}
infoWindows.value.open(map.value, markers.getPosition()) //
map.value.setZoomAndCenter(targetZoom, [data.lnglat.lng, data.lnglat.lat]) // 使
map.value.setCenter(markers.getPosition()) //
infoWindows.value.setContent(createContent(poiArr)) //
// ID
currentStoreId.value = currentId
previousId = currentId
})
}
for (let i = 0; i < pois.length; i++) {
placeSearch_CallBack(pois[i])
}
}
}
}
)
})
}
//
const match = () => {
const match = async (detailAddress: string) => {
const fields = ['address', 'detailAddress', 'radius'] //
formRef.value
?.validateFields(fields)
@ -632,13 +642,48 @@ const match = () => {
lng.value = undefined
lat.value = undefined
map.value.clearMap()
city.value = formModel.market?.slice(0, -1)
AMap.plugin('AMap.Geocoder', function () {
geocoder.value = new AMap.Geocoder({
city: '全国' // city adcode citycode
city: city.value // city adcode citycode
})
})
//
getCenterMarker('match')
// 西180
//
const searchService = new AMap.PlaceSearch({
// API Key
key: '1d3839a0fe4ad113f7d88ec3775107b7',
//
version: '2.0'
})
const addressValue = formModel.address?.toString().split(',').join('') + detailAddress
//
// formModel.address?.toString().split(',').join('') + formModel.detailAddress
//
searchService.search(addressValue, (status: any, result: any) => {
if (status === 'complete' && result.info === 'OK') {
//
const pois = result.poiList.pois
//
console.log(pois, 'pois')
console.log(pois[0].location.lng, pois[0].location.lat, 'pois经纬度')
getCenterMarker('match', pois[0].location.lng, pois[0].location.lat)
// await getCenterMarker('match', formModel.otherAddressesInfo)
// if (type === 'match') {
// formModel.otherAddressesInfo = detailAddress
} else {
//
console.log('地点搜索失败')
}
})
// await getCenterMarker('match', formModel.otherAddressesInfo)
// // if (type === 'match') {
// pagingQuery()
// }
})
.catch(() => {
//
@ -824,6 +869,7 @@ const formModel = reactive<CustomerDTO>({
market: '',
distinguish: '',
detailAddress: '',
otherAddressesInfo: '',
radius: '5000',
enrollStatus: 1,
customStoreEntities: []
@ -905,6 +951,7 @@ defineExpose({
market,
distinguish,
detailAddress,
otherAddressesInfo,
radius,
customStoreVOList
} = data
@ -918,6 +965,7 @@ defineExpose({
formModel.market = market
formModel.distinguish = distinguish
formModel.detailAddress = detailAddress
formModel.otherAddressesInfo = otherAddressesInfo
formModel.radius = radius
formModel.customStoreEntities.push(...customStoreVOList)
//
@ -927,13 +975,17 @@ defineExpose({
if (opendata.type === 'audit') {
// isReadOnly.value = true
// reservationTimeisReadOnly.value = true
// city.value = formModel.market?.slice(0, -1)
isDisabled.value = true
handleMapInit()
title.value = '编辑'
// formModel.description = 1
} else if (opendata.type === 'edit') {
isDisabled.value = true
handleMapInit()
match(formModel.detailAddress)
//
// getCenterMarker('init')
title.value = '编辑预约'
}
}
@ -966,7 +1018,7 @@ defineExpose({
else if (opendata.type === 'distribute') {
isReadOnly.value = true
reservationTimeisReadOnly.value = true
handleMapInit()
// handleMapInit()
title.value = '分发'
formModel.description = 1
}
@ -984,6 +1036,7 @@ defineExpose({
//
// import { provincesAndCitiesAndAutonomousRegions } from '@/utils/geopolitical-customers'
import type { ShowSearchType } from 'ant-design-vue/es/cascader'
import { compileStyle } from 'vue/compiler-sfc'
declare const AMap: any
@ -998,68 +1051,200 @@ const autoComplete = ref()
//AMap.Marker
// Marker
const marker = ref<any>({})
// Marker
const markerCenter = ref<any>({})
const previousMarker = ref<any>({})
//AMap.Map
const map = ref<any>({})
//使geocoder/
// AMap.GeocodergetLocation
// AMap.GeocodergetAddress
const geocoder = ref<any>({})
//
const getCenterMarker = (type: string) => {
const addressValue =
//
formModel.address?.toString().split(',').join('') + formModel.detailAddress
geocoder.value.getLocation(addressValue, function (status: any, result: any) {
if (status === 'complete' && result.info === 'OK') {
// result
lng.value = result.geocodes[0].location.lng
lat.value = result.geocodes[0].location.lat
//
map.value.setCenter([lng.value, lat.value]) //
if (type === 'match') {
//
map.value.setZoom(12) // 12
}
//
const marker = new AMap.Marker({
position: [lng.value, lat.value], //
zIndex: 100 // z-index 100
})
const getCenterMarker = (type: string, lng: number, lat: number) => {
// const addressValue = ref<string>('')
// if (address) {
// addressValue.value = address
// } else {
// addressValue.value =
// //
// formModel.address?.toString().split(',').join('') + formModel.detailAddress
// // console.log(addressValue, 'addressValue')
// }
// console.log(addressValue.value, 'addressValue.value')
// 西180
// geocoder.value.getLocation(addressValue.value, function (status: any, result: any) {
// if (status === 'complete' && result.info === 'OK') {
// result
// lng.value = result.geocodes[0].location.lng
// lat.value = result.geocodes[0].location.lat
// lng.value = lng
// lat.value = lat
//
map.value.setCenter([lng, lat]) //
if (type === 'match' || type === 'select') {
//
map.value.setZoom(12) // 12
}
// console.log(lng.value, lat.value, 'lng.value, lat.value')
//
marker.setIcon(
new AMap.Icon({
image: 'https://webapi.amap.com/theme/v1.3/markers/n/mark_r.png', // 使 URL
size: new AMap.Size(18, 30), //
imageSize: new AMap.Size(18, 30) //
})
)
marker.setMap(map.value) //
}
if (type === 'match') {
pagingQuery()
}
if (previousMarker.value && type === 'select') {
map.value.remove(markerCenter.value) //
}
//
markerCenter.value = new AMap.Marker({
position: [lng, lat], //
zIndex: 100 // z-index 100
})
//
markerCenter.value.setIcon(
new AMap.Icon({
image: 'https://webapi.amap.com/theme/v1.3/markers/n/mark_r.png', // 使 URL
size: new AMap.Size(18, 30), //
imageSize: new AMap.Size(18, 30) //
})
)
markerCenter.value.setMap(map.value) //
previousMarker.value = marker // previousMarker
if (type === 'match') {
console.log(type, 'type')
pagingQuery(lng, lat)
}
// }
// })
}
//
const performQuery = (selectedTip: any) => {
const geocoder = new AMap.Geocoder()
const location = selectedTip.location
const performQuery = (selectedTip: any, detailAddress: string) => {
//
const searchService = new AMap.PlaceSearch({
// API Key
key: '1d3839a0fe4ad113f7d88ec3775107b7',
//
version: '2.0'
})
const addressValue = formModel.address?.toString().split(',').join('') + selectedTip.name
//
// formModel.address?.toString().split(',').join('') + formModel.detailAddress
// 使
geocoder.getAddress(location, function (status: any, result: any) {
//
searchService.search(addressValue, (status: any, result: any) => {
if (status === 'complete' && result.info === 'OK') {
//
const address = result.regeocode.formattedAddress
console.log('查询结果:', address)
// ...
//
const pois = result.poiList.pois
//
console.log(pois, 'pois')
console.log(pois[0].location.lng, pois[0].location.lat, 'pois经纬度')
getCenterMarker('select', pois[0].location.lng, pois[0].location.lat)
formModel.otherAddressesInfo = `${pois[0].location.lng},${pois[0].location.lat}`
} else {
//
console.log('地点搜索失败')
}
})
// const geocoder = new AMap.Geocoder()
// const location = selectedTip.location
// if (location) {
// // 使
// geocoder.getAddress(location, function (status: any, result: any) {
// if (status === 'complete' && result.info === 'OK') {
// //
// const address = result.regeocode.formattedAddress
// console.log('', address)
// console.log(detailAddress, 'detailAddress')
// // ...
// match()
// // detailAddress = detailAddress.substring(0, 14)
// // if (detailAddress === '8·') {
// // detailAddress = detailAddress.substring(0, detailAddress.indexOf('') + 1)
// // console.log(detailAddress, 'detailAddress1111')
// // //
// // getCenterMarker('select', detailAddress)
// // formModel.otherAddressesInfo = detailAddress
// // } else {
// // //
// // getCenterMarker('select', detailAddress)
// // formModel.otherAddressesInfo = detailAddress
// // }
// }
// })
// } else {
// message.info(',')
// }
}
const city = ref<string | undefined>('')
const cityAnddistinguish = ref<string | undefined>('')
const detailAddress = ref<string>('')
const auto = async () => {
await AMap.plugin('AMap.AutoComplete', function () {
// Autocomplete
// cityAnddistinguish.value
const autoOptions = {
city: '浙江省杭州市西湖区', //
input: 'tipinput',
citylimit: true,
noLocation: true //
}
console.log(cityAnddistinguish.value, 'cityAnddistinguish.value')
autoComplete.value = new AMap.AutoComplete(autoOptions)
setTimeout(() => {
// autoComplete.value?.on('beforeSearch', (e: any) => {
// const keywords = e.keywords //
// console.log(keywords, 'keywords')
// e.keywords = `${formModel.market} ${keywords}` //
// // const selectedDistrict = formModel.market //
// //
// // if (selectedDistrict && selectedDistrict !== '西') {
// // e.keywords = `${selectedDistrict} ${keywords}` //
// // }
// })
autoComplete.value?.on('select', (e: any) => {
// console.log(e.poi, 'e.poi')
// const selectedTip = e.poi //
// formModel.detailAddress = selectedTip.name // 使 v-model
// detailAddress.value = selectedTip.district + selectedTip.address
// // console.log(formModel.detailAddress, 'formModel.detailAddress')
// performQuery(selectedTip, detailAddress.value) //
const selectedTip = e.poi
if (selectedTip.district === formModel.market) {
//
formModel.detailAddress = selectedTip.name
detailAddress.value = selectedTip.district + selectedTip.address
performQuery(selectedTip, detailAddress.value)
} else {
//
message.info(`只能选择${formModel.distinguish}内的地址`)
// console.log('西')
}
})
}, 300)
AMap.plugin('AMap.Geocoder', function () {
geocoder.value = new AMap.Geocoder({
// city: '' // city adcode citycode
city: city.value
})
})
// geocoder.value = new AMap.Geocoder({
// city: '010' //
// })
})
}
//
const initMap = () => {
const initMap = async () => {
map.value = new AMap.Map('draw-station-container', {
// center: [120.1551, 30.2741], //
zoom: 18 //
@ -1084,32 +1269,28 @@ const initMap = () => {
// }
// })
AMap.plugin('AMap.AutoComplete', function () {
// Autocomplete
const autoOptions = {
//city
input: 'tipinput'
}
// AMap.plugin('AMap.AutoComplete', function () {
// // Autocomplete
// const autoOptions = {
// city: city.value, //
// input: 'tipinput'
// }
autoComplete.value = new AMap.AutoComplete(autoOptions)
// geocoder.value = new AMap.Geocoder({
// city: '010' //
// })
})
setTimeout(() => {
autoComplete.value?.on('select', (e: any) => {
const selectedTip = e.poi //
formModel.detailAddress = selectedTip.name // 使 v-model
performQuery(selectedTip) //
})
}, 300)
AMap.plugin('AMap.Geocoder', function () {
geocoder.value = new AMap.Geocoder({
city: '全国' // city adcode citycode
})
})
//
getCenterMarker('init')
// autoComplete.value = new AMap.AutoComplete(autoOptions)
// // geocoder.value = new AMap.Geocoder({
// // city: '010' //
// // })
// })
await auto()
if (title.value === '编辑预约' || title.value === '编辑') {
// city.value = formModel.market?.slice(0, -1)
//
getCenterMarker(
'init',
Number(formModel.otherAddressesInfo?.split(',')[0]),
Number(formModel.otherAddressesInfo?.split(',')[1])
)
}
// map.value.add(marker.value)
}
@ -1359,4 +1540,27 @@ const storeItemClick = (item: any, index: number) => {
::v-deep .ant-space-item {
width: 100% !important;
}
//a-input
.custom-tooltip {
position: relative;
}
.custom-tooltip::before {
content: attr(title);
position: absolute;
top: 100%;
left: 0;
width: 100%;
padding: 5px;
background-color: #f8f8f8;
border: 1px solid #ccc;
border-top: none;
font-size: 14px;
color: #333;
pointer-events: none;
opacity: 0;
transition: opacity 0.2s ease-in-out;
}
.custom-tooltip:hover::before {
opacity: 1;
}
</style>

@ -22,13 +22,13 @@ import { antdvStyleDeps } from './src/utils/resolvers'
//项目
// const serverAddress = 'http://admin.ballcat.cn'
//xy
const serverAddress = 'http://172.18.0.225:8000'
// const serverAddress = 'http://172.18.0.225:8000'
//jt
// const serverAddress = 'http://172.18.1.8:8000'
//ts
// const serverAddress = 'http://172.18.0.228:8000'
//测试
// const serverAddress = 'http://39.100.77.21:8000'
const serverAddress = 'http://39.100.77.21:8000'
//线上ip
// const serverAddress = 'http://175.27.212.74:80'

Loading…
Cancel
Save