当前位置:网站首页>Antd design pro uses Baidu map, which can be tested in person
Antd design pro uses Baidu map, which can be tested in person
2022-04-23 00:11:00 【Buliang_ C】
List of articles
Preface
Recently assigned tasks , To use Baidu map , I happen to be using it Antd Design Pro V5. Just share a wave of Baidu map into pro Methods in the project , There are two ways . Apply for baidu account and ak Don't write anything like that , There are also many online tutorials .
1. Use BMap call JavaScript API
First, in the document.ejs Of head in , Global reference Baidu map API file
<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak= Your key "></script>
<script>
window.BMap = BMap
</script>

But only add the above two items , After we call window.BMap When , Will prompt in window I can't find it in China. 'BMap' attribute

At this point, we just need to find typing.d.ts Declaration file , It's just src Under the table of contents

stay window Add attributes to the extended interface of BMap

At this point, you are calling var BMap = window.BMap; There will be no prompt that the attribute cannot be found .
// example Demo
class map extends React.Component {
componentDidMount() {
const lng = 116.404; // Set latitude and longitude
const lat = 39.915;
var BMap = window.BMap
var map = new BMap.Map("container");
var point = new BMap.Point(lng, lat);
map.centerAndZoom(point, 18); // Initialize map
map.addControl(new BMap.MapTypeControl()); // Add a map type control
map.enableScrollWheelZoom(true); // Turn on mouse wheel zoom
}
render() {
return (
<PageContainer>
<div id="container" style={
{
// Create map container elements
width: '100vw',
height: '100vh',
margin: "-24px"
}} />
</PageContainer>);
}
}
export default map;
The renderings are as follows :

2. install react-bmap Components
First npm install react-bmap
npm install react-bmap --save
stay package.json View in , The component package has been successfully installed

When calling immediately , You will be prompted that the module cannot be found

At this time, we still need to go typing.d.ts Module declaration in

At this time, it can be used normally .
import React from 'react'
import {
Map, Marker, NavigationControl, InfoWindow} from 'react-bmap'
export default (): React.ReactNode => {
const lng = 116.404; // Set latitude and longitude
const lat = 39.915;
return (
<PageContainer>
<div>
<Map center={
{
lng, lat }} zoom="18" ScrollWheelZoom="true">
<Marker position={
{
lng, lat }} />
<NavigationControl />
<InfoWindow position={
{
lng, lat }} text=" Hello " title=" bye " />
</Map>
</div>
</PageContainer >
)
}
design sketch :

3. summary
The above are the problems and solutions I have encountered in introducing Baidu map into the project , I hope you guys will criticize and correct .
版权声明
本文为[Buliang_ C]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230008120613.html
边栏推荐
- L1-065 nonsense code (5 points)
- Understanding of swin transformer network architecture and corresponding improvement modules
- FCOS中相较传统anchor-based方法中独特的地方
- 两种方法实现mongodb自增id,推荐第二种
- 安川电机伺服软件SigmaWin+连接伺服驱动器无法连接问题
- 绝对定位不使用left,right,top,bottom等属性
- (转)Aspose.words编程指南之DOM树结构初识,Node类继承关系及说明
- Conditional judgment (while loop & for & switch loop & if else judgment)
- Hypermesh-laminate复合材料案例学习笔记
- PHP one-dimensional array de duplication
猜你喜欢

Ignition Modbus

(转)使用dotTrace6.0进行性能,内存分析

Automatic watering system based on 51 single chip microcomputer

Nodejs+express登录鉴权并注册部分

Swin Transformer网络架构、相应改进模块的理解

Summarize the methods of AI data enhancement

Invite you to participate in the ume plug-in development competition

什么是目标关键词?

EL2124模块接线和引脚含义

(转)Aspose.words编程指南之DOM树再识,各层结构之间的关系
随机推荐
Concurrent reachability analysis (three color marking method)
归纳AI数据增强的方法
Differences between WMS system and ERP warehouse management
What are the target keywords?
Vibrato tiktok
条码WMS系统与ERP接口实现方法
三菱FX5U配置MR-JE-C伺服驱动器 IEBasic设定
制作目标检测训练样本的方案
MTP management training plan - study notes on day 2
【leetcode】27. Removing Elements
基于.NetCore开发博客项目 StarBlog - (3) 模型设计
Sample imbalance
(转)WinSCP(SSH的FTP客户端)如何生成密钥登陆linu
Interviewer: how big is the performance difference between ArrayList and LinkedList?
Shell script notes (5) - conditional statements of this
Programming 2022-02 KTV
【ACM】78. Subset (return elements of all nodes without setting termination conditions)
算法--两数相加 II(Kotlin)
API接口知识小结
(转)Aspose.words编程指南之DOM树再识,各层结构之间的关系