AngularJS ng-map 将视图位置设置为矩形坐标
AngularJS ng-map set view position as rectangle coordinates
你知道我怎么能 ng-map 指令设置 ng-map 视图的位置而不是 center="[40.74, -74.18]", 而是矩形 - 我有 4 个值的地图视图的角值[东西南北]?
现在我有类似的东西了:
<ng-map zoom="11" center="[40.74, -74.18]" class="csiMap" default-style="false"></ng-map>
但我想要矩形,而不是中心
您好
里松
fitBounds
function 用于设置视口以包含给定的边界,下面演示了如何将其与 ng-map
库一起使用。
例子
angular.module('mapApp', ['ngMap'])
.controller('mapController', function ($scope, NgMap) {
NgMap.getMap().then(function (map) {
$scope.map = map;
$scope.bounds = [47.0, 30.0, -80.0, -110.0];
var southWest = new google.maps.LatLng($scope.bounds[1], $scope.bounds[3]);
var northEast = new google.maps.LatLng($scope.bounds[0], $scope.bounds[2]);
var bounds = new google.maps.LatLngBounds(southWest, northEast);
map.fitBounds(bounds);
});
});
<script src="https://maps.google.com/maps/api/js"></script>
<script src="https://code.angularjs.org/1.3.15/angular.js"></script>
<script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>
<div ng-app="mapApp" ng-controller="mapController">
<ng-map zoom="4">
</ng-map>
</div>
你知道我怎么能 ng-map 指令设置 ng-map 视图的位置而不是 center="[40.74, -74.18]", 而是矩形 - 我有 4 个值的地图视图的角值[东西南北]?
现在我有类似的东西了:
<ng-map zoom="11" center="[40.74, -74.18]" class="csiMap" default-style="false"></ng-map>
但我想要矩形,而不是中心
您好 里松
fitBounds
function 用于设置视口以包含给定的边界,下面演示了如何将其与 ng-map
库一起使用。
例子
angular.module('mapApp', ['ngMap'])
.controller('mapController', function ($scope, NgMap) {
NgMap.getMap().then(function (map) {
$scope.map = map;
$scope.bounds = [47.0, 30.0, -80.0, -110.0];
var southWest = new google.maps.LatLng($scope.bounds[1], $scope.bounds[3]);
var northEast = new google.maps.LatLng($scope.bounds[0], $scope.bounds[2]);
var bounds = new google.maps.LatLngBounds(southWest, northEast);
map.fitBounds(bounds);
});
});
<script src="https://maps.google.com/maps/api/js"></script>
<script src="https://code.angularjs.org/1.3.15/angular.js"></script>
<script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>
<div ng-app="mapApp" ng-controller="mapController">
<ng-map zoom="4">
</ng-map>
</div>