我在以下呈现谷歌街景的主干视图中遇到问题。
问题是在 processSVData 函数中,this
不是App.DetailStreetView
. 当我console.log(this)
进去时processSVData()
,我得到了DOMWindow
对象。因此,当尝试访问时,this.panorama
我得到undefined
App.DetailStreetView = Backbone.View.extend({
initialize: function() {
this.latLng = new google.maps.LatLng(37.869085,-122.254775);
this.panorama = new google.maps.StreetViewPanorama(this.el);
},
render: function() {
var sv = new google.maps.StreetViewService();
sv.getPanoramaByLocation(this.latLng, 50, this.processSVData);
},
processSVData: function(data, status) {
if (status == google.maps.StreetViewStatus.OK) {
// calculate correct heading for POV
//var heading = google.maps.geometry.spherical.computeHeading(data.location.latLng, this.latLng);
this.panorama.setPano(data.location.pano);
this.panorama.setPov({
heading: 270,
pitch:0,
zoom:1,
});
this.panorama.setVisible(true);
}
},
});