地图修改

This commit is contained in:
Sliverber 2024-07-24 18:00:08 +08:00
parent 74be13b534
commit 23ea8a9c71
5 changed files with 901 additions and 726 deletions

View File

@ -6,7 +6,7 @@ ENV = 'development'
# 共享电动车管理系统/开发环境 # 共享电动车管理系统/开发环境
# VUE_APP_BASE_API = 'https://dche.ccttiot.com/prod-api' # VUE_APP_BASE_API = 'https://dche.ccttiot.com/prod-api'
VUE_APP_BASE_API = 'http://localhost:8080' VUE_APP_BASE_API = 'http://192.168.2.189:8080'
# 路由懒加载 # 路由懒加载
VUE_CLI_BABEL_TRANSPILE_MODULES = true VUE_CLI_BABEL_TRANSPILE_MODULES = true

View File

@ -54,6 +54,14 @@ export function updateArea(data) {
data: data data: data
}) })
} }
// 修改导览
export function putguide(data) {
return request({
url: '/system/area/guide',
method: 'put',
data: data
})
}
// 修改运营区 // 修改运营区
export function updateArea2(data) { export function updateArea2(data) {
return request({ return request({

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="place-search-map" :style="{width: width, height: height}" v-loading="loading"> <div class="place-search-map" :style="{ width: width, height: height }" v-loading="loading">
<div id="container"></div> <div id="container"></div>
<div class="input-card"> <div class="input-card">
<h4>轨迹回放控制</h4> <h4>轨迹回放控制</h4>
@ -52,7 +52,7 @@ export default {
loading: false, loading: false,
keyword: null, keyword: null,
markers: [], markers: [],
line:[], line: [],
area: { area: {
province: '福建省', province: '福建省',
city: '宁德市', city: '宁德市',
@ -99,7 +99,40 @@ export default {
// //
trajectory() { trajectory() {
this.line = JSON.parse(this.tripRouteStr) this.line = JSON.parse(this.tripRouteStr)
console.log("this.line================"+this.line) console.log("this.line================" + this.line)
let abb;
try {
abb = JSON.parse(this.tripRouteStr);
} catch (error) {
console.error("Error parsing tripRouteStr:", error);
return;
}
let latitude = parseFloat(abb[0][1]);
let longitude = parseFloat(abb[0][0]);
let latitude1 = parseFloat(abb[abb.length - 1][1]);
let longitude1 = parseFloat( abb[abb.length - 1][0]);
this.marker = new AMap.Marker({
map: this.map,
position: [longitude, latitude],
icon: new AMap.Icon({
size: new AMap.Size(25, 38), //
image: "https://lxnapi.ccttiot.com/bike/img/static/u06paUGiHLvL08Pw7BGr",
imageSize: new AMap.Size(25, 38) //
}),
offset: new AMap.Pixel(-12.5, -19.5),
});
this.marker = new AMap.Marker({
map: this.map,
position: [longitude1, latitude1],
icon: new AMap.Icon({
size: new AMap.Size(25, 38), //
image: "https://lxnapi.ccttiot.com/bike/img/static/uwpAj9vYtPRmhtTOtflx",
imageSize: new AMap.Size(25, 38) //
}),
offset: new AMap.Pixel(-12.5, -19.5),
});
// console.log(latitude,longitude,'longitudelongitudelongitude');
let line = this.line; let line = this.line;
this.marker = new AMap.Marker({ this.marker = new AMap.Marker({
map: this.map, map: this.map,
@ -196,7 +229,7 @@ export default {
line-height: 1.5; line-height: 1.5;
border-radius: 1rem; border-radius: 1rem;
-webkit-appearance: button; -webkit-appearance: button;
cursor:pointer; cursor: pointer;
} }
.input-item { .input-item {

View File

@ -2,7 +2,7 @@
<div class="container"> <div class="container">
<div class="input-card-right"> <div class="input-card-right">
<div class="img"> <div class="img">
<image-upload v-model="picture" /> <image-upload :limit="1" :isShowTip="false" v-model="picture" />
</div> </div>
<el-button :style="topRightCoord ? buttonStyleActive : buttonStyleInactive" @click="setClickType('topRight')"> <el-button :style="topRightCoord ? buttonStyleActive : buttonStyleInactive" @click="setClickType('topRight')">
@ -16,8 +16,12 @@
<el-button @click="generateMap" :disabled="!canGenerateMap"> <el-button @click="generateMap" :disabled="!canGenerateMap">
生成导览地图 生成导览地图
</el-button> </el-button>
<el-button @click="saveMap" :disabled="!canSaveMap">
保存
</el-button>
</div> </div>
<div id="amap-container" class="map-container"></div> <div id="amap-container" class="map-container"></div>
<div class="coordinates"> <div class="coordinates">
@ -25,15 +29,16 @@
<div v-if="bottomLeftCoord">左下角: {{ bottomLeftCoord }}</div> <div v-if="bottomLeftCoord">左下角: {{ bottomLeftCoord }}</div>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import AMapLoader from "@amap/amap-jsapi-loader"; import AMapLoader from "@amap/amap-jsapi-loader";
import globalConfig from '@/utils/config/globalConfig'; import globalConfig from '@/utils/config/globalConfig';
import {getArea, optionselect as getAreaOptionselect} from "@/api/system/area"; import { getArea, putguide } from "@/api/system/area";
export default { export default {
name: "NewPage", name: "NewPage",
data() { data() {
return { return {
map: null, map: null,
@ -44,17 +49,31 @@ export default {
picture: '', picture: '',
buttonStyleActive: 'background-color: #409EFF; color: white;', buttonStyleActive: 'background-color: #409EFF; color: white;',
buttonStyleInactive: 'background-color: #fff; color: #409EFF;', buttonStyleInactive: 'background-color: #fff; color: #409EFF;',
areaLon: null,
areaLat: null,
queryParams: {
pageNum: 1,
pageSize: 10,
parkingName: null,
areaId: null,
type: "2"
},
// id
defaultAreaId: "",
isMapGenerated: false,
}; };
}, },
computed: { computed: {
canGenerateMap() { canGenerateMap() {
return this.picture && this.topRightCoord && this.bottomLeftCoord; return this.picture && this.topRightCoord && this.bottomLeftCoord;
},
canSaveMap() {
return this.isMapGenerated;
} }
}, },
created() { created() {
const areaId = this.$route.params && this.$route.params.areaId; const areaId = this.$route.params && this.$route.params.areaId;
this.getArea(areaId); this.getArea(areaId);
// this.getAreaList();
}, },
mounted() { mounted() {
this.initMap(); this.initMap();
@ -67,7 +86,6 @@ export default {
this.areaLon = response.data.longitude; this.areaLon = response.data.longitude;
this.areaLat = response.data.latitude; this.areaLat = response.data.latitude;
this.defaultAreaId = response.data.areaId; this.defaultAreaId = response.data.areaId;
this.getList();
}); });
}, },
initMap() { initMap() {
@ -84,6 +102,7 @@ export default {
this.map = new AMap.Map("amap-container", { this.map = new AMap.Map("amap-container", {
viewMode: "3D", viewMode: "3D",
zoom: 13, zoom: 13,
center: [this.areaLon, this.areaLat], //
}); });
this.map.setFitView(); this.map.setFitView();
this.map.on('click', this.handleMapClick); this.map.on('click', this.handleMapClick);
@ -93,33 +112,49 @@ export default {
}, },
setClickType(type) { setClickType(type) {
this.clickType = type; this.clickType = type;
//
if (type === 'topRight' && this.topRightCoord) {
this.clearMarker('topRight');
this.topRightCoord = null;
} else if (type === 'bottomLeft' && this.bottomLeftCoord) {
this.clearMarker('bottomLeft');
this.bottomLeftCoord = null;
}
}, },
handleMapClick(event) { handleMapClick(event) {
const lnglat = event.lnglat; const lnglat = event.lnglat;
//
if (this.clickType === 'topRight') { if (this.clickType === 'topRight') {
this.topRightCoord = lnglat; this.topRightCoord = lnglat;
this.addMarker(lnglat, 'topRight');
} else if (this.clickType === 'bottomLeft') { } else if (this.clickType === 'bottomLeft') {
this.bottomLeftCoord = lnglat; this.bottomLeftCoord = lnglat;
this.addMarker(lnglat, 'bottomLeft');
} }
//
const marker = new AMap.Marker({
position: lnglat,
});
this.map.add(marker);
this.markers.push(marker);
// //
this.clickType = null; this.clickType = null;
}, },
clearMarkers() { addMarker(lnglat, type) {
this.markers.forEach(marker => { //
this.map.remove(marker); this.clearMarker(type);
//
const marker = new AMap.Marker({
position: lnglat,
});
this.map.add(marker);
this.markers.push({ marker, type });
},
clearMarker(type) {
this.markers = this.markers.filter(({ marker, type: markerType }) => {
if (markerType === type) {
this.map.remove(marker);
return false;
}
return true;
}); });
this.markers = [];
this.topRightCoord = null;
this.bottomLeftCoord = null;
}, },
generateMap() { generateMap() {
if (!this.canGenerateMap) { if (!this.canGenerateMap) {
@ -136,14 +171,20 @@ export default {
const topRight = lnglatToFixed(this.topRightCoord); const topRight = lnglatToFixed(this.topRightCoord);
const bottomLeft = lnglatToFixed(this.bottomLeftCoord); const bottomLeft = lnglatToFixed(this.bottomLeftCoord);
console.log('Top Right:', topRight);
console.log('Bottom Left:', bottomLeft);
// //
const bounds = new AMap.Bounds([bottomLeft.lng, bottomLeft.lat], [topRight.lng, topRight.lat]); const bounds = new AMap.Bounds([bottomLeft.lng, bottomLeft.lat], [topRight.lng, topRight.lat]);
console.log('Bounds:', bounds);
// //
const imageLayer = new AMap.ImageLayer({ const imageLayer = new AMap.ImageLayer({
url: this.picture, url: this.picture,
bounds: bounds, bounds: bounds,
zooms: [15, 20] zooms: [15, 20],
zIndex: 999 // zIndex
}); });
// //
@ -155,6 +196,34 @@ export default {
// //
this.map.add(imageLayer); this.map.add(imageLayer);
//
this.isMapGenerated = true;
},
saveMap() {
if (!this.canSaveMap) {
this.$message.error('请先生成导览地图');
return;
}
//
const formatLngLat = (lnglat) => `${lnglat.lng},${lnglat.lat}`;
//
const mapData = {
guideMap: this.picture,
upperRight: formatLngLat(this.topRightCoord),
lowerLeft: formatLngLat(this.bottomLeftCoord),
areaId: this.defaultAreaId
};
putguide(mapData).then(response => {
//
});
// mapData
console.log('保存地图数据:', mapData);
this.$message.success('地图数据已保存');
} }
}, },
}; };
@ -172,11 +241,14 @@ export default {
} }
.input-card-right { .input-card-right {
position: fixed;
top: 100px;
left: 230px;
z-index: 100;
width: 100%; width: 100%;
display: flex; display: flex;
flex-wrap: nowrap; flex-wrap: nowrap;
align-items: flex-end; align-items: flex-end;
// justify-content: center;
margin-bottom: 10px; margin-bottom: 10px;
} }
@ -193,4 +265,4 @@ export default {
padding: 10px; padding: 10px;
border-radius: 5px; border-radius: 5px;
} }
</style> </style>

File diff suppressed because it is too large Load Diff