<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>邢台地图</title>
<style type="text/css">
</style>
<!--<script type="text/javascript" src="http://api.map.baidu.com/api?key=&v=1.1&services=true"></script>-->
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
</head>
<body>
<div style="width:1000px;height:400px;border:#ccc solid 1px;" id="dituContent"></div>
</body>
<script type="text/javascript">
//创建和初始化地图函数:
function initMap(){
createMap();//创建地图
setMapEvent();//设置地图事件
addMapControl();//向地图添加控件
addMarker();//向地图中添加marker
}
//创建地图函数:
function createMap(){
var map = new BMap.Map("dituContent");//在百度地图容器中创建一个地图
var point = new BMap.Point(114.510314,37.082719);//定义一个中心点坐标
map.centerAndZoom(point,12);//设定地图的中心点和坐标并将地图显示在地图容器中
window.map = map;//将map变量存储在全局
}
//地图事件设置函数:
function setMapEvent(){
map.enableDragging();//启用地图拖拽事件,默认启用(可不写)
map.enableScrollWheelZoom();//启用地图滚轮放大缩小
map.enableDoubleClickZoom();//启用鼠标双击放大,默认启用(可不写)
map.enableKeyboard();//启用键盘上下左右键移动地图
}
//地图控件添加函数:
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);
}
//标注点数组
var markerArr = [{title:"邢台市桥西管理部",content:"邢台市桥西",point:"114.476233|37.066431",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市内丘县管理部",content:"邢台市内丘县",point:"114.519792|37.297078",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市隆尧县管理部",content:"邢台市隆尧县",point:"114.777789|37.355611",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市邢台县管理部",content:"邢台市邢台县",point:"114.550642|37.092054",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市任县管理部",content:"邢台市任县",point:"114.676548|37.12728",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市南和县管理部",content:"邢台市南和县",point:"114.709893|37.034229",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市柏乡县管理部",content:"邢台市柏乡县",point:"114.700699|37.488854",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市临城县管理部",content:"邢台市临城县",point:"114.505998|37.451062",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市宁晋县管理部",content:"邢台市宁晋县",point:"114.92703|37.625731",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市巨鹿县管理部",content:"邢台市巨鹿县",point:"115.047268|37.227904",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市新河县管理部",content:"邢台市新河县",point:"115.248685|37.534461",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市威县管理部",content:"邢台市威县",point:"115.271583|36.982599",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市临西县管理部",content:"邢台市临西县",point:"115.505082|36.876364",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市桥东管理部",content:"邢台市桥东区",point:"114.505998|37.451062",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市邢台经济开发区管理部",content:"邢台市邢台经济开发区",point:"114.572242|37.067604",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市大曹庄管理区管理部",content:"邢台市大曹庄管理区",point:"114.948494|37.536264",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市平乡县管理部",content:"邢台市平乡县",point:"115.034926|37.069463",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市清河县管理部",content:"邢台市清河县",point:"115.674151|37.046311",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市南宫县管理部",content:"邢台市南宫县",point:"115.41461|37.364505",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
,{title:"邢台市沙河县管理部",content:"邢台市沙河县",point:"114.509796|36.861397",isOpen:0,icon:{w:23,h:25,l:46,t:21,x:9,lb:12}}
];
//创建marker
function addMarker(){
for(var i=0;i<markerArr.length;i++){
var json = markerArr[i];
var p0 = json.point.split("|")[0];
var p1 = json.point.split("|")[1];
var point = new BMap.Point(p0,p1);
var iconImg = createIcon(json.icon);
var marker = new BMap.Marker(point,{icon:iconImg});
var iw = createInfoWindow(i);
var label = new BMap.Label(json.title,{"offset":new BMap.Size(json.icon.lb-json.icon.x+10,-20)});
marker.setLabel(label);
map.addOverlay(marker);
label.setStyle({
borderColor:"#808080",
color:"#333",
cursor:"pointer"
});
(function(){
var index = i;
var _iw = createInfoWindow(i);
var _marker = marker;
_marker.addEventListener("click",function(){
this.openInfoWindow(_iw);
});
_iw.addEventListener("open",function(){
_marker.getLabel().hide();
})
_iw.addEventListener("close",function(){
_marker.getLabel().show();
})
label.addEventListener("click",function(){
_marker.openInfoWindow(_iw);
})
if(!!json.isOpen){
label.hide();
_marker.openInfoWindow(_iw);
}
})()
}
}
//创建InfoWindow
function createInfoWindow(i){
var json = markerArr[i];
var iw = new BMap.InfoWindow("<b class='iw_poi_title' title='" + json.title + "'>" + json.title + "</b><div class='iw_poi_content'>"+json.content+"</div>");
return iw;
}
//创建一个Icon
function createIcon(json){
var icon = new BMap.Icon("http://app.baidu.com/map/images/us_mk_icon.png", new BMap.Size(json.w,json.h),{imageOffset: new BMap.Size(-json.l,-json.t),infoWindowOffset:new BMap.Size(json.lb+5,1),offset:new BMap.Size(json.x,json.h)})
return icon;
}
initMap();//创建和初始化地图
//创建marker
function getBoundary(){
var bdary = new BMap.Boundary();
bdary.get("邢台市桥西",function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 1, fillColor: "#ec42aa",fillOpacity:0.3,strokeColor: "#ec42aa",strokeOpacity:0.3}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
function getBoundary2(){
var bdary = new BMap.Boundary();
bdary.get("邢台市内丘县",function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 1, fillColor: "#47e3c4",fillOpacity:0.3,strokeColor: "#47e3c4",strokeOpacity:0.3}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
function getBoundary3(){
var bdary = new BMap.Boundary();
bdary.get("邢台市隆尧县",function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 1, fillColor: "#2892ce",fillOpacity:0.3,strokeColor: "#2892ce",strokeOpacity:0.3}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
function getBoundary4(){
var bdary = new BMap.Boundary();
bdary.get("邢台市邢台县",function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 1, fillColor: "#dfea32",fillOpacity:0.3,strokeColor: "#dfea32",strokeOpacity:0.3}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
function getBoundary5(){
var bdary = new BMap.Boundary();
bdary.get("邢台市任县",function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 1, fillColor: "#de891a",fillOpacity:0.3,strokeColor: "#de891a",strokeOpacity:0.3}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
function getBoundary6(){
var bdary = new BMap.Boundary();
bdary.get("邢台市南和县",function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 1, fillColor: "#5d5d5d",fillOpacity:0.3,strokeColor: "#5d5d5d",strokeOpacity:0.3}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
function getBoundary7(){
var bdary = new BMap.Boundary();
bdary.get("邢台市巨鹿县",function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 1, fillColor: "#c56313",fillOpacity:0.3,strokeColor: "#c56313",strokeOpacity:0.3}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
function getBoundary8(){
var bdary = new BMap.Boundary();
bdary.get("邢台市平乡县",function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 1, fillColor: "#2a4ac0",fillOpacity:0.3,strokeColor: "none",strokeOpacity:0.3}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
function getBoundary9(){
var bdary = new BMap.Boundary();
bdary.get("邢台市南宫市",function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 1, fillColor: "#8946ec",fillOpacity:0.3,strokeColor: "none",strokeOpacity:0.3}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
function getBoundary10(){
var bdary = new BMap.Boundary();
bdary.get("邢台市沙河市",function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 1, fillColor: "#9b412f",fillOpacity:0.3,strokeColor: "#9b412f",strokeOpacity:0.3}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
function getBoundary11(){
var bdary = new BMap.Boundary();
bdary.get("邢台市广宗县",function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 1, fillColor: "#949832",fillOpacity:0.3,strokeColor: "none",strokeOpacity:0.3}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
function getBoundary12(){
var bdary = new BMap.Boundary();
bdary.get("邢台市清河县",function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 1, fillColor: "#373837",fillOpacity:0.3,strokeColor: "#373837",strokeOpacity:0.3}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
function getBoundary13(){
var bdary = new BMap.Boundary();
bdary.get("邢台市威县",function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 1, fillColor: "#e72e62",fillOpacity:0.3,strokeColor: "none",strokeOpacity:0.3}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
function getBoundary14(){
var bdary = new BMap.Boundary();
bdary.get("邢台市临城县",function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 1, fillColor: "#1ac222",fillOpacity:0.3,strokeColor: "none",strokeOpacity:0.3}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
function getBoundary15(){
var bdary = new BMap.Boundary();
bdary.get("邢台市临西县",function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 1, fillColor: "#9b412f",fillOpacity:0.3,strokeColor: "none",strokeOpacity:0.3}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
function getBoundary16(){
var bdary = new BMap.Boundary();
bdary.get("邢台市新河县",function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 1, fillColor: "#949832",fillOpacity:0.3,strokeColor: "#eef36c",strokeOpacity:0.3}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
function getBoundary17(){
var bdary = new BMap.Boundary();
bdary.get("邢台市柏乡县",function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 1, fillColor: "#dfa00a",fillOpacity:0.3,strokeColor: "#dfa00a",strokeOpacity:0.3}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
function getBoundary18(){
var bdary = new BMap.Boundary();
bdary.get("邢台市宁晋县",function(rs){ //获取行政区域
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
return ;
}
var pointArray = [];
for (var i = 0; i < count; i++) {
var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 1, fillColor: "#e0760f",fillOpacity:0.3,strokeColor: "#e0760f",strokeOpacity:0.3}); //建立多边形覆盖物
map.addOverlay(ply); //添加覆盖物
pointArray = pointArray.concat(ply.getPath());
}
});
}
getBoundary();getBoundary2();getBoundary3();getBoundary4();getBoundary5();getBoundary6();getBoundary7();getBoundary8();getBoundary9();getBoundary10();
getBoundary11();getBoundary12();getBoundary13();getBoundary14();getBoundary15();getBoundary16();getBoundary17();getBoundary18();
</script>
</html>