dqdz6464 2013-01-09 08:01
浏览 53
已采纳

Gmap信息框弹出窗口

Hi i have an web app where i integrate gmap on it which will look similar to Yelp gmap services. The issues is that when i mouseover the marker the infobox stuck within the box as follow:

enter image description here

the infobox suppose to look like this

enter image description here

Below are my current code for integrate gmap

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox_packed.js"></script>

<script type="text/javascript">

    var gmap, gpoints = [];

    $(document).ready(function() {
        initialize();
    });

function initialize() {

        gmap = new google.maps.Map(document.getElementById('themap'), {
            zoom:               8,
            streetViewControl:  false,
            scaleControl:       false,
            center:             new google.maps.LatLng(3.3000000,101.9629796),
            mapTypeId:          google.maps.MapTypeId.ROADMAP
        });
 <?php
$content = '<p>Test</p>'; 
?>
 gpoints.push( new point(gmap, '<?php echo $lat; ?>', '<?php echo $long; ?>', '<?php echo $content; ?>') );
}

 function point(_map, lat, lng, content) {
        this.marker = new google.maps.Marker({
            position:           new google.maps.LatLng(lat,lng),
            map:                _map,
            zIndex: 11
        });
this.content = content;



        var gpoint = this;


        google.maps.event.addListener(gpoint.marker, 'mouseover', function() {
            popup(gpoint);
        });

google.maps.event.addListener(_map, 'zoom_changed', function() {
            center=gpoint.marker.getPosition();
            lat=center.lat();
            lng=center.lng();
           // alert(lat+"===="+lng);
        });    
}

 function popup(_point) {
        _point.popup = new InfoBox({
            content: _point.content,
            position:  _point.marker.getPosition(),
           // shadowStyle: 1,
            padding: 20,
            //backgroundColor: '#ddd',
            borderRadius: 10,
            arrowSize: 10,
            borderWidth: 1,
           // borderColor: '#dddddd',
            disableAutoPan: true,
            arrowPosition: 30,
           // backgroundClassName: 'phoney',
            arrowStyle: 2


        });

_point.popup.open(_point.marker.map, _point.marker);

        google.maps.event.addListener(_point.popup, 'domready', function() {                    
            google.maps.event.addDomListener(_point.marker, 'mouseout', function() {
                _point.popup.close();
            });
        });

}

</script>
  • 写回答

1条回答 默认 最新

  • dongzhilian0188 2013-01-09 12:22
    关注

    You may use the option pixelOffset of the infoBox to control the position related to the marker.

    The default is 0,0 , which means that the top left corner of the infoBox sticks on the position(of the marker).

    To place it top+center, you must explicitly assign to the content of the infobox, and apply a pixelOffset as follows:

    pixelOffset:new google.maps.Size(-halfOfWidthOfTheBox,0)
    

    When you don't know the size of the infoBox you may calculate it. Add this to the domready-callback of _point.popup:

    this.setOptions({pixelOffset:new google.maps
                                 .Size(-parseInt(this.div_.offsetWidth/2,10),0)});
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用