1

我读了:

将 Google 地图自定义叠加层与主干视图混合

并尝试实现和玩弄它,因为我需要使用自定义叠加层作为视图,并且我已经使用了主干.js

var Label = function(){
        Backbone.View.apply(this, arguments);
        this.newInit();
    };

    Label.extend = Backbone.View.extend;

    _.extend(Label.prototype, Backbone.View.prototype, google.maps.OverlayView.prototype,{
        newInit: function(){
         this.setMap(this.options.map);
        },
        onAdd: function(){...},
        onRemove: function(){...},
        draw: function(){...}
    });

    var label_view = new LabelView({map: map});
    label_view.bindTo('some_event', {name: 'some_event_occured'});

从我的测试来看,“draw”方法没有被调用,尽管它应该覆盖它。我究竟做错了什么?

4

1 回答 1

0

找到了解决方案:

var Label = function(){
        Backbone.View.apply(this, arguments);
        google.maps.OverlayView.apply(this, arguments);
    };

而不是

newInit: function(){

利用:

initialize: function(options){

希望这可以帮助

于 2012-08-26T17:59:05.913 回答