当前位置:网站首页>Let the "label" content in Baidu map generator expand--solution
Let the "label" content in Baidu map generator expand--solution
2022-07-30 07:51:00 【cplvfx】
This article is simple:Copy directly from the article“完整代码”, 修改【坐标】和【公司信息】就完事了
代码
If you use the code I wrote,Need to know below2个
百度地图生成器:http://api.map.baidu.com/lbsapi/createmap/index.html
百度地图拾取坐标系统:http://api.map.baidu.com/lbsapi/getpoint/index.html
但是,Baidu map generator“标注”点,是不会展开的, We just want it to unfold today
效果展示:

Just focus on the code:
var cp_title=" Zhengzhou Yinglun Electric Co., Ltd";
var cp_content="联系人:王伟(先生) <br/>手 机:137***367<br/> 电 话:0371-***628 <br/> Q Q:128***498 <br/>网址:http://www.xxx.com <br/>地 址:Tanxiang Road, High-tech Development Zone, Zhengzhou City1号";
var cp_lng=113.539696;
var cp_lat=34.804373;
完整代码:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="百度地图,百度地图API,百度地图自定义工具,百度地图所见即所得工具" />
<meta name="description" content="百度地图API自定义地图,帮助用户在可视化操作下生成百度地图" />
<title>百度地图API自定义地图</title>
<!--引用百度地图API-->
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=v3Cg0hRvbX7cuUSKG2sEklyeP8iw5eye"></script>
</head>
<body>
<!--百度地图容器-->
<div style="width:80%;height:550px;border:#ccc solid 1px;font-size:12px" id="map"></div>
</body>
<script type="text/javascript">
var cp_title=" Zhengzhou Yinglun Electric Co., Ltd";
var cp_content="联系人:王伟(先生) <br/>手 机:137***367<br/> 电 话:0371-***628 <br/> Q Q:128***498 <br/>网址:http://www.xxx.com <br/>地 址:Tanxiang Road, High-tech Development Zone, Zhengzhou City1号";
var cp_lng=113.539696;
var cp_lat=34.804373;
//创建和初始化地图函数:
function initMap(){
createMap();//创建地图
setMapEvent();//设置地图事件
addMapControl();//向地图添加控件
addMapOverlay();//向地图添加覆盖物
}
function createMap(){
map = new BMap.Map("map");
map.centerAndZoom(new BMap.Point(cp_lng,cp_lat),19);
}
function setMapEvent(){
map.enableScrollWheelZoom();
map.enableKeyboard();
map.enableDragging();
map.enableDoubleClickZoom()
}
function addClickHandler(target,window){
target.addEventListener("click",function(){
target.openInfoWindow(window);
});
}
function addMapOverlay(){
var markers = [
{content:cp_content,title:cp_title,imageOffset: {width:-46,height:-21},position:{lat:cp_lat,lng:cp_lng}}
];
for(var index = 0; index < markers.length; index++ ){
var point = new BMap.Point(markers[index].position.lng,markers[index].position.lat);
var marker = new BMap.Marker(point,{icon:new BMap.Icon("http://api.map.baidu.com/lbsapi/createmap/images/icon.png",new BMap.Size(20,25),{
imageOffset: new BMap.Size(markers[index].imageOffset.width,markers[index].imageOffset.height)
})});
var label = new BMap.Label(markers[index].title,{offset: new BMap.Size(25,5)});
var opts = {
width: 200,
title: markers[index].title,
enableMessage: false
};
var infoWindow = new BMap.InfoWindow(markers[index].content,opts);// 创建信息窗口对象
marker.setLabel(label);
addClickHandler(marker,infoWindow);
map.addOverlay(marker);
map.openInfoWindow(infoWindow, map.getCenter()); // 打开信息窗口
};
}
//向地图添加控件
function addMapControl(){
var scaleControl = new BMap.ScaleControl({anchor:BMAP_ANCHOR_BOTTOM_LEFT});
scaleControl.setUnit(BMAP_UNIT_IMPERIAL);
map.addControl(scaleControl);
var navControl = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_LARGE});
map.addControl(navControl);
var overviewControl = new BMap.OverviewMapControl({anchor:BMAP_ANCHOR_BOTTOM_RIGHT,isOpen:true});
map.addControl(overviewControl);
}
var map;
initMap();
</script>
</html>修改代码
修改内容
var cp_title="The title you want to display、店名、公司名";
var cp_content="联系人:XXX(先生) <br/>手 机:137****5367<br/> 电 话:0371-***28 <br/> Q Q:128***98 <br/>网址:http://www.XXXXX.com <br/>地 址:Tanxiang Road, High-tech Development Zone, Zhengzhou City1号";修改坐标
第一步:打开 【百度地图拾取坐标系统】:http://api.map.baidu.com/lbsapi/getpoint/index.html
第二步:Find where you want to show
第三步:复制坐标

第四步:修改代码
“,”The value before the comma is given to the variablecp_lng
“,”The value after the comma is given to the variablecp_lat
var cp_lng=113.539696;
var cp_lat=34.804373;
第五步:保存-完成
边栏推荐
- 引导过程与服务控制
- flask项目快速搭建部署gunicorn+supervisor
- MongoDB - query
- Test and Development Engineer Growth Diary 009 - Environment Pai Pai Station: Development Environment, Test Environment, Production Environment, UAT Environment, Simulation Environment
- Network Protocol 03 - Routing and NAT
- Shortcut keys commonly used in the use of Word
- numpy 多维数组ndarray的详解
- Test Development Engineer Growth Diary 010 - CI/CD/CT in Jenkins (Continuous Integration Build/Continuous Delivery/Continuous Testing)
- 空间顶点到直线的距离计算及其源码
- (GGG)JWT
猜你喜欢
随机推荐
MySql connecting to the server remotely
Camera coordinate system, world coordinate system, pixel coordinate system conversion, and Fov conversion of OPENGLDEFocal Length and Opengl
DHCP principle and configuration
计算矩阵的逆源码(使用伴随矩阵,3×3的矩阵)
The Force Plan Microservices | Centralized Configuration Center Config Asymmetric Encryption and Security Management
向量三重积的等式推导证明
Data types of Redis6
Test development engineer diary 002 - starting from 0 interface automation
测试开发工程师成长日记001 - 敏捷测试、CI/CD/CT、DecOps的一些介绍
测试开发工程师成长日记017 - bug的生命周期
STL源码剖析:bound friend template friend代码测试和理解
prometheus监控minio
MongoDB-介绍,数据类型,基本语句
测试开发工程师成长日记002 - 从0开始做接口自动化
Bull: remove common characters
how to use xilinx's FFT ip
proftpd 配置文件说明
MongoDB - Introduction, Data Types, Basic Statements
牛客:删除公共字符
空间平面相交的直线的计算及其源码









