【问题标题】:Google maps hide marker (and info) and only show when you click on an area that has info谷歌地图隐藏标记(和信息),仅在您点击有信息的区域时显示
【发布时间】:2010-12-16 12:40:18
【问题描述】:

我想在谷歌地图中添加一个透明的 png,而不是使用默认图标。在我的示例代码中,我会将默认图标更改为名为 transparent.png 的 png?

谢谢!

 function onLoad() {
      map = new GMap(document.getElementById("div_map"));
      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng(54, -3), 5);

      getMarkers();

      GEvent.addListener(map, "click", function(overlay, point) {
          if (overlay){ // marker clicked
              overlay.openInfoWindowHtml(overlay.infowindow);   // open InfoWindow
          } else if (point) {   // background clicked

          }
      });
    }

    function getMarkers(){
        var urlstr="read.php";
        var request = GXmlHttp.create();
        request.open('GET', urlstr , true); // request XML from PHP with AJAX call
        request.onreadystatechange = function () {
            if (request.readyState == 4) {
                var xmlDoc = request.responseXML;
                locations = xmlDoc.documentElement.getElementsByTagName("location");
                markers = [];
                if (locations.length){
                    for (var i = 0; i < locations.length; i++) { // cycle thru locations
                        markers[i] = new GMarker(new GLatLng(locations[i].getAttribute("lat"),locations[i].getAttribute("lng")));
                        // Add attributes to the marker so we can poll them later.
                        // When clicked, an overlay will have these properties.
                        markers[i].infowindow = "This is "+locations[i].getAttribute("name");

                        // Useful things to store on a marker (Not needed for this example, could be removed)
                        // Tells you what index in the markers[] array an overlay is
                        markers[i].markerindex = i;
                        // Store the location_id of the location the marker represents.
                        // Very useful to know the true id of a marker, you could then make
                        // AJAX calls to the database to update the information if you had it's location_id
                        markers[i].db_id = locations[i].getAttribute("location_id");

                        map.addOverlay(markers[i]);

                    }
                }
            }
        }
        request.send(null);
    }

【问题讨论】:

    标签: php javascript database google-maps


    【解决方案1】:

    您可以在普通 GIcon.image 中使用几乎不可见的 PNG 文件作为标记,您只需要注意某些不是 100% 透明的内容可用作点击目标。这可能是 GIcon.image 或 GIcon.transparent。某些浏览器不处理对 100% 透明对象的点击。

    这种方法的一个问题是可点击区域会随着缩放级别的变化而变化。另一种方法是绘制不可见的可点击多边形来标记有信息的区域。在这种情况下,多边形可以 100% 透明,因为 API 不依赖于浏览器检测多边形是否被点击。

    【讨论】:

      【解决方案2】:

      所以您根本不希望标记显示?只需通过启动弹出窗口做出反应?我会用自定义清除 png 交换图标。

      http://code.google.com/apis/maps/documentation/reference.html#GIcon

      【讨论】:

        猜你喜欢
        • 2019-12-11
        • 1970-01-01
        • 2019-05-17
        • 2014-10-15
        • 1970-01-01
        • 1970-01-01
        • 2015-01-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多