我創建了一個指令,增加了折角材料flex
屬性在編譯的leaflet
指令。這使容器寬度達到100%。然後從地圖對象完成渲染時調用的Leaflet獲得承諾。調用方法map::invalidateSize()
將強制Leaflet檢查在父容器的此點正確設置的大小。
(function() {
angular.module('live')
.directive('ttLeafletFlexFit', leafletFlexFit);
leafletFlexFit.$inject = ['$timeout', 'leafletData'];
function leafletFlexFit($timeout, leafletData) {
var directive = {
restrict: 'A',
compile: compile
};
return directive;
function compile(tElem, attrs) {
tElem.attr('flex', '');
// A hack to get Leaflet to fill the flex container.
// @link https://github.com/tombatossals/angular-leaflet-directive/issues/950
leafletData.getMap().then(function (map) {
$timeout(function() {map.invalidateSize()});
});
}
}
})();
然後在leaflet指令元素上添加一個屬性。
<leaflet tt-leaflet-flex-fit></leaflet>
我花了一段時間才弄清楚flex和Angular Material是我的問題,但沒有時間去實現您的修復。謝謝! –