嗨,我正在使用ngMap来显示谷歌地图组件。
现在,以一个非常基本的例子为例,我正在使用Bootstrap,并尝试将谷歌地图放在屏幕的一半上,因此我给它col-lg-6。
但是显然我总是得到相同的高度,即300px。我想让谷歌地图组件的高度为100%而不是固定的高度(这根本不是响应式的)。以下是我所说的代码:
这里是问题的plunker:http://plnkr.co/edit/BQgMe5EQiFBmojgx45t5?p=preview
var app=angular.module('myapp', ['ngMap']);
app.controller('EventSimpleCtrl', ['$scope', '$timeout', function($scope, $timeout) {
var marker, map;
$scope.$on('mapInitialized', function(evt, evtMap) {
map = evtMap;
marker = map.markers[0];
});
$scope.centerChanged = function(event) {
$timeout(function() {
map.panTo(marker.getPosition());
}, 3000);
}
$scope.click = function(event) {
map.setZoom(8);
map.setCenter(marker.getPosition());
}
}]);
.map .panel-body {
padding: 0;
}
<html ng-app="myapp">
<head>
<link data-require="bootstrap@3.3.2" data-semver="3.3.2" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script data-require="bootstrap@3.3.2" data-semver="3.3.2" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script data-require="jquery@2.1.3" data-semver="2.1.3" src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3"></script>
<script src="http://code.angularjs.org/1.2.25/angular.js"></script>
<script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>
<script src="script.js"></script>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div ng-controller="EventSimpleCtrl" class="ng-scope">
<div class="row">
<div class="col-lg-6">
<!--<div class="panel panel-primary map">-->
<!-- <div class="panel-heading">Test</div>-->
<!-- <div class="panel-body">-->
<!-- <map zoom="4" center="-25.363882, 131.044922" on-center-changed="centerChanged()">-->
<!-- <marker position="-25.363882, 131.044922" on-click="click()" title="Click to zoom"></marker>-->
<!-- </map>-->
<!-- </div>-->
<!--</div>-->
</div>
<div class="col-lg-6">
<map zoom="4" center="-25.363882, 131.044922" on-center-changed="centerChanged()">
<marker position="-25.363882, 131.044922" on-click="click()" title="Click to zoom"></marker>
</map>
</div>
</div>
</div>
</body>
</html>