PopupMarker.prototype = new google.maps.OverlayView();
function PopupMarker(opts) {
this.ICON_WIDTH = 28;//图标的宽
this.ICON_HEIGHT = 28;//图标的高
this.map_ = opts.map;//地图对象
this.latlng_ = opts.position;
this.icon_ = opts.icon;
this.text_ = opts.text || "";
this.setMap(this.map_);
this.showpop = opts.showpop || false;
var agt = navigator.userAgent.toLowerCase();
var is_ie_ = ((agt.indexOf("msie") !== -1) && (agt.indexOf("opera") === -1));
var yPos = 0;
this.popupImgSrc_ = "images/1280.png";
this.popupTbl = {};
this.popupTbl.leftTop = {
"left": 0,
"top": yPos,
"width": 19,
"height": 7
};
this.popupTbl.leftTopFill = {
"left": 16,
"top": 3,
"width": 4,
"height": 4
};
this.popupTbl.rightTop = {
"left": 19,
"top": yPos,
"width": 10,
"height": 7
};
this.popupTbl.rightTopImg = {
"left": -125,
"top": 0,
"width": 10,
"height": 7
};
this.popupTbl.centerTopFill = {
"left": 19,
"top": yPos,
"width": 0,
"height": 7
};
yPos += this.popupTbl.leftTop.height;
this.popupTbl.leftBody = {
"left": 11,
"top": yPos,
"width": 8,
"height": 0
};
this.popupTbl.centerBodyFill = {
"left": 19,
"top": yPos,
"width": 40,
"height": 15
};
this.popupTbl.rightBody = {
"left": 19,
"top": yPos,
"width": 9,
"height": 0
};
this.popupTbl.leftBottom = {
"left": 0,
"top": yPos,
"width": 20,
"height": 21
};
this.popupTbl.leftBottomImg = {
"left": 0,
"top": -13,
"width": 20,
"height": 21
};
this.popupTbl.leftBottomFill = {
"left": 16,
"top": 0,
"width": 4,
"height": 6
};
this.popupTbl.rightBottom = {
"left": 19,
"top": yPos,
"width": 10,
"height": 7
};
this.popupTbl.rightBottomImg = {
"left": -125,
"top": -13,
"width": 10,
"height": 7
};
this.popupTbl.centerBottomFill = {
"left": 19,
"top": (yPos + (is_ie_ ? -1: 0)),
"width": 0,
"height": (6 + (is_ie_ ? 1: 0))
};
};
PopupMarker.prototype.onAdd = function() {
this.container_ = document.createElement("div");
this.iconContainer = document.createElement("div");
this.iconContainer.style.width = this.ICON_WIDTH + "px";
this.iconContainer.style.height = this.ICON_HEIGHT + "px";
this.iconContainer.innerHTML = "<img src='" + this.icon_ + "'>";
var panes = this.getPanes();
panes.floatShadow.appendChild(this.iconContainer);
this.iconContainer.style.position = "absolute";
panes.floatPane.appendChild(this.container_);
this.container_.style.position = "absolute";
if (!this.showpop) this.container_.style.visibility = "hidden";
this.makeNormalPopup_();
};
PopupMarker.prototype.draw = function() {
this.redrawNormalPopup_(this.text_);
};
PopupMarker.prototype.onRemove = function() {
this.container_.parentNode.removeChild(this.container_);
this.iconContainer.parentNode.removeChild(this.iconContainer);
};
PopupMarker.prototype.makeNormalPopup_ = function() {
this.leftTop_ = this.makeImgDiv_(this.popupImgSrc_, this.popupTbl.leftTop);
this.leftTop_.appendChild(this.fillDiv_(this.popupTbl.leftTopFill));
this.container_.appendChild(this.leftTop_);
this.leftBody_ = this.fillDiv_(this.popupTbl.leftBody);
this.leftBody_.style.borderWidth = "0 0 0 1px";
this.leftBody_.style.borderStyle = "none none none solid";
this.leftBody_.style.borderColor = "#000000";
this.container_.appendChild(this.leftBody_);
this.leftBottom_ = this.makeImgDiv_(this.popupImgSrc_, this.popupTbl.leftBottomImg);
this.leftBottom_.style.left = this.popupTbl.leftBottom.left + "px";
this.leftBottom_.style.top = this.popupTbl.leftBottom.top + "px";
this.leftBottom_.style.width = this.popupTbl.leftBottom.width + "px";
this.leftBottom_.style.height = this.popupTbl.leftBottom.height + "px";
this.leftBottom_.appendChild(this.fillDiv_(this.popupTbl.leftBottomFill));
this.container_.appendChild(this.leftBottom_);
this.bodyContainer_ = document.createElement("div");
this.bodyContainer_.style.position = "absolute";
this.bodyContainer_.style.backgroundColor = "#FFF";
this.bodyContainer_.style.overflow = "hidden";
this.bodyContainer_.style.left = this.popupTbl.centerBodyFill.left + "px";
this.bodyContainer_.style.top = this.popupTbl.centerBodyFill.top + "px";
this.bodyContainer_.style.width = this.popupTbl.centerBodyFill.width + "px";
this.bodyContainer_.style.height = this.popupTbl.centerBodyFill.height + "px";
this.container_.appendChild(this.bodyContainer_);
this.rightTop_ = this.makeImgDiv_(this.popupImgSrc_, this.popupTbl.rightTopImg);
this.rightTop_.style.left = this.popupTbl.rightTop.left + "px";
this.rightTop_.style.top = this.popupTbl.rightTop.top + "px";
this.rightTop_.style.width = this.popupTbl.rightTop.width + "px";
this.rightTop_.style.height = this.popupTbl.rightTop.height + "px";
this.container_.appendChild(this.rightTop_);
this.rightBottom_ = this.makeImgDiv_(this.popupImgSrc_, this.popupTbl.rightBottomImg);
this.rightBottom_.style.left = this.popupTbl.rightBottom.left + "px";
this.rightBottom_.style.top = this.popupTbl.rightBottom.top + "px";
this.rightBottom_.style.width = this.popupTbl.rightBottom.width + "px";
this.rightBottom_.style.height = this.popupTbl.rightBottom.height + "px";
this.container_.appendChild(this.rightBottom_);
this.rightBody_ = this.fillDiv_(this.popupTbl.rightBody);
this.rightBody_.style.borderWidth = "0 1px 0 0";
this.rightBody_.style.borderStyle = "none solid none none";
this.rightBody_.style.borderColor = "#000000";
this.container_.appendChild(this.rightBody_);
this.centerBottom_ = this.fillDiv_(this.popupTbl.centerBottomFill);
this.centerBottom_.style.borderWidth = "0 0 1px 0";
this.centerBottom_.style.borderStyle = "none none solid none";
this.centerBottom_.style.borderColor = "#000000";
this.container_.appendChild(this.centerBottom_);
this.centerTop_ = this.fillDiv_(this.popupTbl.centerTopFill);
this.centerTop_.style.borderColor = "#000000";
this.centerTop_.style.borderWidth = "1px 0 0 0";
this.centerTop_.style.borderStyle = "solid none none none";
this.container_.appendChild(this.centerTop_);
};
PopupMarker.prototype.redrawNormalPopup_ = function(text) {
if (this.beforeNormalPopupText_ !== text) {
try {
while (this.bodyContainer_.firstChild) {
this.bodyContainer_.removeChild(this.bodyContainer_.firstChild);
}
} catch(e) {}
this.bodyContainer_.innerHTML = text;
if (this.isIE_() === false && this.bodyContainer_.hasChildNodes) {
if (this.bodyContainer_.firstChild.nodeType === 1) {
this.bodyContainer_.firstChild.style.margin = 0;
}
}
var offsetBorder = this.isIE_() ? 2: 0;
var cSize = this.getHtmlSize_(text);
var rightX = this.popupTbl.leftTop.width + cSize.width;
this.leftBottom_.style.top = (cSize.height + this.popupTbl.leftBody.top) + "px";
this.leftBody_.style.height = cSize.height + "px";
this.bodyContainer_.style.width = cSize.width + "px";
this.bodyContainer_.style.height = cSize.height + "px";
this.bodyContainer_.style.top = this.popupTbl.leftBody.top;
this.rightTop_.style.left = rightX + "px";
this.rightBottom_.style.left = this.rightTop_.style.left;
this.rightBottom_.style.top = this.leftBottom_.style.top;
this.rightBody_.style.left = rightX + "px";
this.rightBody_.style.height = this.leftBody_.style.height;
this.centerBottom_.style.top = this.leftBottom_.style.top;
this.centerBottom_.style.width = cSize.width + "px";
this.centerTop_.style.width = cSize.width + "px";
this.size_ = {
"width": (rightX + this.popupTbl.rightTop.width),
"height": (cSize.height + this.popupTbl.leftTop.height + this.popupTbl.leftBottom.height)
};
this.container_.style.width = this.size_.width + "px";
this.container_.style.height = this.size_.height + "px";
}
this.setPosition(this.latlng_);
this.beforeNormalPopupText_ = text;
};
PopupMarker.prototype.setPosition = function(latlng) {
var pxPos = this.getProjection().fromLatLngToDivPixel(latlng);
this.container_.style.left = pxPos.x + "px";
this.container_.style.top = (pxPos.y - this.size_.height) + "px";
this.iconContainer.style.left = (pxPos.x - this.ICON_WIDTH / 2) + "px";
this.iconContainer.style.top = (pxPos.y - this.ICON_HEIGHT) + "px";
};
PopupMarker.prototype.isNull = function(value) {
if (!value && value !== 0 || value === undefined || value === "" || value === null || typeof value === "undefined") {
return true;
}
return false;
};
PopupMarker.prototype.getHtmlSize_ = function(html) {
var mapContainer = this.map_.getDiv();
var onlineHTMLsize_ = function(text) {
var dummyTextNode = document.createElement("span");
dummyTextNode.innerHTML = text;
dummyTextNode.style.display = "inline";
mapContainer.appendChild(dummyTextNode);
var size = {};
size.width = dummyTextNode.offsetWidth;
size.height = dummyTextNode.offsetHeight;
mapContainer.removeChild(dummyTextNode);
return size;
};
var ret;
var lines = html.split(/\n/i);
var totalSize = new google.maps.Size(1, 1);
for (var i = 0; i < lines.length; i++) {
ret = onlineHTMLsize_(lines[i]);
totalSize.width += ret.width;
totalSize.height += ret.height;
}
return totalSize;
};
PopupMarker.prototype.makeImgDiv_ = function(imgSrc, params) {
var imgDiv = document.createElement("div");
imgDiv.style.position = "absolute";
imgDiv.style.overflow = "hidden";
if (params.width) {
imgDiv.style.width = params.width + "px";
}
if (params.height) {
imgDiv.style.height = params.height + "px";
}
var img = null;
if (this.isIE_() === false) {
img = new Image();
img.src = imgSrc;
} else {
img = document.createElement("div");
if (params.width) {
img.style.width = params.width + "px";
}
if (params.height) {
img.style.height = params.height + "px";
}
}
img.style.position = "relative";
img.style.left = params.left + "px";
img.style.top = params.top + "px";
img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imgSrc + "')";
imgDiv.appendChild(img);
return imgDiv;
};
PopupMarker.prototype.fillDiv_ = function(params) {
var bgDiv = document.createElement("div");
bgDiv.style.position = "absolute";
bgDiv.style.backgroundColor = "#FFF";
bgDiv.style.fontSize = "1px";
bgDiv.style.lineHeight = "1px";
bgDiv.style.overflow = "hidden";
bgDiv.style.left = params.left + "px";
bgDiv.style.top = params.top + "px";
bgDiv.style.width = params.width + "px";
bgDiv.style.height = params.height + "px";
return bgDiv;
};
PopupMarker.prototype.isIE_ = function() {
return (navigator.userAgent.toLowerCase().indexOf('msie') !== -1) ? true: false;
};
PopupMarker.prototype.hide = function() {
if (this.container_) {
this.container_.style.visibility = "hidden";
}
};
PopupMarker.prototype.show = function() {
if (this.container_) {
this.container_.style.visibility = "visible";
}
};
PopupMarker.prototype.toggle = function() {
if (this.container_) {
if (this.container_.style.visibility == "hidden") {
this.show();
} else {
this.hide();
}
}
};
PopupMarker.prototype.update = function(obj) {
if ((typeof obj.icon) != "undefined") {
this.iconContainer.innerHTML = "<img src='" + obj.icon + "'>";
}
if ((typeof obj.position) != "undefined") {
this.latlng_ = obj.position;
this.setPosition(this.latlng_);
}
if ((typeof obj.text) != "undefined") {
this.text_ = obj.text;
this.redrawNormalPopup_(obj.text);
}
};
PopupMarker.prototype.setZIndex = function(index) {
this.container_.style.zIndex = index;
this.iconContainer.style.zIndex = index;
};
PopupMarker.prototype.latlng = function() {
return this.latlng_;
}
PopupMarker.prototype.hideMarker = function(){
this.container_.style.visibility = "hidden";
this.iconContainer.style.visibility = "hidden";
};
PopupMarker.prototype.showMarker = function(){
this.container_.style.visibility = "visible";
this.iconContainer.style.visibility = "visible";
};
//效果见http://www.gpsoo.net 或者 http://www.goocar.net
分享到:
相关推荐
谷歌地图 Google Map API V3 中文开发文档是 Google 公司提供的一种基于 Web 的地图应用程序接口,允许开发者在自己的网站或应用程序中嵌入谷歌地图,以提供地图检索、路线规划、地标显示等功能。本文档旨在为开发者...
谷歌地图API V3是Google提供的一种用于在网页上嵌入交互式地图的服务,它基于JavaScript编程语言,允许开发者创建各种地图应用。这个源码可能是谷歌地图API V3的一个示例项目,不含任何特定的API密钥,因此可以作为...
Google Map API V3(3.9.12)是谷歌提供的一个用于在网页上嵌入交互式地图的服务,它是Google Maps JavaScript API的第三个主要版本。这个离线开发包允许开发者在没有网络连接的情况下进行地图应用的开发和测试,这...
《基于GoogleMap API的GPS终端和用户管理系统》 在当今数字化时代,GPS定位技术与地图API的结合在交通管理、物流调度、车辆监控等领域发挥着重要作用。本系统——基于GoogleMap API的GPS终端和用户管理系统,就是...
本文将详细解析如何利用Google Map API实现"基于Google Map API的简单地图"的功能,包括显示用户所在地区、地图操作以及标记地点等核心知识点。 首先,我们要了解Google Map API的基本用法。它是Google提供的...
JavaScript调用Google Map API V3是一项常见的Web开发任务,它允许开发者在网页中嵌入交互式地图,并根据需求进行自定义。以下是对这个经典教程的详细解析: 1. **目标** - 整个教程旨在教会读者如何利用...
在 Google Maps API V3 中,Map 是地图的核心组件,提供了多种配置选项和事件监听器。开发者可以使用 MapOptions 对象来配置地图的基本属性,如中心点、缩放级别、地图类型等。同时,MapTypeId 对象提供了多种地图...
### 谷歌地图API V3 - 详细知识点解析 #### 概述 谷歌地图API V3(Google Maps API V3)是谷歌提供的一套强大的工具和服务集合,旨在帮助开发者在网页上集成交互式地图。它支持多种功能,如自定义地图样式、添加...
最新版的Google Map API是V3,它是一个基于JavaScript的API,具有高度可定制性和灵活性。 在Google Map API V3中,开发者可以实现以下主要功能: 1. **地图嵌入**:通过简单的HTML和JavaScript代码,可以在网页上...
通过这个"google Map api v3学习例子",你可以逐步掌握如何利用Google Maps API V3构建交互式地图应用,包括添加标记、处理事件、展示叠加层等功能。实践中不断探索,你会发现Google Maps API V3的强大和灵活性,能...
这个类通常基于谷歌地图API的`MVCObject`基类构建,`MVCObject`提供了属性管理和事件处理的基本框架。`ExtDraggableObject`扩展了这一基础,添加了拖拽功能。当创建一个可拖动对象时,你需要指定它的初始位置,然后...
Google Map API是一个强大的工具,允许开发者在网页或应用程序中集成地图功能,进行各种定制和交互。这个源代码压缩包提供了一种实现Google Map API二次开发的实例,对于想要深入理解和应用这一技术的人来说非常有...
Google Map API 是一款强大的工具,它允许开发者在自己的网站或应用程序中嵌入地图功能,提供定位、导航、地理编码、路线规划等多种服务。本示例将深入探讨如何使用 Google Map API,帮助你理解和掌握其核心概念及...
基于Google Map API的Android导航应用,是以Google地图API为依托开发的Android平台的导航软件,它实现了为用户提供更加人性化的路线规划和实时导航服务。如今,智能手机逐渐成为人们生活中不可或缺的一部分,特别是...
在IT行业中,Google Map API 和 ASP.NET(C#)的结合应用是构建地理位置服务的重要技术组合。Google Map API 提供了丰富的地图展示和地理定位功能,而ASP.NET(C#)则是一个强大的Web应用程序开发框架,两者结合可以创建...
google map api 实现自定义mark和其移动
在本实例中,我们主要探讨如何使用GoogleMap API进行二次开发,并结合Asp.Net、数据库以及GPS技术,创建一个功能丰富的Web应用。首先,我们来深入理解这些关键知识点。 1. GoogleMap API: GoogleMap API是Google...
google map api 参考文档google map api 参考文档google map api 参考文档google map api 参考文档google map api 参考文档google map api 参考文档
基于Google Map Api的Android导航应用是一种利用谷歌地图API在Android平台上构建的智能导航软件。它结合了GPS定位、网络连接和用户界面设计,为用户提供高效、便捷的导航服务。以下是对这一主题的详细阐述: 首先,...
Google Maps API V3 是谷歌为开发者提供的一个强大工具,用于在网站或应用程序中集成交互式地图功能。这个API允许开发人员自定义地图显示的内容、样式以及交互方式,从而构建出各种基于地理位置的应用。在Google ...