Commit c36dce93 by chenwq

切换地图

1 parent f1176dea
...@@ -1895,6 +1895,51 @@ ...@@ -1895,6 +1895,51 @@
"integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==",
"dev": true "dev": true
}, },
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"optional": true,
"requires": {
"color-convert": "^2.0.1"
}
},
"chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"optional": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"optional": true,
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true,
"optional": true
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true,
"optional": true
},
"ssri": { "ssri": {
"version": "8.0.1", "version": "8.0.1",
"resolved": "https://registry.npmjs.org/ssri/-/ssri-8.0.1.tgz", "resolved": "https://registry.npmjs.org/ssri/-/ssri-8.0.1.tgz",
...@@ -1903,6 +1948,28 @@ ...@@ -1903,6 +1948,28 @@
"requires": { "requires": {
"minipass": "^3.1.1" "minipass": "^3.1.1"
} }
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"optional": true,
"requires": {
"has-flag": "^4.0.0"
}
},
"vue-loader-v16": {
"version": "npm:vue-loader@16.8.3",
"resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-16.8.3.tgz",
"integrity": "sha512-7vKN45IxsKxe5GcVCbc2qFU5aWzyiLrYJyUuMz4BQLKctCj/fmCa0w6fGiiQ2cLFetNcek1ppGJQDCup0c1hpA==",
"dev": true,
"optional": true,
"requires": {
"chalk": "^4.1.0",
"hash-sum": "^2.0.0",
"loader-utils": "^2.0.0"
}
} }
} }
}, },
...@@ -13347,75 +13414,6 @@ ...@@ -13347,75 +13414,6 @@
} }
} }
}, },
"vue-loader-v16": {
"version": "npm:vue-loader@16.8.3",
"resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-16.8.3.tgz",
"integrity": "sha512-7vKN45IxsKxe5GcVCbc2qFU5aWzyiLrYJyUuMz4BQLKctCj/fmCa0w6fGiiQ2cLFetNcek1ppGJQDCup0c1hpA==",
"dev": true,
"optional": true,
"requires": {
"chalk": "^4.1.0",
"hash-sum": "^2.0.0",
"loader-utils": "^2.0.0"
},
"dependencies": {
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"optional": true,
"requires": {
"color-convert": "^2.0.1"
}
},
"chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"optional": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"optional": true,
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true,
"optional": true
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true,
"optional": true
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"optional": true,
"requires": {
"has-flag": "^4.0.0"
}
}
}
},
"vue-router": { "vue-router": {
"version": "3.6.5", "version": "3.6.5",
"resolved": "https://registry.npmjs.org/vue-router/-/vue-router-3.6.5.tgz", "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-3.6.5.tgz",
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
"glsx-common": "^2.0.9", "glsx-common": "^2.0.9",
"glsx-components": "^1.5.7", "glsx-components": "^1.5.7",
"vue": "^2.6.10", "vue": "^2.6.10",
"vue-amap": "^0.5.10",
"vue-router": "^3.1.3", "vue-router": "^3.1.3",
"vuex": "^3.1.2" "vuex": "^3.1.2"
}, },
......
import { http, http_common, http_merchant } from '@/main' import { http, http_common, http_merchant, http_province } from '@/main'
const path = 'dj.api.' const path = 'dj.api.'
const defaultPath = 'scrm.api.carlife.' const defaultPath = 'scrm.api.carlife.'
...@@ -58,4 +58,13 @@ const brandList = params => { ...@@ -58,4 +58,13 @@ const brandList = params => {
sign: true sign: true
}) })
} }
export default { getAreaInfoApi, getGoodsCategoryConfiguration, uploadImg, uploadVideo, brandList }
const getProvince = params => {
return http_province({
url: '/nesi/apiRegion/search',
method: 'GET',
data: params,
sign: true
})
}
export default { getAreaInfoApi, getGoodsCategoryConfiguration, uploadImg, uploadVideo, brandList, getProvince }
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
</el-input> </el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
<GLDialog :visible.sync="dialogMapVisible" :mode="'big'" bigTitle="选择地址"> <GLDialog v-if="dialogMapVisible" :visible.sync="dialogMapVisible" :mode="'big'" bigTitle="选择地址">
<map-view ref="mapForm" :mapHeight="mapHeight"></map-view> <map-view ref="mapForm" :mapHeight="mapHeight"></map-view>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button size="small" @click="dialogMapVisible = false">取 消</el-button> <el-button size="small" @click="dialogMapVisible = false">取 消</el-button>
...@@ -146,20 +146,26 @@ export default { ...@@ -146,20 +146,26 @@ export default {
**/ **/
// 获取省市信息 // 获取省市信息
provinceList() { provinceList() {
var params = {} var params = {
params.subdistrict = this.subdistrict keyword: '中国',
extensions_code: 1
}
params.sub_admin = this.subdistrict
// params.subdistrict = this.subdistrict
let data = '' let data = ''
for (let key in params) { for (let key in params) {
data += '&' + key + '=' + params[key] data += '&' + key + '=' + params[key]
} }
let path = `https://restapi.amap.com/v3/config/district?key=d22348363c34c266f772ae9b635eef2a` // let path = `https://restapi.amap.com/v3/config/district?key=d22348363c34c266f772ae9b635eef2a`
path = path + data // path = path + data
const path = this.$provinceUrl + data
const pro = fetch(path).then(res => { const pro = fetch(path).then(res => {
return res.json() return res.json()
}) })
if (this.provinceView) { if (this.provinceView) {
pro.then(r => { pro.then(r => {
this.AllData = r.districts[0].districts // this.AllData = r.districts[0].districts
this.AllData = JSON.parse(r.data).districts[0].districts
}) })
} }
return pro return pro
...@@ -240,8 +246,9 @@ export default { ...@@ -240,8 +246,9 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
if (this.provinceForm.fullAddress && !this.$refs.mapForm.address) { if (this.provinceForm.fullAddress && !this.$refs.mapForm.address) {
this.$refs.mapForm.address = this.provinceForm.fullAddress this.$refs.mapForm.address = this.provinceForm.fullAddress
this.$refs.mapForm.addMarker([this.provinceForm.lng, this.provinceForm.lat]) // this.$refs.mapForm.addMarker([this.provinceForm.lng, this.provinceForm.lat])
} }
this.$refs.mapForm.mapInit(this.provinceForm.lng, this.provinceForm.lat)
}) })
}, },
......
<template> <template>
<div class="map-box" :style="{ height: mapHeight + 'px' }"> <div class="map-box" :style="{ height: mapHeight + 'px' }">
<div id="container" style="width: 100%; height: 100%"></div> <div id="mapContainer" style="width: 100%; height: 100%"></div>
<div class="map-address">{{ address }}</div> <div class="map-address">{{ address }}</div>
<div id="myPageTop" style="position: absolute; top: 10px; width: 50%; left: 25%"> <div id="myPageTop" style="position: absolute; top: 10px; width: 50%; left: 25%">
<el-input placeholder="请输入关键字" v-model="input" class="input-with-select"> <el-input placeholder="请输入关键字" v-model="input" @keyup.enter.native="searchAddress" class="input-with-select">
<el-button slot="append" icon="el-icon-search" @click="searchAddress"></el-button> <el-button slot="append" icon="el-icon-search" @click="searchAddress"></el-button>
</el-input> </el-input>
</div> </div>
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
</template> </template>
<script> <script>
let map, marker, placeSearch let map, marker, geocoder
export default { export default {
name: 'map', name: 'map',
props: { props: {
...@@ -25,84 +25,70 @@ export default { ...@@ -25,84 +25,70 @@ export default {
return { return {
input: '', input: '',
address: '', address: '',
lnglat: [], lnglat: {},
geocoderAddress: {} geocoderAddress: {},
mapapi: null
} }
}, },
methods: { methods: {
mapInit() { async mapInit(lng, lat) {
map = new AMap.Map('container', { console.log(lng, lat, '==========', this.$mapapi)
resizeEnable: true, const mapapi = this.$mapapi
zoom: 20 map = await mapapi.invoke('Map', 'mapContainer')
}) mapapi.invoke('centerAndZoom', mapapi.invoke('Point', lng || 116.4033, lat || 39.9258), 15)
AMap.plugin(['AMap.PlaceSearch'], function() { map.enableScrollWheelZoom() // 启用滚轮放大缩小
//构造地点查询类 map.enableAutoResize() // 启用自动适应容器尺寸变化
placeSearch = new AMap.PlaceSearch({ geocoder = mapapi.invoke('Geocoder')
pageSize: 8, // 单页显示结果条数 if (lng && lat) {
pageIndex: 1, // 页码 this.addMarker({lng, lat}, true)
citylimit: false, //是否强制限制在设置的城市内搜索 }
// panel: "panel", // 结果列表将在此容器中进行展示。 // 右键菜单
autoFitView: true, // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围 mapapi.invoke('mapAddEventListener', 'click', (e) => {
renderStyle: 'default' this.getAddress(e.point)
})
}) })
// 添加列表点选监听事件
map.on('click', this.getAddress)
}, },
searchAddress() { searchAddress() {
let _this = this const mapapi = this.$mapapi
placeSearch.search(this.input, function(status, result) { mapapi.invoke('getPoint', this.input, res => {
if (status === 'complete' && result.poiList.pois.length) { // this.addMarker(res)
let lnglat = result.poiList.pois[0].location this.getAddress(res)
_this.getAddress(lnglat) }, '全国')
}
})
}, },
addMarker(lnglat) { addMarker(lnglat) {
let position const mapapi = this.$mapapi
let lnglatXY
this.lnglat = lnglat
if (lnglat.lng) { if (lnglat.lng) {
position = [lnglat.lng, lnglat.lat] const { lng, lat } = lnglat
lnglatXY = mapapi.invoke('Point', lng, lat)
} else { } else {
position = lnglat lnglatXY = mapapi.invoke('Point', lnglat[0], lnglat[1])
}
if (marker) {
mapapi.invoke('removeOverlay', marker)
} }
marker = new AMap.Marker({ marker = mapapi.invoke('Marker', lnglatXY, {
icon: new AMap.Icon({ icon:mapapi.invoke('Icon', require('@/assets/address.png'), mapapi.invoke('Size', 26, 36))
image: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
size: new AMap.Size(27, 34), //图标大小
imageSize: new AMap.Size(27, 34)
}),
position: position,
offset: new AMap.Pixel(-10, -10)
}) })
map.add(marker) mapapi.invoke('panTo', lnglatXY)
map.setFitView() mapapi.invoke('addOverlay', marker)
}, },
getAddress(e) { getAddress(e) {
let self = this let self = this
const mapapi = this.$mapapi
this.lnglat = e
let lnglat let lnglat
if (e.type == 'click') { if (e.lng) {
lnglat = e.lnglat const { lng, lat } = e
lnglat = mapapi.invoke('Point', lng, lat)
} else { } else {
let { lng, lat } = e lnglat = mapapi.invoke('Point', e[0], e[1])
lnglat = [lng, lat]
}
if (marker) {
marker.setMap(null)
marker = null
} }
self.addMarker(lnglat) self.addMarker(lnglat)
AMap.plugin('AMap.Geocoder', () => { geocoder.getLocation(lnglat, res => {
const geocoder = new AMap.Geocoder() this.address = res.surroundingPois.length ? res.surroundingPois[0].address : res.address
geocoder.getAddress(lnglat, (status, result) => { this.geocoderAddress = res.content.address_detail
self.lnglat = lnglat
self.address = result.regeocode.formattedAddress
geocoder.getLocation(self.address, (status, result) => {
if (status === 'complete' && result.info === 'OK') {
this.geocoderAddress = result.geocodes[0]
}
})
})
}) })
}, },
selectAddress(e) { selectAddress(e) {
...@@ -112,7 +98,7 @@ export default { ...@@ -112,7 +98,7 @@ export default {
}, },
mounted() { mounted() {
this.mapInit() // this.mapInit()
} }
} }
</script> </script>
...@@ -135,8 +121,8 @@ export default { ...@@ -135,8 +121,8 @@ export default {
width: 280px; width: 280px;
} }
.map-address { .map-address {
position: absolute; // position: absolute;
line-height: 20px; line-height: 20px;
bottom: -30px; // bottom: -30px;
} }
</style> </style>
...@@ -13,16 +13,18 @@ import './public-path' ...@@ -13,16 +13,18 @@ import './public-path'
import '@/assets/css/public.scss' import '@/assets/css/public.scss'
import '@/components' import '@/components'
import utils from './utils/index' import utils from './utils/index'
import GLMapSdk from '@/utils/glsk-mapapi-sdk'
// import 'glsx-components/dist/glsx-components.css' // import 'glsx-components/dist/glsx-components.css'
import { start } from '@/setup' import { start } from '@/setup'
import VueAMap from 'vue-amap' Vue.prototype.$mapapi = new GLMapSdk()
Vue.use(VueAMap) // import VueAMap from 'vue-amap'
// 初始化vue-amap // Vue.use(VueAMap)
VueAMap.initAMapApiLoader({ // // 初始化vue-amap
key: 'bd290dc27d0945959280753215ddda71', // 这里写你申请的高德地图的key // VueAMap.initAMapApiLoader({
plugin: ['AMap.PlaceSearch', 'AMap.Geocoder', 'AMap.Geolocation'], // key: 'bd290dc27d0945959280753215ddda71', // 这里写你申请的高德地图的key
v: '1.4.15' // plugin: ['AMap.PlaceSearch', 'AMap.Geocoder', 'AMap.Geolocation'],
}) // v: '1.4.15'
// })
Vue.config.productionTip = false Vue.config.productionTip = false
Vue.prototype.$apis = apis Vue.prototype.$apis = apis
Vue.prototype.size = 'small' Vue.prototype.size = 'small'
...@@ -33,3 +35,4 @@ export { bootstrap, mount, unmount } from '@/setup' ...@@ -33,3 +35,4 @@ export { bootstrap, mount, unmount } from '@/setup'
export const http = params => Vue.prototype.$http(params) export const http = params => Vue.prototype.$http(params)
export const http_merchant = params => Vue.prototype.$http_merchant(params) export const http_merchant = params => Vue.prototype.$http_merchant(params)
export const http_common = params => Vue.prototype.$http_common(params) export const http_common = params => Vue.prototype.$http_common(params)
export const http_province = params => Vue.prototype.$http_province(params)
...@@ -12,10 +12,11 @@ let instance = null ...@@ -12,10 +12,11 @@ let instance = null
Vue.use(ElementUI) Vue.use(ElementUI)
Vue.use(GLTable) Vue.use(GLTable)
export async function bootstrap({ history, common, messenger, globalState, routerBase }) { export async function bootstrap({ history, common, messenger, globalState, routerBase }) {
const { response, request, sign, secret, sign_common, request_common, request_merchant } = await fetchConfig(common) const { response, request, sign, secret, sign_common, request_common, request_merchant, provinceUrl } = await fetchConfig(common)
Vue.prototype.$history = history Vue.prototype.$history = history
Vue.prototype.$messenger = messenger Vue.prototype.$messenger = messenger
Vue.prototype.$globalState = globalState Vue.prototype.$globalState = globalState
Vue.prototype.$provinceUrl = provinceUrl
Vue.prototype.$common = common Vue.prototype.$common = common
Vue.prototype.$message = message Vue.prototype.$message = message
Vue.prototype.$messageBox = messageBox Vue.prototype.$messageBox = messageBox
......
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).GlMap=r()}(this,(function(){"use strict";function t(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=Array(r);e<r;e++)n[e]=t[e];return n}function r(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function e(t,r,e){return r&&function(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,i(n.key),n)}}(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function n(){n=function(){return r};var t,r={},e=Object.prototype,o=e.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",f=a.toStringTag||"@@toStringTag";function l(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{l({},"")}catch(t){l=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=r&&r.prototype instanceof g?r:g,a=Object.create(o.prototype),c=new P(n||[]);return i(a,"_invoke",{value:O(t,e,c)}),a}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=s;var p="suspendedStart",y="suspendedYield",v="executing",d="completed",m={};function g(){}function w(){}function b(){}var L={};l(L,c,(function(){return this}));var x=Object.getPrototypeOf,E=x&&x(x(T([])));E&&E!==e&&o.call(E,c)&&(L=E);var j=b.prototype=g.prototype=Object.create(L);function G(t){["next","throw","return"].forEach((function(r){l(t,r,(function(t){return this._invoke(r,t)}))}))}function S(t,r){function e(n,i,a,c){var u=h(t[n],t,i);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==typeof l&&o.call(l,"__await")?r.resolve(l.__await).then((function(t){e("next",t,a,c)}),(function(t){e("throw",t,a,c)})):r.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return e("throw",t,a,c)}))}c(u.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new r((function(r,n){e(t,o,r,n)}))}return n=n?n.then(i,i):i()}})}function O(r,e,n){var o=p;return function(i,a){if(o===v)throw Error("Generator is already running");if(o===d){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=_(c,n);if(u){if(u===m)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var f=h(r,e,n);if("normal"===f.type){if(o=n.done?d:y,f.arg===m)continue;return{value:f.arg,done:n.done}}"throw"===f.type&&(o=d,n.method="throw",n.arg=f.arg)}}}function _(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,_(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),m;var i=h(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,m;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,m):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,m)}function k(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function A(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function T(r){if(r||""===r){var e=r[c];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function e(){for(;++n<r.length;)if(o.call(r,n))return e.value=r[n],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return w.prototype=b,i(j,"constructor",{value:b,configurable:!0}),i(b,"constructor",{value:w,configurable:!0}),w.displayName=l(b,f,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===w||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,l(t,f,"GeneratorFunction")),t.prototype=Object.create(j),t},r.awrap=function(t){return{__await:t}},G(S.prototype),l(S.prototype,u,(function(){return this})),r.AsyncIterator=S,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new S(s(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},G(j),l(j,f,"Generator"),l(j,c,(function(){return this})),l(j,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=T,P.prototype={constructor:P,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(A),!r)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function n(n,o){return c.type="throw",c.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=o.call(a,"catchLoc"),f=o.call(a,"finallyLoc");if(u&&f){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!f)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,m):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),m},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),A(e),m}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;A(e)}return o}}throw Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:T(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),m}},r}function o(r){return function(r){if(Array.isArray(r))return t(r)}(r)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(r)||function(r,e){if(r){if("string"==typeof r)return t(r,e);var n={}.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(r,e):void 0}}(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t){var r=function(t,r){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t,"string");return"symbol"==typeof r?r:r+""}function a(t){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},a(t)}var c={1:"develop",2:"test",3:"production",4:"beta"},u=function(){return e((function t(){var e=this;!function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,t);var o,i,u={env:3,version:3},f=arguments[0];if(arguments.length>1&&(u="object"==a(arguments[0])?arguments[0]:u,f=arguments[1],null!==(o=u)&&void 0!==o&&o.env||(u.env=3),null!==(i=u)&&void 0!==i&&i.version||(u.version=3)),"undefined"!=typeof window){var l=function(){var t,o=(t=n().mark((function t(){var r,o,i,a;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,fetch("https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=map-api-js&env=".concat(c[u.env]));case 3:return r=t.sent,t.next=6,r.json();case 6:o=t.sent,i=Array.from(document.head.getElementsByTagName("script")).some((function(t){return t.src===o.apiUrl})),i?f&&"function"==typeof f&&(e.GLMap=new window.$GlMapApi(u,(function(){f&&"function"==typeof f&&f(e)}))):((a=document.createElement("script")).src=o.apiUrl,document.head.appendChild(a),a.onload=function(){e.GLMap=new window.$GlMapApi(u,(function(){f&&"function"==typeof f&&f(e)}))}),t.next=14;break;case 11:t.prev=11,t.t0=t.catch(0),console.error("Failed to fetch configuration:",t.t0);case 14:case"end":return t.stop()}}),t,null,[[0,11]])})),function(){var e=this,n=arguments;return new Promise((function(o,i){var a=t.apply(e,n);function c(t){r(a,o,i,c,u,"next",t)}function u(t){r(a,o,i,c,u,"throw",t)}c(void 0)}))});return function(){return o.apply(this,arguments)}}();l()}}),[{key:"invoke",value:function(t){var r,e=Array.prototype.slice.call(arguments,1);return(r=this.GLMap)[t].apply(r,o(e))}},{key:"map",get:function(){return this.GLMap._BMAP}},{key:"mapGL",get:function(){return this.GLMap._BMapGL}}])}();return u}));
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
</el-button> </el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<GLDialog :visible.sync="dialogMapVisible" :mode="'big'" bigTitle="选择地址"> <GLDialog v-if="dialogMapVisible" :visible.sync="dialogMapVisible" :mode="'big'" bigTitle="选择地址">
<map-view ref="mapForm" :mapHeight="mapHeight"></map-view> <map-view ref="mapForm" :mapHeight="mapHeight"></map-view>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button size="small" @click="dialogMapVisible = false">取 消</el-button> <el-button size="small" @click="dialogMapVisible = false">取 消</el-button>
...@@ -148,20 +148,26 @@ export default { ...@@ -148,20 +148,26 @@ export default {
**/ **/
// 获取省市信息 // 获取省市信息
provinceList() { provinceList() {
var params = {} var params = {
params.subdistrict = this.subdistrict keyword: '中国',
extensions_code: 1
}
params.sub_admin = this.subdistrict
// params.subdistrict = this.subdistrict
let data = '' let data = ''
for (let key in params) { for (let key in params) {
data += '&' + key + '=' + params[key] data += '&' + key + '=' + params[key]
} }
let path = `https://restapi.amap.com/v3/config/district?key=d22348363c34c266f772ae9b635eef2a` // let path = `https://restapi.amap.com/v3/config/district?key=d22348363c34c266f772ae9b635eef2a`
path = path + data // path = path + data
const path = this.$provinceUrl + data
const pro = fetch(path).then(res => { const pro = fetch(path).then(res => {
return res.json() return res.json()
}) })
if (this.provinceView) { if (this.provinceView) {
pro.then(r => { pro.then(r => {
this.AllData = r.districts[0].districts // this.AllData = r.districts[0].districts
this.AllData = JSON.parse(r.data).districts[0].districts
}) })
} }
return pro return pro
...@@ -245,18 +251,17 @@ export default { ...@@ -245,18 +251,17 @@ export default {
getLoc(addr) { getLoc(addr) {
let _this = this let _this = this
//加载地理编码插件 //加载地理编码插件
AMap.plugin(['AMap.Geocoder'], function () { const mapapi = this.$mapapi
map = new AMap.Geocoder({}) console.log(mapapi, 'mapapi---')
// 返回地理编码结果 let geocoder = mapapi.invoke('Geocoder')
map.getLocation(addr, function (status, result) { geocoder.getLocation('getPoint', addr, res => {
if (status === 'complete' && result.info === 'OK') { console.log(res)
// result中对应详细地理坐标信息 // this.address = res.surroundingPois.length ? res.surroundingPois[0].address : res.address
_this.provinceForm.lat = result.geocodes[0].location.lat // this.geocoderAddress = res.content.address_detail
_this.provinceForm.lng = result.geocodes[0].location.lng _this.provinceForm.lat = res.geocodes[0].location.lat
_this.provinceForm.provinceCode = result.geocodes[0].adcode.slice(0, 2) + '0000' _this.provinceForm.lng = res.geocodes[0].location.lng
_this.provinceForm.cityCode = result.geocodes[0].adcode _this.provinceForm.provinceCode = res.geocodes[0].adcode.slice(0, 2) + '0000'
} _this.provinceForm.cityCode = res.geocodes[0].adcode
})
}) })
}, },
...@@ -273,8 +278,9 @@ export default { ...@@ -273,8 +278,9 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
if (this.provinceForm.fullAddress && !this.$refs.mapForm.address) { if (this.provinceForm.fullAddress && !this.$refs.mapForm.address) {
this.$refs.mapForm.address = this.provinceForm.fullAddress this.$refs.mapForm.address = this.provinceForm.fullAddress
this.$refs.mapForm.addMarker([this.provinceForm.lng, this.provinceForm.lat]) // this.$refs.mapForm.addMarker([this.provinceForm.lng, this.provinceForm.lat])
} }
this.$refs.mapForm.mapInit(this.provinceForm.lng, this.provinceForm.lat)
}) })
}, },
......
<template> <template>
<div class="map-box" :style="{ height: mapHeight + 'px' }"> <div class="map-box" :style="{ height: mapHeight + 'px' }">
<div id="container" style="width: 100%; height: 100%"></div> <div id="mapContainer" style="width: 100%; height: 100%"></div>
<div class="map-address">{{ address }}</div> <div class="map-address">{{ address }}</div>
<div id="myPageTop" style="position: absolute; top: 10px; width: 50%; left: 25%"> <div id="myPageTop" style="position: absolute; top: 10px; width: 50%; left: 25%">
<el-input placeholder="请输入关键字" v-model="input" class="input-with-select"> <el-input placeholder="请输入关键字" v-model="input" @keyup.enter.native="searchAddress" class="input-with-select">
<el-button slot="append" icon="el-icon-search" @click="searchAddress"></el-button> <el-button slot="append" icon="el-icon-search" @click="searchAddress"></el-button>
</el-input> </el-input>
</div> </div>
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
</template> </template>
<script> <script>
let map, marker, placeSearch let map, marker, geocoder
export default { export default {
name: 'map', name: 'map',
props: { props: {
...@@ -25,84 +25,70 @@ export default { ...@@ -25,84 +25,70 @@ export default {
return { return {
input: '', input: '',
address: '', address: '',
lnglat: [], lnglat: {},
geocoderAddress: {} geocoderAddress: {},
mapapi: null
} }
}, },
methods: { methods: {
mapInit() { async mapInit(lng, lat) {
map = new AMap.Map('container', { console.log(lng, lat, '==========', this.$mapapi)
resizeEnable: true, const mapapi = this.$mapapi
zoom: 20 map = await mapapi.invoke('Map', 'mapContainer')
}) mapapi.invoke('centerAndZoom', mapapi.invoke('Point', lng || 116.4033, lat || 39.9258), 15)
AMap.plugin(['AMap.PlaceSearch'], function() { map.enableScrollWheelZoom() // 启用滚轮放大缩小
//构造地点查询类 map.enableAutoResize() // 启用自动适应容器尺寸变化
placeSearch = new AMap.PlaceSearch({ geocoder = mapapi.invoke('Geocoder')
pageSize: 8, // 单页显示结果条数 if (lng && lat) {
pageIndex: 1, // 页码 this.addMarker({lng, lat}, true)
citylimit: false, //是否强制限制在设置的城市内搜索 }
// panel: "panel", // 结果列表将在此容器中进行展示。 // 右键菜单
autoFitView: true, // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围 mapapi.invoke('mapAddEventListener', 'click', (e) => {
renderStyle: 'default' this.getAddress(e.point)
})
}) })
// 添加列表点选监听事件
map.on('click', this.getAddress)
}, },
searchAddress() { searchAddress() {
let _this = this const mapapi = this.$mapapi
placeSearch.search(this.input, function(status, result) { mapapi.invoke('getPoint', this.input, res => {
if (status === 'complete' && result.poiList.pois.length) { // this.addMarker(res)
let lnglat = result.poiList.pois[0].location this.getAddress(res)
_this.getAddress(lnglat) }, '全国')
}
})
}, },
addMarker(lnglat) { addMarker(lnglat) {
let position const mapapi = this.$mapapi
let lnglatXY
this.lnglat = lnglat
if (lnglat.lng) { if (lnglat.lng) {
position = [lnglat.lng, lnglat.lat] const { lng, lat } = lnglat
lnglatXY = mapapi.invoke('Point', lng, lat)
} else { } else {
position = lnglat lnglatXY = mapapi.invoke('Point', lnglat[0], lnglat[1])
}
if (marker) {
mapapi.invoke('removeOverlay', marker)
} }
marker = new AMap.Marker({ marker = mapapi.invoke('Marker', lnglatXY, {
icon: new AMap.Icon({ icon:mapapi.invoke('Icon', require('@/assets/address.png'), mapapi.invoke('Size', 26, 36))
image: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
size: new AMap.Size(27, 34), //图标大小
imageSize: new AMap.Size(27, 34)
}),
position: position,
offset: new AMap.Pixel(-10, -10)
}) })
map.add(marker) mapapi.invoke('panTo', lnglatXY)
map.setFitView() mapapi.invoke('addOverlay', marker)
}, },
getAddress(e) { getAddress(e) {
let self = this let self = this
const mapapi = this.$mapapi
this.lnglat = e
let lnglat let lnglat
if (e.type == 'click') { if (e.lng) {
lnglat = e.lnglat const { lng, lat } = e
lnglat = mapapi.invoke('Point', lng, lat)
} else { } else {
let { lng, lat } = e lnglat = mapapi.invoke('Point', e[0], e[1])
lnglat = [lng, lat]
}
if (marker) {
marker.setMap(null)
marker = null
} }
self.addMarker(lnglat) self.addMarker(lnglat)
AMap.plugin('AMap.Geocoder', () => { geocoder.getLocation(lnglat, res => {
const geocoder = new AMap.Geocoder() this.address = res.surroundingPois.length ? res.surroundingPois[0].address : res.address
geocoder.getAddress(lnglat, (status, result) => { this.geocoderAddress = res.content.address_detail
self.lnglat = lnglat
self.address = result.regeocode.formattedAddress
geocoder.getLocation(self.address, (status, result) => {
if (status === 'complete' && result.info === 'OK') {
this.geocoderAddress = result.geocodes[0]
}
})
})
}) })
}, },
selectAddress(e) { selectAddress(e) {
...@@ -112,7 +98,7 @@ export default { ...@@ -112,7 +98,7 @@ export default {
}, },
mounted() { mounted() {
this.mapInit() // this.mapInit()
} }
} }
</script> </script>
...@@ -135,8 +121,8 @@ export default { ...@@ -135,8 +121,8 @@ export default {
width: 280px; width: 280px;
} }
.map-address { .map-address {
position: absolute; // position: absolute;
line-height: 20px; line-height: 20px;
bottom: -30px; // bottom: -30px;
} }
</style> </style>
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
</el-button> </el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<GLDialog :visible.sync="dialogMapVisible" :mode="'big'" bigTitle="选择地址"> <GLDialog v-if="dialogMapVisible" :visible.sync="dialogMapVisible" :mode="'big'" bigTitle="选择地址">
<map-view ref="mapForm" :mapHeight="mapHeight"></map-view> <map-view ref="mapForm" :mapHeight="mapHeight"></map-view>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button size="small" @click="dialogMapVisible = false">取 消</el-button> <el-button size="small" @click="dialogMapVisible = false">取 消</el-button>
...@@ -148,20 +148,26 @@ export default { ...@@ -148,20 +148,26 @@ export default {
**/ **/
// 获取省市信息 // 获取省市信息
provinceList() { provinceList() {
var params = {} var params = {
params.subdistrict = this.subdistrict keyword: '中国',
extensions_code: 1
}
params.sub_admin = this.subdistrict
// params.subdistrict = this.subdistrict
let data = '' let data = ''
for (let key in params) { for (let key in params) {
data += '&' + key + '=' + params[key] data += '&' + key + '=' + params[key]
} }
let path = `https://restapi.amap.com/v3/config/district?key=d22348363c34c266f772ae9b635eef2a` // let path = `https://restapi.amap.com/v3/config/district?key=d22348363c34c266f772ae9b635eef2a`
path = path + data // path = path + data
const path = this.$provinceUrl + data
const pro = fetch(path).then(res => { const pro = fetch(path).then(res => {
return res.json() return res.json()
}) })
if (this.provinceView) { if (this.provinceView) {
pro.then(r => { pro.then(r => {
this.AllData = r.districts[0].districts // this.AllData = r.districts[0].districts
this.AllData = JSON.parse(r.data).districts[0].districts
}) })
} }
return pro return pro
...@@ -245,19 +251,32 @@ export default { ...@@ -245,19 +251,32 @@ export default {
getLoc(addr) { getLoc(addr) {
let _this = this let _this = this
//加载地理编码插件 //加载地理编码插件
AMap.plugin(['AMap.Geocoder'], function () { const mapapi = this.$mapapi
map = new AMap.Geocoder({}) console.log(mapapi, 'mapapi---')
// 返回地理编码结果 let geocoder = mapapi.invoke('Geocoder')
map.getLocation(addr, function (status, result) { geocoder.getLocation('getPoint', addr, res => {
if (status === 'complete' && result.info === 'OK') { console.log(res)
// result中对应详细地理坐标信息 // this.address = res.surroundingPois.length ? res.surroundingPois[0].address : res.address
_this.provinceForm.lat = result.geocodes[0].location.lat // this.geocoderAddress = res.content.address_detail
_this.provinceForm.lng = result.geocodes[0].location.lng _this.provinceForm.lat = res.geocodes[0].location.lat
_this.provinceForm.provinceCode = result.geocodes[0].adcode.slice(0, 2) + '0000' _this.provinceForm.lng = res.geocodes[0].location.lng
_this.provinceForm.cityCode = result.geocodes[0].adcode _this.provinceForm.provinceCode = res.geocodes[0].adcode.slice(0, 2) + '0000'
} _this.provinceForm.cityCode = res.geocodes[0].adcode
})
}) })
//加载地理编码插件
// AMap.plugin(['AMap.Geocoder'], function () {
// map = new AMap.Geocoder({})
// // 返回地理编码结果
// map.getLocation(addr, function (status, result) {
// if (status === 'complete' && result.info === 'OK') {
// // result中对应详细地理坐标信息
// _this.provinceForm.lat = result.geocodes[0].location.lat
// _this.provinceForm.lng = result.geocodes[0].location.lng
// _this.provinceForm.provinceCode = result.geocodes[0].adcode.slice(0, 2) + '0000'
// _this.provinceForm.cityCode = result.geocodes[0].adcode
// }
// })
// })
}, },
handleInputAddr() { handleInputAddr() {
...@@ -273,8 +292,9 @@ export default { ...@@ -273,8 +292,9 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
if (this.provinceForm.fullAddress && !this.$refs.mapForm.address) { if (this.provinceForm.fullAddress && !this.$refs.mapForm.address) {
this.$refs.mapForm.address = this.provinceForm.fullAddress this.$refs.mapForm.address = this.provinceForm.fullAddress
this.$refs.mapForm.addMarker([this.provinceForm.lng, this.provinceForm.lat]) // this.$refs.mapForm.addMarker([this.provinceForm.lng, this.provinceForm.lat])
} }
this.$refs.mapForm.mapInit(this.provinceForm.lng, this.provinceForm.lat)
}) })
}, },
......
<template> <template>
<div class="map-box" :style="{ height: mapHeight + 'px' }"> <div class="map-box" :style="{ height: mapHeight + 'px' }">
<div id="container" style="width: 100%; height: 100%"></div> <div id="mapContainer" style="width: 100%; height: 100%"></div>
<div class="map-address">{{ address }}</div> <div class="map-address">{{ address }}</div>
<div id="myPageTop" style="position: absolute; top: 10px; width: 50%; left: 25%"> <div id="myPageTop" style="position: absolute; top: 10px; width: 50%; left: 25%">
<el-input placeholder="请输入关键字" v-model="input" class="input-with-select"> <el-input placeholder="请输入关键字" v-model="input" @keyup.enter.native="searchAddress" class="input-with-select">
<el-button slot="append" icon="el-icon-search" @click="searchAddress"></el-button> <el-button slot="append" icon="el-icon-search" @click="searchAddress"></el-button>
</el-input> </el-input>
</div> </div>
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
</template> </template>
<script> <script>
let map, marker, placeSearch let map, marker, geocoder
export default { export default {
name: 'map', name: 'map',
props: { props: {
...@@ -25,84 +25,70 @@ export default { ...@@ -25,84 +25,70 @@ export default {
return { return {
input: '', input: '',
address: '', address: '',
lnglat: [], lnglat: {},
geocoderAddress: {} geocoderAddress: {},
mapapi: null
} }
}, },
methods: { methods: {
mapInit() { async mapInit(lng, lat) {
map = new AMap.Map('container', { console.log(lng, lat, '==========', this.$mapapi)
resizeEnable: true, const mapapi = this.$mapapi
zoom: 20 map = await mapapi.invoke('Map', 'mapContainer')
}) mapapi.invoke('centerAndZoom', mapapi.invoke('Point', lng || 116.4033, lat || 39.9258), 15)
AMap.plugin(['AMap.PlaceSearch'], function() { map.enableScrollWheelZoom() // 启用滚轮放大缩小
//构造地点查询类 map.enableAutoResize() // 启用自动适应容器尺寸变化
placeSearch = new AMap.PlaceSearch({ geocoder = mapapi.invoke('Geocoder')
pageSize: 8, // 单页显示结果条数 if (lng && lat) {
pageIndex: 1, // 页码 this.addMarker({lng, lat}, true)
citylimit: false, //是否强制限制在设置的城市内搜索 }
// panel: "panel", // 结果列表将在此容器中进行展示。 // 右键菜单
autoFitView: true, // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围 mapapi.invoke('mapAddEventListener', 'click', (e) => {
renderStyle: 'default' this.getAddress(e.point)
})
}) })
// 添加列表点选监听事件
map.on('click', this.getAddress)
}, },
searchAddress() { searchAddress() {
let _this = this const mapapi = this.$mapapi
placeSearch.search(this.input, function(status, result) { mapapi.invoke('getPoint', this.input, res => {
if (status === 'complete' && result.poiList.pois.length) { // this.addMarker(res)
let lnglat = result.poiList.pois[0].location this.getAddress(res)
_this.getAddress(lnglat) }, '全国')
}
})
}, },
addMarker(lnglat) { addMarker(lnglat) {
let position const mapapi = this.$mapapi
let lnglatXY
this.lnglat = lnglat
if (lnglat.lng) { if (lnglat.lng) {
position = [lnglat.lng, lnglat.lat] const { lng, lat } = lnglat
lnglatXY = mapapi.invoke('Point', lng, lat)
} else { } else {
position = lnglat lnglatXY = mapapi.invoke('Point', lnglat[0], lnglat[1])
}
if (marker) {
mapapi.invoke('removeOverlay', marker)
} }
marker = new AMap.Marker({ marker = mapapi.invoke('Marker', lnglatXY, {
icon: new AMap.Icon({ icon:mapapi.invoke('Icon', require('@/assets/address.png'), mapapi.invoke('Size', 26, 36))
image: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
size: new AMap.Size(27, 34), //图标大小
imageSize: new AMap.Size(27, 34)
}),
position: position,
offset: new AMap.Pixel(-10, -10)
}) })
map.add(marker) mapapi.invoke('panTo', lnglatXY)
map.setFitView() mapapi.invoke('addOverlay', marker)
}, },
getAddress(e) { getAddress(e) {
let self = this let self = this
const mapapi = this.$mapapi
this.lnglat = e
let lnglat let lnglat
if (e.type == 'click') { if (e.lng) {
lnglat = e.lnglat const { lng, lat } = e
lnglat = mapapi.invoke('Point', lng, lat)
} else { } else {
let { lng, lat } = e lnglat = mapapi.invoke('Point', e[0], e[1])
lnglat = [lng, lat]
}
if (marker) {
marker.setMap(null)
marker = null
} }
self.addMarker(lnglat) self.addMarker(lnglat)
AMap.plugin('AMap.Geocoder', () => { geocoder.getLocation(lnglat, res => {
const geocoder = new AMap.Geocoder() this.address = res.surroundingPois.length ? res.surroundingPois[0].address : res.address
geocoder.getAddress(lnglat, (status, result) => { this.geocoderAddress = res.content.address_detail
self.lnglat = lnglat
self.address = result.regeocode.formattedAddress
geocoder.getLocation(self.address, (status, result) => {
if (status === 'complete' && result.info === 'OK') {
this.geocoderAddress = result.geocodes[0]
}
})
})
}) })
}, },
selectAddress(e) { selectAddress(e) {
...@@ -112,7 +98,7 @@ export default { ...@@ -112,7 +98,7 @@ export default {
}, },
mounted() { mounted() {
this.mapInit() // this.mapInit()
} }
} }
</script> </script>
...@@ -135,8 +121,8 @@ export default { ...@@ -135,8 +121,8 @@ export default {
width: 280px; width: 280px;
} }
.map-address { .map-address {
position: absolute; // position: absolute;
line-height: 20px; line-height: 20px;
bottom: -30px; // bottom: -30px;
} }
</style> </style>
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
</el-button> </el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<GLDialog :visible.sync="dialogMapVisible" <GLDialog v-if="dialogMapVisible" :visible.sync="dialogMapVisible"
:mode="'big'" :mode="'big'"
bigTitle="选择地址"> bigTitle="选择地址">
<map-view ref="mapForm" <map-view ref="mapForm"
...@@ -300,21 +300,33 @@ export default { ...@@ -300,21 +300,33 @@ export default {
getLoc(addr) { getLoc(addr) {
let _this = this let _this = this
//加载地理编码插件 //加载地理编码插件
AMap.plugin(['AMap.Geocoder'], function () { const mapapi = this.$mapapi
map = new AMap.Geocoder({}) console.log(mapapi, 'mapapi---')
// 返回地理编码结果 let geocoder = mapapi.invoke('Geocoder')
map.getLocation(addr, function (status, result) { geocoder.getLocation('getPoint', addr, res => {
console.log('addr', addr); console.log(res)
console.log('result', result); // this.address = res.surroundingPois.length ? res.surroundingPois[0].address : res.address
if (status === 'complete' && result.info === 'OK') { // this.geocoderAddress = res.content.address_detail
// result中对应详细地理坐标信息 _this.provinceForm.lat = res.geocodes[0].location.lat
_this.provinceForm.lat = result.geocodes[0].location.lat _this.provinceForm.lng = res.geocodes[0].location.lng
_this.provinceForm.lng = result.geocodes[0].location.lng _this.provinceForm.provinceCode = res.geocodes[0].adcode.slice(0, 2) + '0000'
_this.provinceForm.provinceCode = result.geocodes[0].adcode.slice(0, 2) + '0000' _this.provinceForm.cityCode = res.geocodes[0].adcode
_this.provinceForm.cityCode = result.geocodes[0].adcode
}
})
}) })
// AMap.plugin(['AMap.Geocoder'], function () {
// map = new AMap.Geocoder({})
// // 返回地理编码结果
// map.getLocation(addr, function (status, result) {
// console.log('addr', addr);
// console.log('result', result);
// if (status === 'complete' && result.info === 'OK') {
// // result中对应详细地理坐标信息
// _this.provinceForm.lat = result.geocodes[0].location.lat
// _this.provinceForm.lng = result.geocodes[0].location.lng
// _this.provinceForm.provinceCode = result.geocodes[0].adcode.slice(0, 2) + '0000'
// _this.provinceForm.cityCode = result.geocodes[0].adcode
// }
// })
// })
}, },
handleInputAddr() { handleInputAddr() {
...@@ -330,8 +342,9 @@ export default { ...@@ -330,8 +342,9 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
if (this.provinceForm.fullAddress && !this.$refs.mapForm.address) { if (this.provinceForm.fullAddress && !this.$refs.mapForm.address) {
this.$refs.mapForm.address = this.provinceForm.fullAddress this.$refs.mapForm.address = this.provinceForm.fullAddress
this.$refs.mapForm.addMarker([this.provinceForm.lng, this.provinceForm.lat]) // this.$refs.mapForm.addMarker([this.provinceForm.lng, this.provinceForm.lat])
} }
this.$refs.mapForm.mapInit(this.provinceForm.lng, this.provinceForm.lat)
}) })
}, },
...@@ -344,38 +357,39 @@ export default { ...@@ -344,38 +357,39 @@ export default {
this.provinceForm.fullAddress = this.$refs.mapForm.address this.provinceForm.fullAddress = this.$refs.mapForm.address
// 获取选择经纬度 // 获取选择经纬度
let lnglat = this.$refs.mapForm.lnglat let lnglat = this.$refs.mapForm.lnglat
this.provinceForm.lat = lnglat.lat console.log(lnglat, 'lngat')
this.provinceForm.lng = lnglat.lng this.provinceForm.lat = +(lnglat.lat.toFixed(4))
this.provinceForm.lng = +(lnglat.lng.toFixed(4))
var mapData = this.$refs.mapForm.geocoderAddress var mapData = this.$refs.mapForm.geocoderAddress
// 赋值省市区名称和code // 赋值省市区名称和code
const { city, citycode, province, district, towncode } = mapData.addressComponent const { city, citycode, province, district, towncode } = mapData
if (!this.provinceForm.provinceName) { console.log(this.provinceForm, 'this.provinceForm---')
this.provinceForm.provinceName = province console.log(mapData, 'mapData')
this.provinceForm.cityName = city this.provinceForm.provinceName = province
this.provinceForm.townName = district this.provinceForm.cityName = city
this.provinceForm.provinceCode = mapData.adcode this.provinceForm.townName = district
this.provinceForm.cityCode = citycode this.provinceForm.provinceCode = Number((mapData.adcode + '').slice(0, 2) + '0000')
this.provinceForm.townCode = towncode this.provinceForm.cityCode = mapData.adcode
} this.provinceForm.townCode = towncode
var fullAddress = '' var fullAddress = ''
var provincecode = '' var provincecode = ''
// 为防止打开地图弹框不选择地址点确定按钮无法正确判断地址选择是否正确产生的报错,设置this.addressData.fullAddress来保存上次选择的地址 // 为防止打开地图弹框不选择地址点确定按钮无法正确判断地址选择是否正确产生的报错,设置this.addressData.fullAddress来保存上次选择的地址
if (mapData.addressComponent) { // if (mapData.addressComponent) {
fullAddress = mapData.addressComponent // fullAddress = mapData.addressComponent
provincecode = mapData.adcode // provincecode = mapData.adcode
this.addressData.fullAddress = fullAddress // this.addressData.fullAddress = fullAddress
this.addressData.provincecode = provincecode // this.addressData.provincecode = provincecode
} else { // } else {
fullAddress = this.addressData.fullAddress // fullAddress = this.addressData.fullAddress
provincecode = this.addressData.provincecode // provincecode = this.addressData.provincecode
} // }
// 获取省市 // 获取省市
var provincename = '' var provincename = ''
var cityname = '' var cityname = ''
var town = '' var town = ''
provincename = fullAddress.province provincename = mapData.province
cityname = fullAddress.city ? fullAddress.city : fullAddress.district cityname = mapData.city ? mapData.city : mapData.district
town = fullAddress.district town = mapData.district
// 直辖市需额外判断 // 直辖市需额外判断
const municipalities = ['北京市', '天津市', '上海市', '重庆市'] const municipalities = ['北京市', '天津市', '上海市', '重庆市']
var municipality = municipalities.find(item => item == provincename) var municipality = municipalities.find(item => item == provincename)
...@@ -385,8 +399,8 @@ export default { ...@@ -385,8 +399,8 @@ export default {
provincecode = provincecode.slice(0, 4) provincecode = provincecode.slice(0, 4)
provincecode == 5001 ? (cityname = cityname.slice(0, 2) + '城区') : (cityname = cityname.slice(0, 2) + '郊县') provincecode == 5001 ? (cityname = cityname.slice(0, 2) + '城区') : (cityname = cityname.slice(0, 2) + '郊县')
// 重新赋值城市名 // 重新赋值城市名
this.provinceForm.cityName = cityname
} }
this.provinceForm.cityName = cityname
} }
// 判断省市是否匹配 // 判断省市是否匹配
// 如果只展示省市 // 如果只展示省市
...@@ -405,6 +419,7 @@ export default { ...@@ -405,6 +419,7 @@ export default {
return return
} }
} }
this.provinceForm.fullAddress = this.$refs.mapForm.address
this.dialogMapVisible = false this.dialogMapVisible = false
// this.subdistrict == 2 ? this.init(province, city) : this.init(province, city, town) // this.subdistrict == 2 ? this.init(province, city) : this.init(province, city, town)
// 通过地图选择省市区 // 通过地图选择省市区
......
<template> <template>
<div class="map-box" <div class="map-box" :style="{ height: mapHeight + 'px' }">
:style="{ height: mapHeight + 'px' }"> <div id="mapContainer" style="width: 100%; height: 100%"></div>
<div id="container"
style="width: 100%; height: 100%"></div>
<div class="map-address">{{ address }}</div> <div class="map-address">{{ address }}</div>
<div id="myPageTop" <div id="myPageTop" style="position: absolute; top: 10px; width: 50%; left: 25%">
style="position: absolute; top: 10px; width: 50%; left: 25%"> <el-input placeholder="请输入关键字" v-model="input" @keyup.enter.native="searchAddress" class="input-with-select">
<el-input placeholder="请输入关键字" <el-button slot="append" icon="el-icon-search" @click="searchAddress"></el-button>
v-model="input"
class="input-with-select">
<el-button slot="append"
icon="el-icon-search"
@click="searchAddress"></el-button>
</el-input> </el-input>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
let map, marker, placeSearch let map, marker, geocoder
export default { export default {
name: 'map', name: 'map',
props: { props: {
...@@ -32,84 +25,70 @@ export default { ...@@ -32,84 +25,70 @@ export default {
return { return {
input: '', input: '',
address: '', address: '',
lnglat: [], lnglat: {},
geocoderAddress: {} geocoderAddress: {},
mapapi: null
} }
}, },
methods: { methods: {
mapInit() { async mapInit(lng, lat) {
map = new AMap.Map('container', { console.log(lng, lat, '==========', this.$mapapi)
resizeEnable: true, const mapapi = this.$mapapi
zoom: 20 map = await mapapi.invoke('Map', 'mapContainer')
}) mapapi.invoke('centerAndZoom', mapapi.invoke('Point', lng || 116.4033, lat || 39.9258), 15)
AMap.plugin(['AMap.PlaceSearch'], function () { map.enableScrollWheelZoom() // 启用滚轮放大缩小
//构造地点查询类 map.enableAutoResize() // 启用自动适应容器尺寸变化
placeSearch = new AMap.PlaceSearch({ geocoder = mapapi.invoke('Geocoder')
pageSize: 8, // 单页显示结果条数 if (lng && lat) {
pageIndex: 1, // 页码 this.addMarker({lng, lat}, true)
citylimit: false, //是否强制限制在设置的城市内搜索 }
// panel: "panel", // 结果列表将在此容器中进行展示。 // 右键菜单
autoFitView: true, // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围 mapapi.invoke('mapAddEventListener', 'click', (e) => {
renderStyle: 'default' this.getAddress(e.point)
})
}) })
// 添加列表点选监听事件
map.on('click', this.getAddress)
}, },
searchAddress() { searchAddress() {
let _this = this const mapapi = this.$mapapi
placeSearch.search(this.input, function (status, result) { mapapi.invoke('getPoint', this.input, res => {
if (status === 'complete' && result.poiList.pois.length) { // this.addMarker(res)
let lnglat = result.poiList.pois[0].location this.getAddress(res)
_this.getAddress(lnglat) }, '全国')
}
})
}, },
addMarker(lnglat) { addMarker(lnglat) {
let position const mapapi = this.$mapapi
let lnglatXY
this.lnglat = lnglat
if (lnglat.lng) { if (lnglat.lng) {
position = [lnglat.lng, lnglat.lat] const { lng, lat } = lnglat
lnglatXY = mapapi.invoke('Point', lng, lat)
} else { } else {
position = lnglat lnglatXY = mapapi.invoke('Point', lnglat[0], lnglat[1])
}
if (marker) {
mapapi.invoke('removeOverlay', marker)
} }
marker = new AMap.Marker({ marker = mapapi.invoke('Marker', lnglatXY, {
icon: new AMap.Icon({ icon:mapapi.invoke('Icon', require('@/assets/address.png'), mapapi.invoke('Size', 26, 36))
image: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
size: new AMap.Size(27, 34), //图标大小
imageSize: new AMap.Size(27, 34)
}),
position: position,
offset: new AMap.Pixel(-10, -10)
}) })
map.add(marker) mapapi.invoke('panTo', lnglatXY)
map.setFitView() mapapi.invoke('addOverlay', marker)
}, },
getAddress(e) { getAddress(e) {
let self = this let self = this
const mapapi = this.$mapapi
this.lnglat = e
let lnglat let lnglat
if (e.type == 'click') { if (e.lng) {
lnglat = e.lnglat const { lng, lat } = e
lnglat = mapapi.invoke('Point', lng, lat)
} else { } else {
let { lng, lat } = e lnglat = mapapi.invoke('Point', e[0], e[1])
lnglat = [lng, lat]
}
if (marker) {
marker.setMap(null)
marker = null
} }
self.addMarker(lnglat) self.addMarker(lnglat)
AMap.plugin('AMap.Geocoder', () => { geocoder.getLocation(lnglat, res => {
const geocoder = new AMap.Geocoder() this.address = res.surroundingPois.length ? res.surroundingPois[0].address : res.address
geocoder.getAddress(lnglat, (status, result) => { this.geocoderAddress = res.content.address_detail
self.lnglat = lnglat
self.address = result.regeocode.formattedAddress
geocoder.getLocation(self.address, (status, result) => {
if (status === 'complete' && result.info === 'OK') {
this.geocoderAddress = result.geocodes[0]
}
})
})
}) })
}, },
selectAddress(e) { selectAddress(e) {
...@@ -119,7 +98,7 @@ export default { ...@@ -119,7 +98,7 @@ export default {
}, },
mounted() { mounted() {
this.mapInit() // this.mapInit()
} }
} }
</script> </script>
...@@ -142,8 +121,8 @@ export default { ...@@ -142,8 +121,8 @@ export default {
width: 280px; width: 280px;
} }
.map-address { .map-address {
position: absolute; // position: absolute;
line-height: 20px; line-height: 20px;
bottom: -30px; // bottom: -30px;
} }
</style> </style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!