|
@@ -13,20 +13,21 @@
|
|
|
</div>
|
|
|
</template>
|
|
|
</el-autocomplete>
|
|
|
- <div id="container"></div>
|
|
|
+ <div :id="`map_uid_${uid}`" class="containers"></div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { mapAddress } from './index';
|
|
|
export default {
|
|
|
data() {
|
|
|
+ let _this = this;
|
|
|
return {
|
|
|
map: '',
|
|
|
placeSearch: '',
|
|
|
marker: '',
|
|
|
addressName: '', //地址查询名称
|
|
|
poisArray: [],
|
|
|
+ uid: _this._uid
|
|
|
};
|
|
|
},
|
|
|
props: {
|
|
@@ -39,11 +40,10 @@ export default {
|
|
|
methods: {
|
|
|
init() {
|
|
|
let _this = this;
|
|
|
- _this.map = new AMap.Map('container', {
|
|
|
+ _this.map = new AMap.Map(`map_uid_${_this.uid}`, {
|
|
|
resizeEnable: true, //是否监控地图容器尺寸变化
|
|
|
zoom: 11 //初始化地图层级
|
|
|
});
|
|
|
- // _this.map.on('click', _this.mapClick);
|
|
|
_this.placeSearch = new AMap.PlaceSearch({
|
|
|
map: _this.map
|
|
|
});
|
|
@@ -58,7 +58,7 @@ export default {
|
|
|
position: loc
|
|
|
});
|
|
|
this.map.add(this.marker);
|
|
|
- this.$emit('getDot',e)
|
|
|
+ this.$emit('getDot', e);
|
|
|
},
|
|
|
togglePlaceSearch(val, resolve) {
|
|
|
this.placeSearch.search(val, (status, result) => {
|
|
@@ -70,7 +70,6 @@ export default {
|
|
|
},
|
|
|
handleSelect(item) {
|
|
|
this.mapClick(item);
|
|
|
- // this.$emit('getDot', item);
|
|
|
},
|
|
|
querySearch(queryString, cb) {
|
|
|
new Promise((resolve) => {
|
|
@@ -82,6 +81,10 @@ export default {
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
+ destroyed() {
|
|
|
+ this.map && this.map.destroy();
|
|
|
+ this.marker = '';
|
|
|
+ },
|
|
|
created() {
|
|
|
new Promise((resolve) => {
|
|
|
if (!!AMap) {
|
|
@@ -95,7 +98,7 @@ export default {
|
|
|
</script>
|
|
|
<style scoped lang="scss">
|
|
|
/* --------------------------------高德地图样式----------------------------- */
|
|
|
-#container {
|
|
|
+.containers {
|
|
|
margin-top: 20px;
|
|
|
width: 100%;
|
|
|
height: 400px;
|