我有一个带有Google Maps mashup的页面,其中有按天(星期一、星期二等)进行颜色编码的图钉。包含地图的IFrame是动态调整大小的,因此当调整浏览器窗口的大小时,它的大小也会随之调整。
我想在地图窗口的角落里放一个图例,告诉用户每种颜色的含义。Google Maps API包括一个GScreenOverlay类,该类具有我想要的行为,但它只允许您指定要用作覆盖的图像,并且我更喜欢使用其中包含文本的DIV。将DIV放置在地图窗口上的最简单方法是什么?例如,当浏览器窗口调整大小时,地图窗口的左下角将自动停留在与该角相同的位置?
发布于 2008-09-03 23:06:30
您可以添加自己的自定义控件并将其用作图例。
此代码将添加一个150w x 100h (灰色边框/白色背景)和"Hello World“字样的方框。您可以将文本替换为图例中想要的任何HTML。这将保持锚定在地图的右上角(G_ANCHOR_TOP_RIGHT) 10px下方和50px上方。
function MyPane() {}
MyPane.prototype = new GControl;
MyPane.prototype.initialize = function(map) {
var me = this;
me.panel = document.createElement("div");
me.panel.style.width = "150px";
me.panel.style.height = "100px";
me.panel.style.border = "1px solid gray";
me.panel.style.background = "white";
me.panel.innerHTML = "Hello World!";
map.getContainer().appendChild(me.panel);
return me.panel;
};
MyPane.prototype.getDefaultPosition = function() {
return new GControlPosition(
G_ANCHOR_TOP_RIGHT, new GSize(10, 50));
//Should be _ and not _
};
MyPane.prototype.getPanel = function() {
return me.panel;
}
map.addControl(new MyPane());发布于 2008-08-31 12:25:02
我会像下面这样使用HTML:
<div id="wrapper">
<div id="map" style="width:400px;height:400px;"></div>
<div id="legend"> ... marker descriptions in here ... </div>
</div>然后,您可以设置此样式以使图例保持在右下角:
div#wrapper { position: relative; }
div#legend { position: absolute; bottom: 0px; right: 0px; }position: relative将导致任何包含的元素相对于#wrapper容器进行定位,而position: absolute将导致#legend div从流中“拉出”并位于地图之上,使其右下边缘保持在#wrapper的底部,并根据需要进行拉伸以包含标记描述。
https://stackoverflow.com/questions/36515
复制相似问题