87,910
社区成员
发帖
与我相关
我的任务
分享
<?php
while($row5=mysql_fetch_array($query5))
{
$str1 = $row5['jingwei']; // 原始字符串
$str2 = explode("|", $str1); //explode分离函数的应用
$num = count($str2) - 1;
?>
var polygon = new BMap.Polygon([
<?php
for($n=0; $n < $num; $n++)
{
?>
new BMap.Point(<?php echo $str2[$n]; ?>, <?php echo $str2[$n+1]; ?>)
<?php if($n < $num) echo ","; if($n == $num) echo ""; $n++;
}
?>
], {strokeColor:"<?php echo $row['bdcolor'] ?>",fillColor:"#f8f8f8", strokeWeight:3, strokeOpacity:0,fillOpacity:0});
map.addOverlay(polygon);
polygon.addEventListener('mouseover',function(){map.addOverlay(label)})
polygon.addEventListener('mouseout',function(){map.removeOverlay(label)})
str2 = str2.concat(polygon.getPath());
map.setViewport(str2); //调整视野
var label=new BMap.Label('文字内容',{position:map.getCenter()});
<?php
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=您的密钥"></script>
<title>添加行政区划</title>
</head>
<body>
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
// 百度地图API功能
var map = new BMap.Map("allmap");
map.centerAndZoom(new BMap.Point(116.403765, 39.914850), 5);
map.enableScrollWheelZoom();
function getBoundary(){
var bdary = new BMap.Boundary();
bdary.get("北京市海淀区", function(rs){ //获取行政区域
map.clearOverlays(); //清除地图覆盖物
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
alert('未能获取当前输入行政区域');
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 2, strokeColor: "#ff0000"}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
//////////////////////
ply.addEventListener('mouseover',function(){map.addOverlay(label)})
ply.addEventListener('mouseout',function(){map.removeOverlay(label)})
//////////////////////
pointArray = pointArray.concat(ply.getPath());
}
map.setViewport(pointArray); //调整视野
var label=new BMap.Label('文字内容',{position:map.getCenter()})////////////////////////
});
}
setTimeout(function(){
getBoundary();
}, 2000);
</script>