weflex / react-baidu-map

React component to work with baidu javascript API which enables you search, pinch and more
36 stars 11 forks source link

'BMap' is not defined #3

Open alivelee opened 8 years ago

alivelee commented 8 years ago

I wraped my components like this

componentDidMount(){
    this.map = new BMap.Map(this.id);
    this.map.centerAndZoom(new BMap.Point(121.406316,31.009703), 22);
    this.map.addControl(new BMap.MapTypeControl());   
    this.map.setCurrentCity("上海");   
    this.map.enableScrollWheelZoom(true);    
  }

and i use create-react-app as a boilerplate,it can not compiled

yorkie commented 8 years ago

What's the BMap?

alivelee commented 8 years ago

this this._map = new BMap.Map(this.id); BMap in your component

yorkie commented 8 years ago

I mean how do you require the BMap? I didn't use any keyword names "BMap"...

alivelee commented 8 years ago

I haven't required BMap . I think it's coming from the script that from the Baidu Map API. You use the BMap in your componentDidMount lifecycle I add the script file in index file but can't require BMap from the script

gengjiawen commented 7 years ago

It's a bug in source code, need to change new BMap to new window.BMap.

alivelee commented 7 years ago

@gengjiawen I will try later

ruoru commented 6 years ago

Bmap may need add ur index.html header

<head>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=NrTYvuK4VE8l4E7e7eTEtcOe"></script>
</head>

//NrTYvuK4VE8l4E7e7eTEtcOe is my ak, u need use ur ak