|
@@ -126,6 +126,7 @@
|
|
TextToCode
|
|
TextToCode
|
|
} from 'element-china-area-data'
|
|
} from 'element-china-area-data'
|
|
import image from '../../../public/img/ic_locationmarker.jpg'
|
|
import image from '../../../public/img/ic_locationmarker.jpg'
|
|
|
|
+ import AMapLoader from '@amap/amap-jsapi-loader';
|
|
export default {
|
|
export default {
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
@@ -168,17 +169,26 @@
|
|
}
|
|
}
|
|
},
|
|
},
|
|
async created() {
|
|
async created() {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+ mounted() {
|
|
// AMapLoader.reset();
|
|
// AMapLoader.reset();
|
|
// 已载入高德地图API,则直接初始化地图
|
|
// 已载入高德地图API,则直接初始化地图
|
|
if (window.AMap && window.AMapUI) {
|
|
if (window.AMap && window.AMapUI) {
|
|
// 未载入高德地图API,则先载入API再初始化
|
|
// 未载入高德地图API,则先载入API再初始化
|
|
} else {
|
|
} else {
|
|
- await remoteLoad(`http://webapi.amap.com/maps?v=1.3&key=${MapKey}&plugin=AMap.AutoComplete`)
|
|
|
|
- await remoteLoad('http://webapi.amap.com/ui/1.0/main.js')
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- mounted() {
|
|
|
|
- // console.log(this)
|
|
|
|
|
|
+ // await remoteLoad(`http://webapi.amap.com/maps?v=1.3&key=${MapKey}&plugin=AMap.AutoComplete`)
|
|
|
|
+ // await remoteLoad('http://webapi.amap.com/ui/1.0/main.js')
|
|
|
|
+ // AMapLoader.reset();
|
|
|
|
+ AMapLoader.load({
|
|
|
|
+ "key": "211dd6f989e719022aaf47ddb0659c47", // 申请好的Web端开发者Key,首次调用 load 时必填
|
|
|
|
+ "version": "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
|
|
|
|
+ "plugins": ['plugin=AMap.Scale', 'AMap.ToolBar','AMap.AutoComplete', 'AMap.PlaceSearch', 'AMap.Geocoder', 'AMap.DistrictSearch'],
|
|
|
|
+ "Loca": { // 是否加载 Loca, 缺省不加载
|
|
|
|
+ "version": '2.0.0' // Loca 版本,缺省 1.3.2
|
|
|
|
+ },
|
|
|
|
+ }).then((AMap) => {
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
var that = this
|
|
var that = this
|
|
this.map = new AMap.Map('mapContainer', {
|
|
this.map = new AMap.Map('mapContainer', {
|
|
@@ -208,19 +218,11 @@
|
|
map: that.map,
|
|
map: that.map,
|
|
})
|
|
})
|
|
AMap.plugin(
|
|
AMap.plugin(
|
|
- ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Geocoder', 'AMap.DistrictSearch'],
|
|
|
|
|
|
+ ['AMap.AutoComplete', 'AMap.PlaceSearch', 'AMap.Geocoder', 'AMap.DistrictSearch'],
|
|
function() {
|
|
function() {
|
|
- var autocomplete
|
|
|
|
- if(AMap.Autocomplete){
|
|
|
|
- autocomplete = new AMap.Autocomplete({
|
|
|
|
|
|
+ var autocomplete = new AMap.AutoComplete({
|
|
input: 'searchValue',
|
|
input: 'searchValue',
|
|
})
|
|
})
|
|
- }else{
|
|
|
|
- autocomplete = new AMap.AutoComplete({
|
|
|
|
- input: 'searchValue',
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
var placeSearch = new AMap.PlaceSearch({
|
|
var placeSearch = new AMap.PlaceSearch({
|
|
city: that.acode,
|
|
city: that.acode,
|
|
citylimit: true,
|
|
citylimit: true,
|
|
@@ -233,8 +235,7 @@
|
|
level: 'city',
|
|
level: 'city',
|
|
showbiz: false,
|
|
showbiz: false,
|
|
});
|
|
});
|
|
- console.log(autocomplete)
|
|
|
|
- AMap.event.addListener(autocomplete, 'select', function(e) {
|
|
|
|
|
|
+ autocomplete.on( 'select', function(e) {
|
|
that.marker.setMap(that.map)
|
|
that.marker.setMap(that.map)
|
|
if (e.poi.location) {
|
|
if (e.poi.location) {
|
|
placeSearch.search() // 关键字查询查询
|
|
placeSearch.search() // 关键字查询查询
|
|
@@ -291,10 +292,9 @@
|
|
that.map.on('moveend', function(e) {
|
|
that.map.on('moveend', function(e) {
|
|
//地图变动之后需要重新赋值省市区,未完成
|
|
//地图变动之后需要重新赋值省市区,未完成
|
|
that.center = that.map.getCenter(); //获取当前地图中心位置
|
|
that.center = that.map.getCenter(); //获取当前地图中心位置
|
|
|
|
+ console.log(that.center)
|
|
that.center.lat = Number(that.center.lat.toFixed(3))
|
|
that.center.lat = Number(that.center.lat.toFixed(3))
|
|
that.center.lng = Number(that.center.lng.toFixed(3))
|
|
that.center.lng = Number(that.center.lng.toFixed(3))
|
|
- that.center.Q = Number(that.center.Q.toFixed(3))
|
|
|
|
- that.center.R = Number(that.center.R.toFixed(3))
|
|
|
|
for (var i = 0, l = that.polygons.length; i < l; i++) {
|
|
for (var i = 0, l = that.polygons.length; i < l; i++) {
|
|
that.polygons[i].setMap(null)
|
|
that.polygons[i].setMap(null)
|
|
}
|
|
}
|
|
@@ -321,10 +321,9 @@
|
|
//地图变动之后需要重新赋值省市区,未完成
|
|
//地图变动之后需要重新赋值省市区,未完成
|
|
// this.zoom = map.getZoom(); //获取当前地图级别
|
|
// this.zoom = map.getZoom(); //获取当前地图级别
|
|
that.center = that.map.getCenter(); //获取当前地图中心位置
|
|
that.center = that.map.getCenter(); //获取当前地图中心位置
|
|
|
|
+ console.log(that.center)
|
|
that.center.lat = Number(that.center.lat.toFixed(3))
|
|
that.center.lat = Number(that.center.lat.toFixed(3))
|
|
that.center.lng = Number(that.center.lng.toFixed(3))
|
|
that.center.lng = Number(that.center.lng.toFixed(3))
|
|
- that.center.Q = Number(that.center.Q.toFixed(3))
|
|
|
|
- that.center.R = Number(that.center.R.toFixed(3))
|
|
|
|
for (var i = 0, l = that.polygons.length; i < l; i++) {
|
|
for (var i = 0, l = that.polygons.length; i < l; i++) {
|
|
that.polygons[i].setMap(null)
|
|
that.polygons[i].setMap(null)
|
|
}
|
|
}
|
|
@@ -347,29 +346,6 @@
|
|
}
|
|
}
|
|
})
|
|
})
|
|
});
|
|
});
|
|
- // that.map.on('click', function (e) {
|
|
|
|
- // for (var i = 0, l = that.polygons.length; i < l; i++) {
|
|
|
|
- // that.polygons[i].setMap(null)
|
|
|
|
- // }
|
|
|
|
- // that.marker.setMap(that.map)
|
|
|
|
- // that.marker.setPosition(e.lnglat)
|
|
|
|
- // geocoder.getAddress(e.lnglat, function (status, result) {
|
|
|
|
- // if (status === 'complete') {
|
|
|
|
- // var obj = {}
|
|
|
|
- // that.province = result.regeocode.addressComponent.province
|
|
|
|
- // that.city = result.regeocode.addressComponent.city
|
|
|
|
- // that.district = result.regeocode.addressComponent.district
|
|
|
|
- // obj.formattedAddress = result.regeocode.formattedAddress
|
|
|
|
- // obj.areacode = result.regeocode.addressComponent.adcode
|
|
|
|
- // that.address = result.regeocode.formattedAddress
|
|
|
|
- // obj.lat = e.lnglat.lat
|
|
|
|
- // obj.lng = e.lnglat.lng
|
|
|
|
- // that.$emit('pickedAddress', obj)
|
|
|
|
- // } else {
|
|
|
|
- // that.$emit('pickedAddress', '')
|
|
|
|
- // }
|
|
|
|
- // })
|
|
|
|
- // })
|
|
|
|
// 根据坐标点定位,获取地址的详细信息
|
|
// 根据坐标点定位,获取地址的详细信息
|
|
if (that.position) {
|
|
if (that.position) {
|
|
that.marker.setMap(that.map)
|
|
that.marker.setMap(that.map)
|
|
@@ -394,6 +370,11 @@
|
|
)
|
|
)
|
|
}, 500)
|
|
}, 500)
|
|
this.loadmap()
|
|
this.loadmap()
|
|
|
|
+ // this.loadmap()
|
|
|
|
+ }).catch(e => {
|
|
|
|
+ console.log(e);
|
|
|
|
+ })
|
|
|
|
+ }
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
positions() {
|
|
positions() {
|