谷歌地图V3信息框 - 扩展地图边框?

时间:2013-02-17 00:13:01

标签: javascript google-maps google-maps-api-3 bing-maps

我正在开发一个wordpress plugin,在地图上显示一些照片。详细信息显示在信息框/信息窗口中。

这适用于bing map 6.3,信息框会占用地图的边框。

示例:http://www.denktfrei.de/?p=805

现在我不想添加对Google地图3和Bing地图7的支持。两种API都不支持此类信息框,信息框/信息窗不能大于地图。 我怎么能设法创建这样的信息框呢?

1 个答案:

答案 0 :(得分:1)

如评论中所述,我建议使用从地图控件本身添加到DOM的自定义信息框。这样您就不会受限于地图控件的DIV容器。

请参阅下面的代码示例:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script type="text/javascript" charset="UTF-8" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0">
    </script>
    <script type="text/javascript">
        var map = null;

        function getMap() {

            map = new Microsoft.Maps.Map(
                document.getElementById('myMap'), 
                { 
                    credentials: 'YOURKEY', 
                    showCopyright: false
                });

            // Create the pushpin
            var pushpin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(47.5, 2.75));

            // Add the pushpin to the map
            map.entities.push(pushpin);

            // Bind the click event on the pushpin
            Microsoft.Maps.Events.addHandler(pushpin, 'click', function(e) {
                if (e.targetType == 'pushpin') {
                    var box = document.getElementById('infobox');
                    box.style.top = e.pageY + 'px';
                    box.style.left = e.pageX + 'px';
                    box.style.visibility = 'visible';
                }
            });
        }

    </script>
</head>
<body onload="getMap();">
    <div id="container" style="position:relative;"></div>
    <div id="myMap" style="position: absolute;z-index:1; width: 800px; height: 600px;">
    </div>
    <div id="infobox" style="float:left;z-index:2; visibility:hidden;position:absolute; width:500px; height: 300px; background-color:White; border: 1px solid #333;">Sample content for an infobox which should be larger than the map control.</div>
</body>
</html>