|
@@ -0,0 +1,149 @@
|
|
|
+<template>
|
|
|
+ <div class="hui-flex hui-dialog">
|
|
|
+ <div class="hui-flex-box hui-dialog-content" style="padding: 0;padding-bottom: 20px;">
|
|
|
+ <div class="map">
|
|
|
+ <div class="map-input">
|
|
|
+ <input type="text" placeholder="请输入地理位置" v-model="input" id="tipinput" />
|
|
|
+ </div>
|
|
|
+ <div ref="gaode_Map" id="gaode_Map"></div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="hui-dialog-submit">
|
|
|
+ <el-button size="medium" @click="$emit('callback')">取 消</el-button>
|
|
|
+ <el-button size="medium" type="primary" @click="submit">保 存</el-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+<script>
|
|
|
+ import AMapLoader from "@amap/amap-jsapi-loader"; //引入AMapLoader
|
|
|
+ window._AMapSecurityConfig = {
|
|
|
+ // 设置安全密钥
|
|
|
+ securityJsCode: "3e392dc7eb2cf2c04b1b8899776e8905",
|
|
|
+ };
|
|
|
+ export default {
|
|
|
+ props: ['coordinates'],
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ map: {},
|
|
|
+ input: '',
|
|
|
+ markers: [],
|
|
|
+ address: [116.397428, 39.90923],
|
|
|
+ visible: false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ if (this.coordinates) this.address = this.coordinates.split(',');
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ this.initMap();
|
|
|
+ },
|
|
|
+ beforeDestroy() {
|
|
|
+ this.map && this.map.destroy();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ initMap() {
|
|
|
+ AMapLoader.load({
|
|
|
+ key: "880f8193c52d9dee80cd82212d9508cf", // 申请好的Web端开发者Key,首次调用 load 时必填
|
|
|
+ version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
|
|
|
+ plugins: ["AMap.AutoComplete", "AMap.PlaceSearch", "AMap.Geocoder"],
|
|
|
+ }).then((AMap) => {
|
|
|
+ this.map = new AMap.Map("gaode_Map", {
|
|
|
+ // 设置地图容器id
|
|
|
+ viewMode: "3D", // 是否为3D地图模式
|
|
|
+ zoom: 18, // 初始化地图级别
|
|
|
+ center: this.address, //中心点坐标
|
|
|
+ resizeEnable: true,
|
|
|
+ });
|
|
|
+ this.setMarker();
|
|
|
+ this.searchMap();
|
|
|
+ // 监听鼠标点击事件
|
|
|
+ this.map.on("click", this.clickMapHandler);
|
|
|
+ }).catch((e) => {});
|
|
|
+ },
|
|
|
+ searchMap() {
|
|
|
+ // 搜索框自动完成类
|
|
|
+ let auto = new AMap.AutoComplete({
|
|
|
+ input: "tipinput", // 使用联想输入的input的id
|
|
|
+ });
|
|
|
+ //构造地点查询类
|
|
|
+ let placeSearch = new AMap.PlaceSearch({
|
|
|
+ map: this.map,
|
|
|
+ });
|
|
|
+ // 当选中某条搜索记录时触发
|
|
|
+ auto.on("select", e => {
|
|
|
+ if (e.poi.location) {
|
|
|
+ placeSearch.setCity(e.poi.adcode);
|
|
|
+ placeSearch.search(e.poi.name);
|
|
|
+ this.address = [e.poi.location.lng, e.poi.location.lat];
|
|
|
+ this.setMarker();
|
|
|
+ } else {
|
|
|
+ this.$message.error("查询地址失败,请重新输入地址");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 点击地图事件获取经纬度,并添加标记
|
|
|
+ clickMapHandler(e) {
|
|
|
+ this.address = [e.lnglat.getLng(), e.lnglat.getLat()];
|
|
|
+ this.setMarker();
|
|
|
+ },
|
|
|
+ // 添加标记
|
|
|
+ setMarker() {
|
|
|
+ this.removeMarker();
|
|
|
+ let marker = new AMap.Marker({
|
|
|
+ position: this.address,
|
|
|
+ });
|
|
|
+ marker.setMap(this.map);
|
|
|
+ this.markers.push(marker);
|
|
|
+ },
|
|
|
+ // 删除之前后的标记点
|
|
|
+ removeMarker() {
|
|
|
+ if (this.markers) {
|
|
|
+ this.map.remove(this.markers);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ submit() {
|
|
|
+ this.$emit('callback', 'set', this.address);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+</script>
|
|
|
+
|
|
|
+
|
|
|
+<style lang="scss">
|
|
|
+ .map {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ position: relative;
|
|
|
+
|
|
|
+ #gaode_Map {
|
|
|
+ overflow: hidden;
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ }
|
|
|
+
|
|
|
+ .map-input {
|
|
|
+ position: absolute;
|
|
|
+ top: 20px;
|
|
|
+ left: 20px;
|
|
|
+ width: 300px;
|
|
|
+ z-index: 998;
|
|
|
+ background: #fff;
|
|
|
+ color: #000;
|
|
|
+ box-shadow: 0 2px 2px rgba(0, 0, 0, .15);
|
|
|
+ border-radius: 3px;
|
|
|
+
|
|
|
+ input {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ height: 38px;
|
|
|
+ line-height: 38px;
|
|
|
+ padding: 0 10px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .amap-sug-result {
|
|
|
+ color: #000;
|
|
|
+ z-index: 9999;
|
|
|
+ }
|
|
|
+</style>
|