123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <template>
- <div>
- <el-autocomplete
- popper-class="my-autocomplete"
- v-model="addressName"
- :fetch-suggestions="querySearch"
- placeholder="请输入地址查找"
- @select="handleSelect"
- >
- <template slot-scope="{ item }">
- <div class="name">
- {{ item.name }} <span>({{ item.cityname + item.adname }})</span>
- </div>
- </template>
- </el-autocomplete>
- <div id="container"></div>
- </div>
- </template>
- <script>
- import { mapAddress } from './index';
- export default {
- data() {
- return {
- map: '',
- placeSearch: '',
- marker: '',
- addressName: '', //地址查询名称
- poisArray: [],
- };
- },
- props: {
- mapPopUpStatus: {
- type: Boolean,
- required: true
- }
- },
- computed: {},
- methods: {
- init() {
- let _this = this;
- _this.map = new AMap.Map('container', {
- resizeEnable: true, //是否监控地图容器尺寸变化
- zoom: 11 //初始化地图层级
- });
- // _this.map.on('click', _this.mapClick);
- _this.placeSearch = new AMap.PlaceSearch({
- map: _this.map
- });
- },
- mapClick(e) {
- if (this.marker !== '') {
- this.map.remove(this.marker);
- }
- let loc = [e.location.lat, e.location.lng];
- this.marker = new AMap.Marker({
- icon: 'https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png',
- position: loc
- });
- this.map.add(this.marker);
- this.$emit('getDot',e)
- },
- togglePlaceSearch(val, resolve) {
- this.placeSearch.search(val, (status, result) => {
- if (result.info == 'OK') {
- this.poisArray = result.poiList.pois;
- }
- resolve && resolve(true);
- });
- },
- handleSelect(item) {
- this.mapClick(item);
- // this.$emit('getDot', item);
- },
- querySearch(queryString, cb) {
- new Promise((resolve) => {
- this.togglePlaceSearch(queryString, resolve);
- }).then(() => {
- if (this.poisArray.length !== 0) {
- cb(this.poisArray);
- }
- });
- }
- },
- created() {
- new Promise((resolve) => {
- if (!!AMap) {
- resolve(true);
- }
- }).then(() => {
- this.init();
- });
- }
- };
- </script>
- <style scoped lang="scss">
- /* --------------------------------高德地图样式----------------------------- */
- #container {
- margin-top: 20px;
- width: 100%;
- height: 400px;
- }
- .my-autocomplete {
- li {
- line-height: normal;
- padding: 7px;
- .name {
- text-overflow: ellipsis;
- overflow: hidden;
- span {
- font-size: 12px;
- color: #b4b4b4;
- }
- }
- }
- }
- </style>
|