|
|
@@ -29,6 +29,11 @@ export default class MapSearch extends Component {
|
|
|
componentDidMount () {
|
|
|
document.title = '地图搜索'
|
|
|
this.searchBar.focus()
|
|
|
+ // 检查 BMap 是否存在
|
|
|
+ if (!window.BMap) {
|
|
|
+ console.warn('百度地图未加载,搜索功能将不可用')
|
|
|
+ return
|
|
|
+ }
|
|
|
const { BMap } = window
|
|
|
let that = this
|
|
|
this.localSearch = new BMap.LocalSearch(this.map,
|
|
|
@@ -62,9 +67,10 @@ export default class MapSearch extends Component {
|
|
|
center,
|
|
|
searchList,
|
|
|
} = this.state
|
|
|
-
|
|
|
+ // 只有在 BMap 可用时才渲染搜索结果
|
|
|
+ const showSearchResults = !!window.BMap;
|
|
|
const searchItems = []
|
|
|
- if (searchList) {
|
|
|
+ if (showSearchResults && searchList) {
|
|
|
searchList.forEach((item, index) => {
|
|
|
searchItems.push(
|
|
|
<div
|