// JavaScript Document
//自定义标记点,可以写html
/* map.addOverlay(new google.maps.FocusMarker(latlng,{
innerHtml : '时间
地点
'
}));*/
google.maps.FocusMarker = function(latlng, opt){
this.latlng = latlng;
this.innerHtml = opt.innerHtml || '';
this.className = opt.className || '';
this.css = opt.css || {};
this.id = opt.id || '';
this.offsetX = opt.offsetX || '';
this.offsetY = opt.offsetY || '';
}
google.maps.FocusMarker.prototype = new google.maps.Overlay();
google.maps.FocusMarker.prototype.initialize = function(map){
// 创建用于表示该矩形区域的 DIV 元素
var div = document.createElement("div");
div.id = this.id || '';
div.style.width = this.css.width || 'auto';
div.className = this.className;
div.style.border = this.css.border || "none";
div.style.color = this.css.color || "#ffffff";
div.style.backgroundColor = this.css.backgroundColor || "";
div.style.position = this.css.position || "absolute";
div.style.textAlign= this.css.textAlign || "center";
div.style.padding= this.css.padding || "0px 0px 0px 0px";
div.style.fontSize = this.css.fontSize || "12px";
div.style.height = this.css.height || "60px";
div.style.cursor = this.css.cursor || "pointer";
div.style.whiteSpace= this.css.whiteSpace || "nowrap";
var c = map.fromLatLngToDivPixel(this.latlng);
div.style.left = c.x+"px";
div.style.top = c.y+"px";
div.innerHTML = this.innerHtml;
// 我们希望将覆盖物紧贴于地图之上,因此我们把它放置在 Z 序最小的 G_MAP_MAP_PANE 层,
// 事实上,这也是地图本身的 Z 顺序,即在标注的影子之下
map.getPane(G_MAP_MAP_PANE).appendChild(div);
this.map = map;
this.container = div;
}
google.maps.FocusMarker.prototype.remove = function()
{
this.container.parentNode.removeChild(this.container);
}
google.maps.FocusMarker.prototype.redraw = function(force)
{
// 只有当坐标系改变时,我们才需要重绘
if (!force) return;
// 根据当前显示区域的经纬度坐标,计算 DIV 元素的左上角和右下角的像素坐标
var c = this.map.fromLatLngToDivPixel(this.latlng);
// 根据计算得到的坐标放置我们的 DIV 元素
this.container.style.left = (c.x +this.offsetX)+ "px";
this.container.style.top = (c.y +this.offsetY)+ "px";
// this.div_.style.width = "auto";
}