Backbone.js를 사용하여 전단지를 초기화 할 때 더 이상이 정확한지도에 액세스 할 수 없습니다.Backbone.js가있는 전단지 맵에 액세스 할 수 없습니다.
예 :
mapView.map.locate({setView: true, maxZoom: 10});
가 발생합니다지도는 같은 대시 보드보기에서 별도의보기를 통해 초기화
TypeError: 'undefined' is not a function (evaluating 'mapView.map.locate({setView: true, maxZoom: 10})')
에 :
을 :this.mapView = new MapView();
$(this.$el).find('.content').append(this.mapView.el).find('.map').addClass('full').css({
'height': $(window).height()/2
});
이보기처럼 보인다
var MapView = Backbone.View.extend({
template: _.template(""),
render: function()
{
this.$el.html(this.template());
this.map = L.map(this.el).setView([48.00786, 13.17989], 8);
this.map = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'OpenStreetMap © Mitwirkende der <a href="http://osm.org/copyright">OpenStreetMap</a>'
}).addTo(this.map);
return this;
}
});
지도 객체에 console.log를 통해 액세스 할 수 있습니다. 결과는 다음과 같습니다.
_animated: true _bgBuffer: HTMLDivElement _clearBgBufferTimer: 4 _container: HTMLDivElement _initHooksCalled: true _leaflet_events: Object _leaflet_id: 20 _limitedUpdate: function s() {var a=arguments;return n?(o=!0,void 0):(n=!0,setTimeout(function(){n=!1,o&&(s.apply(i,a),o=!1)},e),t.apply(i,a),void 0);} _map: Object _tileContainer: HTMLDivElement _tileImg: HTMLImageElement _tiles: Object _tilesToLoad: 0 _url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" options: Object proto: Object
그런데 왜이지도에 액세스 할 수 없습니까?
감사합니다.
'mapView.map.locate'는 뷰 중 하나에'mapView' 속성 만있을 때'mapView' 변수를 찾을 것을 제안합니다. 그리고'$ (this. $ el)'를 사용하지 말고'this. $ el' 만 사용하십시오; ['this. $'] (http://backbonejs.org/#View-dollar)는'this. $ el.find'와 같습니다. –
감사합니다;) 귀하의 요점을 볼 수 있지만 mapView 및 mapView 두 (잘, 나쁘게 명명 된,하지만 어쨌든) 변수가 있습니다. MapView 자체에 속성 (MapView를 렌더해야하는 라우터)의 mapView가 있습니다. var mapView는 var처럼 초기화됩니다. mapView = view.mapView.render(); - 죄송합니다... – Severin