使用BMap.Label给百度地图的BMap.Marker上加上数字序号

        marker = new BMap.Marker(pointList[i])
		marker.setLabel(getNumberLabel(i));

		function getNumberLabel(number) {
			var offsetSize = new BMap.Size(0, 0);
			var labelStyle = {
				color: "#fff",
				backgroundColor: "0.05",
				border: "0"
			};

			//不同数字长度需要设置不同的样式。
			switch((number + '').length) {
				case 1:
					labelStyle.fontSize = "14px";
					offsetSize = new BMap.Size(4, 2);
					break;
				case 2:
					labelStyle.fontSize = "12px";
					offsetSize = new BMap.Size(2, 4);
					break;
				case 3:
					labelStyle.fontSize = "10px";
					offsetSize = new BMap.Size(-2, 4);
					break;
				default:
					break;
			}

			var label = new BMap.Label(number, {
				offset: offsetSize
			});
			label.setStyle(labelStyle);
			return label;
		}
	}

  

posted @ 2017-11-30 18:36  Asion Tang  阅读(...)  评论(...编辑  收藏