简单Label示例

此示例展示如何绘制Label对象。

关键代码

<style type="text/css">
.F01{word-break:normal;font-size:13px;color:#000;background-color:#0ff;padding:4px 2px 1px 2px;border:1px solid #000;width:100px;}
</style>
<script type="text/javascript">
    var labelOne = new sogou.maps.Label({
        position: myLatlng1, 
        map: map,
        title:"搜狗地图"
    });
	var labelTwo = new sogou.maps.Label({
        position: myLatlng2, 
        map: map,
		//指定自定义的css
		style:"F01",
        title:"搜狗地图搜狗地图搜狗地图搜狗地图搜狗地图搜狗地图搜狗地图搜狗地图"
    });
</script>

代码解析

创建自定义label样式。

.F01{word-break:normal;font-size:13px;color:#000;background-color:#0ff;padding:4px 2px 1px 2px;border:1px solid #000;width:100px;}

创建第一个label对象。

    var labelOne = new sogou.maps.Label({
        position: myLatlng1, 
        map: map,
        title:"搜狗地图"
    });

创建第二个label对象,设置自定义样式F01。

	var labelTwo = new sogou.maps.Label({
        position: myLatlng2, 
        map: map,
		//指定自定义的css
		style:"F01",
        title:"搜狗地图搜狗地图搜狗地图搜狗地图搜狗地图搜狗地图搜狗地图搜狗地图"
    });	

完整代码

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>搜狗地图 JavaScript API 示例: 简单Label示例</title>
<style type="text/css">
html {height: auto;}
body {height: auto;margin: 0;padding: 0;}
#map_canvas {width:1000px;height: 500px;position: absolute;}
.F01{word-break:normal;font-size:13px;color:#000;background-color:#0ff;padding:4px 2px 1px 2px;border:1px solid #000;width:100px;}
@media print {#map_canvas {height: 950px;}}
</style>
<script type="text/javascript" src="//api.go2map.com/maps/js/api_v2.5.1.js"></script>
<script type="text/javascript">
  function initialize() {
    var myLatlng1 = new sogou.maps.LatLng(39.981320,116.320247);
	var myLatlng2 = new sogou.maps.LatLng(39.980520,116.320247);
    var myOptions = {
      zoom: 15,
      center: myLatlng1,
      mapTypeId: sogou.maps.MapTypeId.ROADMAP
    }
    var map = new sogou.maps.Map(document.getElementById("map_canvas"), myOptions);
    var labelOne = new sogou.maps.Label({
        position: myLatlng1, 
        map: map,
        title:"搜狗地图"
    });
	var labelTwo = new sogou.maps.Label({
        position: myLatlng2, 
        map: map,
		//指定自定义的css
		style:"F01",
        title:"搜狗地图搜狗地图搜狗地图搜狗地图搜狗地图搜狗地图搜狗地图搜狗地图"
    });	
  }
</script>
</head>
<body onload="initialize()">
  <div id="map_canvas"></div>
</body>
</html>

运行代码