首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >什么是谷歌地图V3中的openInfoWindowHtml和GPolygon

什么是谷歌地图V3中的openInfoWindowHtml和GPolygon
EN

Stack Overflow用户
提问于 2010-07-17 03:13:06
回答 2查看 18.4K关注 0票数 4
代码语言:javascript
运行
复制
   var polygon = new GPolygon(polylines[0],"#FFFFFF", 1, 1.0, color,opacity);

  polygon.hid = this.id;
  polygon.heat = this.heat;

   google.maps.event.addListener(polygon, 'click', function(point) {

    HoodsUnselect(active_hood_id);
    active_hood_id = polygon.hid;
polygon.setOptions({fillColor: '#2948e4', fillOpacity: 0.50 });
  //polygon.setFillStyle( { color:'#2948e4',opacity:'0.50' } );

    if (point) {
      map.openInfoWindowHtml(point, the_list);  // open info window where user clicked

    } else {
       map.openInfoWindowHtml(polygon.getBounds().getCenter(), the_list);  // open info window at the center of polygon
    }
  });
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-07-17 03:39:44

除了Tony's answer之外,v3接口中没有openInfoWindowHtml()方法。您必须创建一个InfoWindow对象,在该对象上可以调用open()close()方法。如果你想一次只看到一个InfoWindow对象,你通常只想要一个:

代码语言:javascript
运行
复制
var infoWindow = new google.maps.InfoWindow();

google.maps.event.addListener(yourOverlay, 'click', function () {
   infoWindow.setContent('Some info on yourOverlay');
   infoWindow.open(map);
});

当涉及到Info窗口时,Info API和v3 API之间的主要区别在于,在v3 API中,您可以同时打开多个Info窗口。这在v2应用编程接口中是不可能的。要打开多个信息窗口,您需要创建多个InfoWindow对象,而不仅仅是为所有标记(覆盖)创建一个对象。

对于多边形,这是如何在v3接口(借用示例mentioned by @Tony)中创建多边形:

代码语言:javascript
运行
复制
var bermudaTriangle = new google.maps.Polygon({
  paths: [
    new google.maps.LatLng(25.774252, -80.190262),
    new google.maps.LatLng(18.466465, -66.118292),
    new google.maps.LatLng(32.321384, -64.75737)
  ],
  strokeColor: "#FF0000",
  strokeOpacity: 0.8,
  strokeWeight: 3,
  fillColor: "#FF0000",
  fillOpacity: 0.35
});

bermudaTriangle.setMap(map);
票数 15
EN

Stack Overflow用户

发布于 2010-07-17 03:32:25

GPolyline的v3等效项是Polyline,GPolygon是Polygon。这两个都有你可以监听的点击事件。

更好的是,谷歌提供了Polyline examplesPolygon examples,包括one that listens for clicks and opens an infowindow

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3268099

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档