I'm working on a mapping app using Ionic-Cordova-Angular and am trying to use Leaflet. My issue is that I can't get the Leaflet map to automatically fill the entire viewport.
I found the solution when using straight JS. You can use CSS to set the HTML and Body to a height of 100% and then set the map div to 100% as well. You can see this working in this JSFiddle: https://jsfiddle.net/wzfLs10a/
Unfortunately, the same solution does not work when I introduce Angular into the mix. Here's some sample code:
Index.html
<div id="map" ng-app="demoapp" ng-controller="MainCtrl"></div>
App.js
angular.module("demoapp", ["controllers"]);
angular.module('controllers',[])
.controller('MainCtrl',['$scope',
function($scope) {
$scope.map = L.map('map').setView([37.8, -96], 4);
L.tileLayer('http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpeg', {
attribution: 'Tiles Courtesy of <a href="http://www.mapquest.com/">MapQuest</a> — Map data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
subdomains: '1234'
}).addTo($scope.map);
}]);
Style.css
html, body { height: 100%; width: 100%;}
#map { height: 100%;}
Here's a JSFiddle: https://jsfiddle.net/3sv374Lz/. Note that if you change the height of the map div to a fixed value (400px for example), the map will display.
I am aware of the angular leaflet directive and am currently exploring that option as well, but it seems to me this really shouldn't be that difficult. Am I missing something simple? Thanks for the help!