文档链接用于扩展谷歌地图JS v3标记类

时间:2012-03-04 20:15:31

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

我正在寻找有关如何扩展谷歌地图类(如google.maps.Marker)的文档链接。我确实在http://www.googlemapsbook.com/2007/01/22/extending-gmarker/找到了一个非常有用的链接。然而,这是api v2,我正在使用api V3。我还查看了google的文档以扩展OverlayTypes(http://code.google.com/apis/maps/documentation/javascript/overlays.html#CustomOverlays)但是,这不适用于作为MvcObject的Marker。我也阅读并理解,对于大多数实际要求,我们不需要扩展Marker类。它有一个非常有用的界面,几乎可以用来做你需要的一切。但是,我的应用程序现在变得越来越复杂,我希望将自定义功能封装在一个扩展Google标记的自定义标记类中。这甚至可能还是我在做梦?

谢谢大家!

2 个答案:

答案 0 :(得分:2)

是的,我同意这些陈述:'你不需要特殊的界面来扩展对象' 如果您想为您的案例添加“google.maps.Marker”中的某些属性,请使用以下方法:

marker.set("property", New_Value);

可能会有所帮助。您也可以使用:

marker.get("propertu");

获得目标价值。

答案 1 :(得分:1)

google.maps.Marker是一个对象。 您不需要特殊的界面来扩展对象,您可以扩展google.maps.Marker的原型。

样品:

  //applies a onclick-listener to a marker where the marker will be removed
  google.maps.Marker.prototype.removeOnClick=function()
                  {
                    google.maps.event.clearListeners(this,'click');
                    google.maps.event.addListener(this, 'click', 
                            function() {
                                          alert('bye');
                                          this.setMap(null);
                                       });
                  };

http://jsfiddle.net/doktormolle/KgTF5/