vue.js - 放大页面加载时不支持的 vue2-google-maps
问题描述
输入新位置时,我的地图的缩放功能不会停留在 15。
我在一个页面上有一个搜索栏,然后会在另一个页面上显示该位置的地图。:zoom=15
页面加载时似乎没有兑现。我可以手动更改代码中的缩放、更新页面并查看正确的缩放。但我希望页面加载:zoom=15
.
请参见下面的代码:
<template>
<div>
<GmapMap
:center="{lat:10, lng:10}"
:zoom=15
class="my-map"
id="myMap"
ref="myMap"
style="height:500px;width:500px;"
>
<GmapMarker
:key="index"
v-for="(m, index) in locations"
:position="m"
:clickable="true"
:draggable="true"
@click="center=m.position"
/>
</GmapMap>
</div>
</template>
<script>
import { gmapApi } from "vue2-google-maps"
export default {
name: 'FindDefault',
data () {
return {
map: null,
locations: []
}
},
computed: {
google: gmapApi
},
mounted () {
this.$refs.myMap.$mapPromise
.then(map => {
this.map = map
const selection = this.$store.state.geoModule.mapSearchSelection
this.filterCoords(selection)
this.setBounds()
})
.catch(err => {
throw err
})
},
methods: {
filterCoords (selection) {
this.locations.push(selection.geometry.location)
},
setBounds () {
let bounds = new this.google.maps.LatLngBounds()
this.locations.forEach(loc => {
bounds.extend(loc)
})
this.$nextTick().then(() => {
this.$refs.myMap.fitBounds(bounds)
})
this.$refs.myMap.panToBounds(bounds)
}
}
}
</script>
解决方案
您使用的是什么版本的 vue2-google-maps?最近在 12/2018 报告的缩放级别存在问题:https ://github.com/xkjyeah/vue-google-maps/issues/561
确保您的版本 > 0.10.x
推荐阅读
- c - 使用 perf 分析多进程无限循环
- python - 如何在boto3 dynamoDB python中查询“不等于”
- php - 使用 preg_replace 替换 href 值并防止重复问号
- pandas - 如何将列表的对象类型读入熊猫数据框?
- postgresql - 如何通过查询在 postgresql 中使用 gin 索引的 jsonb 列运行组?
- python - 如何创建空浮动?
- rascal - 获取树节点的子节点数
- installation - Inno Setup:加载 wpInfoAfter 安装期间编辑的文件
- sql-server - 如何在 MSSQl Server Management Studio 中查看存储过程代码
- oracle - RAC oracle 中的节点之一未启动