//格式 : 单位(全称搜索位置用),显示名称,介绍及链接(支持html)
//跳到中心点并放大地图
moveTo("威海市环翠区");
//覆盖物
var star_maks = [];
var dw_maks = [];
//一级党组织,直接显示
var d1 = [];
//提示:下面的代码用jquery,所以如果有不能运行的情况请引用后尝试
//百度地图api container对应前端div名称 前端要引用2.0版本的百度地图api
//需引用api.map.baidu.com/library/AreaRestriction/1.2/src/AreaRestriction_min.js
var map = new BMap.Map("container", { enableMapClick: false, minZoom: 10, maxZoom: 18 }); // 创建地图实例,禁止点击地图底图
//设置样式
map.setMapStyle({
styleJson: [
{//不显示点信息
"featureType": "poi",
"elementType": "all",
"stylers": {
"color": "#ffffff",
"visibility": "off"
}
}
]
});
//map.disableDragging();//禁止拖动
//map.disableDoubleClickZoom();//禁止双击缩放
map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
//添加缩放按钮
//var top_right_navigation = new BMap.NavigationControl({ anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_ZOOM }); //右上角,仅包含平移和缩放按钮
//map.addControl(top_right_navigation);
var top_left_control = new BMap.ScaleControl({ anchor: BMAP_ANCHOR_TOP_LEFT });// 左上角,添加比例尺
var top_left_navigation = new BMap.NavigationControl(); //左上角,添加默认缩放平移控件
map.addControl(top_left_control);
map.addControl(top_left_navigation);
var mapType1 = new BMap.MapTypeControl(
{
mapTypes: [BMAP_NORMAL_MAP, BMAP_HYBRID_MAP],
anchor: BMAP_ANCHOR_TOP_RIGHT
}
);
map.addControl(mapType1);
var blist = [];
var districtLoading = 0;
//添加党委
function addDw() {
for (var i = 0; i < d1.length; i++) {
var myCompOverlay = new DWOverlay(new BMap.Point(d1[i][0], d1[i][1]), d1[i][2], d1[i][3]);
map.addOverlay(myCompOverlay);
}
}
function getRandom() {
return Math.random() / 2;
}
/**
* 各种鼠标事件绑定
*/
function click(evt) {
//alert(evt.target.name);
}
function mouseover(evt) {
//evt.target.label.setZIndex(99);
//evt.target.label.setPosition(evt.point);
//evt.target.label.show();
}
function mousemove(evt) {
//evt.target.label.setPosition(evt.point);
}
function mouseout(evt) {
//evt.target.label.hide();
}
// 自定义覆盖物
function ComplexCustomOverlay(point, text, showico, ybg, sContent) {
this._point = point;
this._text = text;
this._showico = showico;
this._ybg = ybg;
this._sContent = sContent;
}
ComplexCustomOverlay.prototype = new BMap.Overlay();
ComplexCustomOverlay.prototype.initialize = function (map) {
this._map = map;
var div = this._div = document.createElement("div");
var flagcolor = "blue";
if (this._ybg == 1) {
flagcolor = "red";
}
div.style.position = "absolute";
div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
div.style.backgroundColor = "#EE5D5B";
div.style.border = "1px solid #BC3B3A";
div.style.color = "white";
div.style.height = "22px";
div.style.padding = "0px";
div.style.lineHeight = "18px";
div.style.whiteSpace = "nowrap";
div.style.MozUserSelect = "none";
div.style.fontSize = "12px"
var span = this._span = document.createElement("span");
span.style.padding = "4px";
span.style.height = "22px";
div.appendChild(span);
span.appendChild(document.createTextNode(this._text));
var that = this;
var arrow = this._arrow = document.createElement("div");
arrow.style.background = "url(http://map.baidu.com/fwmap/upload/r/map/fwmap/static/house/images/label.png) no-repeat";
arrow.style.position = "absolute";
arrow.style.width = "11px";
arrow.style.height = "10px";
arrow.style.top = "22px";
arrow.style.left = "10px";
arrow.style.overflow = "hidden";
div.appendChild(arrow);
if (this._showico) {
var ico = this._ico = document.createElement("div");
//ico.style.background = "url(images/dang.png) no-repeat";
ico.style.position = "absolute";
ico.style.width = "20px";
ico.style.height = "20px";
ico.style.top = "34px";
ico.style.left = "0px";
ico.style.overflow = "hidden";
div.appendChild(ico);
}
div.innerHTML += ("");
var opts = {
width: 300, // 信息窗口宽度
height: 200, // 信息窗口高度
title: that._text, // 信息窗口标题
enableMessage: false,//设置允许信息窗发送短息
}
var infoWindow = new BMap.InfoWindow(this._sContent, opts);
div.onmouseover = function () {
this.style.color = "yellow";
//this.style.backgroundColor = "#6BADCA";
//this.style.borderColor = "#0000ff";
//arrow.style.backgroundPosition = "0px -20px";
}
div.onmouseout = function () {
this.style.color = "white";
//this.style.backgroundColor = "#EE5D5B";
//this.style.borderColor = "#BC3B3A";
//arrow.style.backgroundPosition = "0px 0px";
}
//标记点击事件
div.onclick = function () {
map.openInfoWindow(infoWindow, that._point);
//map.centerAndZoom(that._point, 14);
}
map.getPanes().labelPane.appendChild(div);
return div;
}
ComplexCustomOverlay.prototype.draw = function () {
var map = this._map;
var pixel = map.pointToOverlayPixel(this._point);
this._div.style.left = pixel.x - parseInt(this._arrow.style.left) + "px";
this._div.style.top = pixel.y - 30 + "px";
}
//添加标记函数(地址,标题)
function addDzz(address, title, scontent) {
var myGeo = new BMap.Geocoder();
myGeo.getPoint(address, function (point) {
if (point) {
var myCompOverlay = new ComplexCustomOverlay(point, title, true, 0, scontent);
map.addOverlay(myCompOverlay);
} else {
//alert("没有解析到结果:" + address);
}
}, "威海市环翠区");
}
//转移到地址并放大地图
function moveTo(address) {
var myGeo = new BMap.Geocoder();
myGeo.getPoint(address, function (point) {
if (point) {
map.centerAndZoom(point, 12);
//map.panTo(point);
} else {
//alert("没有解析到结果:" + address);
}
}, "威海市环翠区");
}