1.html 页面引入 相关js

public/index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<title>React App</title>
<link href="lib/baidumapv2/css/baidu_map_v2.css" rel="stylesheet" type="text/css"/>
<script src="lib/baidumapv2/baidumap_offline_v2_load.js"></script>
<script src="lib/baidumapv2/tools/TextIconOverlay_min.js"></script>
<script src="lib/baidumapv2/tools/MarkerClusterer_min.js"></script>
<script>
// 实例化 百度地图
window.BMap = BMap;
window.BMapLib = BMapLib;
</script>
</head>
<body>
<div id="root"></div>
</body>
</html>

2.创建 BMap 组件

src/components/BMap/index.js

/**
* 百度地图 组件
*/
import React,{ PureComponent } from 'react';
// 获取屏幕宽高
const width = document.documentElement.clientWidth + 'px';
const height = document.documentElement.clientHeight - 95 + 'px'; class BMap extends PureComponent {
// 构造函数
constructor(props) {
super(props); this.state = {
//
};
} // 生命周期
componentDidMount () {
var BMap = window.BMap
var map = new BMap.Map("allmap"); // 创建Map实例
map.centerAndZoom(new BMap.Point(116.404, 39.915), 11); // 初始化地图,设置中心点坐标和地图级别
map.addControl(new BMap.MapTypeControl()); //添加地图类型控件
map.setCurrentCity("北京"); // 设置地图显示的城市 此项是必须设置的
map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
} render(){
return (
<div id='allmap' style={{width:width,height:height}}></div>
)
}
} export default BMap;

.

.

react 自定义 百度地图(BMap)组件的更多相关文章

  1. react 引入 百度地图API

    使用 Echarts 的地图的时候,发现报错,说 Bmap api is not loaded 百度地图API没有加载 乍一想,Echarts 用的也是 百度地图 啊,没有引入百度地图,还用个啥,当然 ...

  2. 百度地图BMap实现在行政区域内做标注

    使用环境 vue bmap.js element-ui 页面展示 前提步骤 在index中引入百度地图提供的js库 在使用的vue页面中实例化地图 <!-- 给id随便起给名字 --> & ...

  3. vue项目 调用百度地图 BMap is not defined

    这次老板新接了一个四点半官网页面,使用vue来写.emm……我感觉整个人都不好了,两天半解决了20个静态页面.还好vue写页面简直飞快,遇到一个vue的新坑,使用百度地图. 研究了好一会,总是报错BM ...

  4. echarts3.8.4实现城市空气质量(结合百度地图bmap.js,小航哥)

    (小航哥自己实现的)为了事先地图效果,需要以下准备: 用百度地图作为地图,需要 1.bmap.min.js(下载地址https://github.com/ecomfe/echarts ,GitHub上 ...

  5. 【React】 百度地图API

    百度地图 开发文档 :http://lbsyun.baidu.com/index.php?title=jspopular 调用接口 需要 内置加载一个 百度api文件    使用自己的ak  申请一个 ...

  6. vue引入百度地图 --BMap is not defined ,eslint BMap报错

    在mounted初始化地图的时候,因为异步问题会导致BMap is not defined,也就是百度的api还没完全引入或者加载完成,就已经进行地图初始化了 解决方法: 1.创建一个map.js e ...

  7. 百度地图BMap API实例

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...

  8. vue引入百度地图api组件封装(根据地址定位)

    Map.vue <template> <div class="Map" :style="{ height: this.height+'px', widt ...

  9. echarts 与 百度地图bmap结合系列: 如何设置地图缩放级别和监听缩放事件

    简单的demo: // ehcarts 的实例对象 this.myChart = echarts.init(el) // ehcarts加载完成事件 this.myChart.on('finished ...

随机推荐

  1. selenium - 常用页面操作

    # 2.常用页面操作 # 访问某一个页面url = 'http://www.baidu.com'driver.get(url) # 获取页面的标题title = driver.titleprint(t ...

  2. day03_01 Python历史、32bit和64bit系统的区别

    先看一下讲师的笔记,有python介绍 在python2.6版本之后,想清理一些东西,追求简单明了,就直接升级到了python3.0 但是python3.0导致很多企业都不更新,因为有很多企业的网站代 ...

  3. Leetcode 472.连接词

    连接词 给定一个不含重复单词的列表,编写一个程序,返回给定单词列表中所有的连接词. 连接词的定义为:一个字符串完全是由至少两个给定数组中的单词组成的. 示例: 输入: ["cat" ...

  4. leetcode with python -> tree

    100. Same Tree Given two binary trees, write a function to check if they are the same or not. Two bi ...

  5. JAVA-STRUTS-2x的项目配置

    首先是web.xml的配置,这个是项目加载的开始. <display-name></display-name> <!--struts2配置开始--> <fil ...

  6. AtCoder Beginner Contest 070

    我好想有点思维江化,所以我想给这个丝毫没有问题的abc也写下 A - Palindromic Number Time Limit: 2 sec / Memory Limit: 256 MB Score ...

  7. 【mysql优化 2】索引条件下推优化

    原文地址:Index Condition Pushdown Optimization 索引条件下推(ICP:index condition pushdown)是mysql中一个常用的优化,尤其是当my ...

  8. onclick跳转到其他页面的几种方式

    如果是本页显示可以直接用location,方法如下: ①onclick="javascript:window.location.href='URL'" ②onclick=" ...

  9. UVa——540Team Queue(STL练习map、queue数组的综合使用)

    Team Queue Time Limit:                                                        3000MS                 ...

  10. element-ui 的input组件 @keyup.enter事件的添加办法

    <el-input placeholder="请输入密码" type="password" @keyup.enter.native="login ...