你很幸運,我們剛剛解決了我們的問題。假設模板圖被稱爲模內:
Template.map.rendered = function() {
Tracker.autorun(function() {
Session.set('map_available', true);
var center = {
latitude: -1.8445
longitude: 52.9445
}; // end var center
var zoomLevel = 15;
if(Session.equals('map_available', true)) {
GoogleMaps.init({'sensor': true, 'key' : 'OPTIONAL_KEY' },
function() {
var mapOptions = {
zoom: zoomLevel,
minZoom: 15,
maxZoom: 20,
mapTypeId: google.maps.MapTypeId.ROADMAP,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
};
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
map.setCenter(new google.maps.LatLng(center.latitude, center.longitude));
} // end closure param 2 of GoogleMaps init
}); // end GoogleMaps.init
} // end Session.equals 'map_available'
} //end Tracker.autorun
} // end Template.map.rendered
Template.map.destroyed = function() {
Session.set('map_available', false);
}
所以這裏的策略是監視依賴獨立跟蹤,並確保任何DOM反應後它就會被重新添加。這裏的獎勵功能是,如果您在Tracker.autorun
(例如var center = navigator.location
)中包含var center
修改,那麼您在移動時會有一個更改中心的地圖(lat
,long
已更改)。
也,我們使用擴展mrt:googlemaps
爲GoogleMaps
集成。似乎是最好的使用。
你有複製? – stubailo 2014-10-28 23:47:05