5
加入傳單到我的AngularJS應用後:AngularJS傳單的GetMap()不工作
<leaflet id="map" defaults="defaults" center="center" bounds="bounds" controls="controls" event-broadcast="events"></leaflet>
並設置它:
// Initialise the feature group to store editable layers
var drawnItems = new L.FeatureGroup();
// Initialise the draw control
var drawControl = new L.Control.Draw({
position: 'topright',
edit: {
featureGroup: drawnItems
}
});
// Configure Leaflet
angular.extend($scope, {
defaults: {
zoomControlPosition: 'topright',
minZoom: 3,
tileLayerOptions: {
detectRetina: true,
reuseTiles: true,
attribution: '<a href="http://osm.org">OpenStreetMaps</a>'
}
},
center: {},
controls: {
custom: [drawControl]
},
events: {
map: {
enable: ['click']
}
}
});
在此之後的代碼不會得到評估(無錯誤顯示雖然):
leafletData.getMap().then(
function (map) {
alert('I have accessed the map.');
}
);
這應該馬上告訴我一個警報,雖然沒有任何反應。
如果我延遲這個以前的代碼,例如,在一個按鈕上單擊一個函數運行它,它就可以工作!
有誰知道可能是什麼問題?
部分解決
從leaflet
HTML標籤刪除ID解決了這個問題。必須是一個錯誤。
我有同樣的問題。你有報告嗎? – schmijos
是的,我在幾個月前 - 沒有采取任何行動。 – Julius
您應該通過標記的ID來獲取像這樣的Map()函數:leafletData.getMap('theMap')。then(... –
Dojo