百度地图api3.0使用 标注点 以及 标注信息 个性化风格地图 样例

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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自定义地图,帮助用户在可视化操作下生成百度地图" />
<meta name="viewport" content="user-scalable=no, width=device-width" />
	
<title>疫情地图</title>
	<link rel="icon" href="images/favicon.ico">
<!--引用百度地图API-->
<style type="text/css">
    html,body{
     margin:0;padding:0;}
    .iw_poi_title {
     color:#CC5522;font-size:14px;font-weight:bold;overflow:hidden;padding-right:13px;white-space:nowrap}
    .iw_poi_content {
     font:12px arial,sans-serif;overflow:visible;padding-top:4px;white-space:-moz-pre-wrap;word-wrap:break-word}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=fucku&s=1"></script>
</head>

<body>
  <!--百度地图容器-->
  <div style="width: 100%;height: 500px; border:#ccc solid 1px;" id="dituContent"></div>
</body>
<script type="text/javascript">
	var httpRequest1 = new XMLHttpRequest();
	httpRequest1.open('GET', "http://www.libohao.com.cn/count/count/hrbyq.action", true);
	httpRequest1.send();
	
	var styleJson =
	[{
     
    "featureType": "land",
    "elementType": "geometry",
    "stylers": {
     
        "color": "#fffff9ff"
    }
}, {
     
    "featureType": "water",
    "elementType": "geometry",
    "stylers": {
     
        "color": "#69b0acff"
    }
}, {
     
    "featureType": "highway",
    "elementType": "geometry.fill",
    "stylers": {
     
        "color": "#b5caa0ff"
    }
}, {
     
    "featureType": "highway",
    "elementType": "geometry.stroke",
    "stylers": {
     
        "color": "#94ad79ff"
    }
}, {
     
    "featureType": "nationalway",
    "elementType": "geometry.fill",
    "stylers": {
     
        "color": "#b5caa0ff"
    }
}, {
     
    "featureType": "arterial",
    "elementType": "geometry.fill",
    "stylers": {
     
        "color": "#d4e2c6ff"
    }
}, {
     
    "featureType": "cityhighway",
    "elementType": "geometry.fill",
    "stylers": {
     
        "color": "#d4e2c6ff"
    }
}, {
     
    "featureType": "provincialway",
    "elementType": "geometry.fill",
    "stylers": {
     
        "color": "#d4e2c6ff"
    }
}, {
     
    "featureType": "provincialway",
    "elementType": "geometry.stroke",
    "stylers": {
     
        "color": "#b5caa0ff"
    }
}, {
     
    "featureType": "tertiaryway",
    "elementType": "geometry.fill",
    "stylers": {
     
        "color": "#ffffffff"
    }
}, {
     
    "featureType": "tertiaryway",
    "elementType": "geometry.stroke",
    "stylers": {
     
        "color": "#b5caa0ff"
    }
}, {
     
    "featureType": "fourlevelway",
    "elementType": "geometry.fill",
    "stylers": {
     
        "color": "#ffffffff"
    }
}, {
     
    "featureType": "fourlevelway",
    "elementType": "geometry.stroke",
    "stylers": {
     
        "color": "#b5caa0ff"
    }
}, {
     
    "featureType": "subway",
    "elementType": "geometry",
    "stylers": {
     
        "visibility": "off"
    }
}, {
     
    "featureType": "railway",
    "elementType": "geometry",
    "stylers": {
     
        "visibility": "off"
    }
}, {
     
    "featureType": "highwaysign",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off"
    }
}, {
     
    "featureType": "highwaysign",
    "elementType": "labels.icon",
    "stylers": {
     
        "visibility": "off"
    }
}, {
     
    "featureType": "nationalwaysign",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off"
    }
}, {
     
    "featureType": "nationalwaysign",
    "elementType": "labels.icon",
    "stylers": {
     
        "visibility": "off"
    }
}, {
     
    "featureType": "provincialwaysign",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off"
    }
}, {
     
    "featureType": "provincialwaysign",
    "elementType": "labels.icon",
    "stylers": {
     
        "visibility": "off"
    }
}, {
     
    "featureType": "tertiarywaysign",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off"
    }
}, {
     
    "featureType": "tertiarywaysign",
    "elementType": "labels.icon",
    "stylers": {
     
        "visibility": "off"
    }
}, {
     
    "featureType": "subwaylabel",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off"
    }
}, {
     
    "featureType": "subwaylabel",
    "elementType": "labels.icon",
    "stylers": {
     
        "visibility": "off"
    }
}, {
     
    "featureType": "nationalway",
    "elementType": "geometry.stroke",
    "stylers": {
     
        "color": "#94ad79ff"
    }
}, {
     
    "featureType": "cityhighway",
    "elementType": "geometry.stroke",
    "stylers": {
     
        "color": "#b5caa0ff"
    }
}, {
     
    "featureType": "arterial",
    "elementType": "geometry.stroke",
    "stylers": {
     
        "color": "#b5caa0ff"
    }
}, {
     
    "featureType": "highway",
    "stylers": {
     
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "6"
    }
}, {
     
    "featureType": "highway",
    "stylers": {
     
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "7"
    }
}, {
     
    "featureType": "highway",
    "stylers": {
     
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "8"
    }
}, {
     
    "featureType": "highway",
    "stylers": {
     
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "9"
    }
}, {
     
    "featureType": "highway",
    "elementType": "geometry",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "6"
    }
}, {
     
    "featureType": "highway",
    "elementType": "geometry",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "7"
    }
}, {
     
    "featureType": "highway",
    "elementType": "geometry",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "8"
    }
}, {
     
    "featureType": "highway",
    "elementType": "geometry",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "9"
    }
}, {
     
    "featureType": "highway",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "6"
    }
}, {
     
    "featureType": "highway",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "7"
    }
}, {
     
    "featureType": "highway",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "8"
    }
}, {
     
    "featureType": "highway",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "9"
    }
}, {
     
    "featureType": "nationalway",
    "stylers": {
     
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "6"
    }
}, {
     
    "featureType": "nationalway",
    "stylers": {
     
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "7"
    }
}, {
     
    "featureType": "nationalway",
    "stylers": {
     
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "8"
    }
}, {
     
    "featureType": "nationalway",
    "stylers": {
     
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "9"
    }
}, {
     
    "featureType": "nationalway",
    "elementType": "geometry",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "6"
    }
}, {
     
    "featureType": "nationalway",
    "elementType": "geometry",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "7"
    }
}, {
     
    "featureType": "nationalway",
    "elementType": "geometry",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "8"
    }
}, {
     
    "featureType": "nationalway",
    "elementType": "geometry",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "9"
    }
}, {
     
    "featureType": "nationalway",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "6"
    }
}, {
     
    "featureType": "nationalway",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "7"
    }
}, {
     
    "featureType": "nationalway",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "8"
    }
}, {
     
    "featureType": "nationalway",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "9"
    }
}, {
     
    "featureType": "provincialway",
    "stylers": {
     
        "curZoomRegionId": "0",
        "curZoomRegion": "8,9",
        "level": "8"
    }
}, {
     
    "featureType": "provincialway",
    "stylers": {
     
        "curZoomRegionId": "0",
        "curZoomRegion": "8,9",
        "level": "9"
    }
}, {
     
    "featureType": "provincialway",
    "elementType": "geometry",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "8,9",
        "level": "8"
    }
}, {
     
    "featureType": "provincialway",
    "elementType": "geometry",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "8,9",
        "level": "9"
    }
}, {
     
    "featureType": "provincialway",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "8,9",
        "level": "8"
    }
}, {
     
    "featureType": "provincialway",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "8,9",
        "level": "9"
    }
}, {
     
    "featureType": "cityhighway",
    "stylers": {
     
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "6"
    }
}, {
     
    "featureType": "cityhighway",
    "stylers": {
     
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "7"
    }
}, {
     
    "featureType": "cityhighway",
    "stylers": {
     
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "8"
    }
}, {
     
    "featureType": "cityhighway",
    "stylers": {
     
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "9"
    }
}, {
     
    "featureType": "cityhighway",
    "elementType": "geometry",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "6"
    }
}, {
     
    "featureType": "cityhighway",
    "elementType": "geometry",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "7"
    }
}, {
     
    "featureType": "cityhighway",
    "elementType": "geometry",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "8"
    }
}, {
     
    "featureType": "cityhighway",
    "elementType": "geometry",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "9"
    }
}, {
     
    "featureType": "cityhighway",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "6"
    }
}, {
     
    "featureType": "cityhighway",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "7"
    }
}, {
     
    "featureType": "cityhighway",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "8"
    }
}, {
     
    "featureType": "cityhighway",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off",
        "curZoomRegionId": "0",
        "curZoomRegion": "6,9",
        "level": "9"
    }
}, {
     
    "featureType": "entertainment",
    "elementType": "geometry",
    "stylers": {
     
        "color": "#e4f0d7ff"
    }
}, {
     
    "featureType": "manmade",
    "elementType": "geometry",
    "stylers": {
     
        "color": "#effcf0ff"
    }
}, {
     
    "featureType": "education",
    "elementType": "geometry",
    "stylers": {
     
        "color": "#e3f7e4ff"
    }
}, {
     
    "featureType": "building",
    "elementType": "geometry.stroke",
    "stylers": {
     
        "color": "#a1cfa4ff"
    }
}, {
     
    "featureType": "poilabel",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off"
    }
}, {
     
    "featureType": "poilabel",
    "elementType": "labels.icon",
    "stylers": {
     
        "visibility": "off"
    }
}, {
     
    "featureType": "education",
    "elementType": "labels.text.fill",
    "stylers": {
     
        "color": "#7a7a7aff"
    }
}, {
     
    "featureType": "education",
    "elementType": "labels.text.stroke",
    "stylers": {
     
        "color": "#ffffffff"
    }
}, {
     
    "featureType": "education",
    "elementType": "labels.text",
    "stylers": {
     
        "fontsize": 26
    }
}, {
     
    "featureType": "manmade",
    "elementType": "labels.text.fill",
    "stylers": {
     
        "color": "#afafafff"
    }
}, {
     
    "featureType": "manmade",
    "elementType": "labels.text",
    "stylers": {
     
        "fontsize": 26
    }
}, {
     
    "featureType": "scenicspotslabel",
    "elementType": "labels.text.fill",
    "stylers": {
     
        "color": "#376b6dff"
    }
}, {
     
    "featureType": "scenicspots",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "off"
    }
}, {
     
    "featureType": "scenicspotslabel",
    "elementType": "labels",
    "stylers": {
     
        "visibility": "on"
    }
}, {
     
    "featureType": "scenicspotslabel",
    "elementType": "labels.text.stroke",
    "stylers": {
     
        "color": "#ffffffff",
        "weight": 4
    }
}, {
     
    "featureType": "country",
    "elementType": "labels.text.fill",
    "stylers": {
     
        "color": "#376b6dff"
    }
}, {
     
    "featureType": "country",
    "elementType": "labels.text.stroke",
    "stylers": {
     
        "color": "#ffffffff",
        "weight": 3
    }
}, {
     
    "featureType": "water",
    "elementType": "labels.text.fill",
    "stylers": {
     
        "color": "#ffffffff"
    }
}, {
     
    "featureType": "water",
    "elementType": "labels.text.stroke",
    "stylers": {
     
        "color": "#ffffff00"
    }
}, {
     
    "featureType": "water",
    "elementType": "labels.text",
    "stylers": {
     
        "fontsize": 24
    }
}];
    var map = new BMap.Map("dituContent");//在百度地图容器中创建一个地图
    //创建和初始化地图函数:
    function initMap(){
     
        createMap();//创建地图
	
        setMapEvent();//设置地图事件
        addMapControl();//向地图添加控件
    }
    
    //创建地图函数:
    function createMap(){
     
        var point = new BMap.Point(126.542417,45.807781);//定义一个中心点坐标
        map.centerAndZoom(point,12);//设定地图的中心点和坐标并将地图显示在地图容器中
		map.setMapStyleV2({
     styleJson:styleJson});
		window.onload = function () {
     
			var url = "json/data.json"/*json文件url,本地的就写本地的位置,如果是服务器的就写服务器的路径*/
			var request = new XMLHttpRequest();
			request.open("get", url);/*设置请求方法与路径*/
			request.send(null);/*不发送数据到服务器*/
			request.onload = function () {
     /*XHR对象获取到返回信息后执行*/
				if (request.status == 200) {
     /*返回状态为200,即为数据获取成功*/
					var json = JSON.parse(request.responseText);
					//console.log(json);
					for(var i=0;i<json.length;i++){
     
						var point1 = new BMap.Point(json[i].x, json[i].y);  
						var content = json[i].content;
						//console.log(content);
						createMarker(point1, content, json[i].ad_name);
					}
				}
			}
		}
		
    }
    //地图事件设置函数:
    function setMapEvent(){
     
        map.enableDragging();//启用地图拖拽事件,默认启用(可不写)
        map.enableScrollWheelZoom();//启用地图滚轮放大缩小
        map.enableDoubleClickZoom();//启用鼠标双击放大,默认启用(可不写)
        map.enableKeyboard();//启用键盘上下左右键移动地图
    }
    function createMarker(point1,content, ad_name){
     
			var marker = new BMap.Marker(point1); // 创建标注
			var offsetSize = new BMap.Size(10, 10);
			var labelStyle = {
     
				color: "#fff",
				backgroundColor: "#333333",
				border: "0",
				fontSize : "10px",
				width:"100px",
				opacity:"0.8",
				verticalAlign:"center",
				borderRadius: "2px",
				whiteSpace:"normal",
				wordWrap:"break-word",
				padding:"5px",
			};
			var label = new BMap.Label(ad_name, {
     
				offset: offsetSize
			});
			label.setStyle(labelStyle);

			marker.setLabel(label);
			marker.addEventListener("click", function () {
      marker.openInfoWindow(new BMap.InfoWindow("

" + content + "

"
)); }); map.addOverlay(marker); } //地图控件添加函数: function addMapControl(){ //向地图中添加缩放控件 var ctrl_nav = new BMap.NavigationControl({ anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_LARGE}); map.addControl(ctrl_nav); //向地图中添加缩略图控件 var ctrl_ove = new BMap.OverviewMapControl({ anchor:BMAP_ANCHOR_BOTTOM_RIGHT,isOpen:1}); map.addControl(ctrl_ove); //向地图中添加比例尺控件 var ctrl_sca = new BMap.ScaleControl({ anchor:BMAP_ANCHOR_BOTTOM_LEFT}); map.addControl(ctrl_sca); } initMap();//创建和初始化地图 </script>
[地图实例](http://www.libohao.com.cn/hrbyq/)
#疫情爬虫
import requests
from bs4 import BeautifulSoup
from os import system

def getHTMLText(url):
	try:
		head = {
     \
			'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36'\
			}
		r = requests.get(url, timeout = 30, headers = head)
		r.raise_for_status()
		r.encoding = 'utf-8'
		return r.text
	except:
		return ""

def parsePage(ilt, html):
	try:
		soup = BeautifulSoup(html, 'html.parser')
		#print(soup)
		total = eval(str(soup.find('script', id = 'getStatisticsService'))[69:-20].replace('false', 'False'))
		tplt1 = "\t{0:{5}^12}\t{1:^8}\t{2:^8}\t{3:^4}\t{4:^4}"
		tplt2 = "\t{0:{5}^12}\t{1:{5}^14}\t{2:{5}^10}\t{3:{5}^6}\t{4:{5}^6}"
		print(tplt1.format("病毒名称", "确诊病例", "疑似病例", "死亡病例", "治愈病例", chr(12288)))
		print(tplt2.format(total['virus'], total['confirmedCount'], total['suspectedCount'], total['deadCount'], total['curedCount'], chr(12288)))
		print("{0:-^80}".format(""))
		data = eval(str(soup.find('script', id = 'getAreaStat'))[51:-20])
		for temp in data:
			prov = temp['provinceShortName']
			conf = temp['confirmedCount']
			ilt.append([prov, conf])
	except:
		print("")

def printList(ilt):
	tplt = "{:^4}\t{:^8}\t{:^4}"
	print(tplt.format("序号", "省份", "确诊"))
	count = 0
	for g in ilt:
		count += 1
		print(tplt.format(count, g[0], g[1]))

def main():
	url = "https://ncov.dxy.cn/ncovh5/view/pneumonia_peopleapp"
	infoList = []
	try:
		html = getHTMLText(url)
		parsePage(infoList, html)
	except:
		pass
	printList(infoList)

main()
system('pause')

你可能感兴趣的:(日常)