Commit aec0f986 authored by Administrator's avatar Administrator

添加设备拾取坐标

parent d8716b7f
<template> <template>
<div class="amap-page-container"> <div class="amap-page-container">
<el-amap-search-box class="search-box" style="top:52px" :search-option="searchOption" :on-search-result="onSearchResult"></el-amap-search-box> <el-amap-search-box
<el-amap vid="amapDemo" :center="mapCenter" :zoom="zoom" class="amap-demo" :events="events"> class="search-box"
<el-amap-marker v-for="marker in markers" :key="marker.id" :position="marker"></el-amap-marker> :search-option="searchOption"
:on-search-result="onSearchResult"
>
</el-amap-search-box>
<el-amap
vid="amapDemo"
:center="mapCenter"
:zoom="zoom"
class="amap-demo"
:plugin="plugin"
:events="events"
>
<el-amap-marker
vid="component-marker"
:position="[lng, lat]"
>
</el-amap-marker>
</el-amap> </el-amap>
<div class="toolbar"> <div class="toolbar">
position: {{ lng }}, {{ lat }} 坐标: {{ lng }}, {{ lat }}
<el-button type="primary" @click="mapConfirm(true)">确定</el-button>
<el-button type="info" @click="mapConfirm(false)">取消</el-button>
</div> </div>
</div> </div>
</template> </template>
...@@ -15,46 +33,41 @@ import VueAMap from 'vue-amap'; ...@@ -15,46 +33,41 @@ import VueAMap from 'vue-amap';
Vue.use(VueAMap); Vue.use(VueAMap);
VueAMap.initAMapApiLoader({ VueAMap.initAMapApiLoader({
key: '2719fe261fee06a08dcb4980990879da', key: '2719fe261fee06a08dcb4980990879da',
plugin: ['AMap.Geocoder'], plugin: ['ToolBar'],
v: '1.4.4', v: '1.4.4',
uiVersion: '1.0.11', uiVersion: '1.0.11',
}); });
export default { export default {
data() { data() {
const self = this;
return { return {
lng: 0, lng: 0,
lat: 0, lat: 0,
zoom: 13, zoom: 13,
center: [114.512417, 38.061424], center: [114.509327, 38.046555],
markers: [ plugin: [
[121.59996, 31.197646], {
[121.40018, 31.197622], pName: 'ToolBar',
[121.69991, 31.207649], events: {
init(instance) {
// console.log(instance);
},
},
},
], ],
markers: [],
searchOption: { searchOption: {
city: '上海', city: '石家庄',
citylimit: true, citylimit: false,
}, },
mapCenter: [114.512417, 38.061424], mapCenter: [114.512417, 38.061424],
address: '', address: '',
events: { events: {
click(e) { click(e) {
const self = this;
const { lng, lat } = e.lnglat; const { lng, lat } = e.lnglat;
self.lng = lng; self.lng = lng.toFixed(6);
self.lat = lat; self.lat = lat.toFixed(6);
// var geocoder = VueAMap.Geocoder({ console.log(lng, lat);
// radius: 1000,
// extensions: 'all',
// });
// geocoder.getAddress([lng, lat], function(status, result) {
// if (status === 'complete' && result.info === 'OK') {
// if (result && result.regeocode) {
// self.address = result.regeocode.formattedAddress;
// self.$nextTick();
// }
// }
// });
}, },
}, },
}; };
...@@ -62,10 +75,11 @@ export default { ...@@ -62,10 +75,11 @@ export default {
created() { created() {
}, },
methods: { methods: {
addMarker() { mapConfirm(state) {
const lng = 121.5 + Math.round(Math.random() * 1000) / 10000; this.$emit(
const lat = 31.197646 + Math.round(Math.random() * 500) / 10000; 'map-confirm',
this.markers.push([lng, lat]); { state: state, location: this.lng + ', ' + this.lat },
);
}, },
onSearchResult(pois) { onSearchResult(pois) {
var latSum = 0; var latSum = 0;
...@@ -82,8 +96,8 @@ export default { ...@@ -82,8 +96,8 @@ export default {
lat: latSum / pois.length, lat: latSum / pois.length,
}; };
this.mapCenter = [center.lng, center.lat]; this.mapCenter = [center.lng, center.lat];
this.lng = center.lng; this.lng = center.lng.toFixed(6);
this.lat = center.lat; this.lat = center.lat.toFixed(6);
} }
}, },
}, },
...@@ -92,14 +106,18 @@ export default { ...@@ -92,14 +106,18 @@ export default {
<style> <style>
.amap-demo { .amap-demo {
height: 600px !important; height: 90vh !important;
} }
.search-box { .search-box {
position: absolute; position: absolute;
top: 25px; top: 60px;
left: 20px; left: 30%;
} }
.amap-page-container { .amap-page-container {
position: relative; position: relative;
top: -45px;
}
.toolbar {
padding: 20px;
} }
</style> </style>
...@@ -49,9 +49,8 @@ ...@@ -49,9 +49,8 @@
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-card> </el-card>
<el-drawer title="拾取坐标" :visible.sync="drawer" :direction="direction" :before-close="handleClose"> <el-drawer title="拾取坐标" :visible.sync="drawer" :direction="direction" :before-close="handleClose" size="50%" :with-header="false">
<span style="color: #E6A23C;" @click="positionUrl">如果找不到坐标!请点击</span> <div><CoordinateMap @map-confirm="mapConfirmData" @giveLnglat="getLnglat"></CoordinateMap></div>
<div><CoordinateMap @giveLnglat="getLnglat"></CoordinateMap></div>
</el-drawer> </el-drawer>
</div> </div>
</template> </template>
...@@ -127,6 +126,15 @@ export default { ...@@ -127,6 +126,15 @@ export default {
this.addUserDevices(); this.addUserDevices();
}, },
methods: { methods: {
mapConfirmData(text) {
if (text.state === true) {
this.form.devicecoord = text.location;
this.drawer = false;
}
if (text.state === false) {
this.drawer = false;
}
},
checkPermission, checkPermission,
onSubmit(formName) { onSubmit(formName) {
this.$refs[formName].validate((valid) => { this.$refs[formName].validate((valid) => {
...@@ -181,6 +189,7 @@ export default { ...@@ -181,6 +189,7 @@ export default {
this.drawer = false; this.drawer = false;
}, },
handleClose(done) { handleClose(done) {
console.log(done);
this.$confirm('确认关闭?') this.$confirm('确认关闭?')
.then(_ => { .then(_ => {
done(); done();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment