bounds
和maxBounds
性質可經由angular-leaflet-directive
分別使用maxBounds
和bounds
指令來設定,例如:
<leaflet markers="markers" maxbounds="boundsInfo" bounds="boundsInfo"></leaflet>
其中邊界應以下列格式來指定:
$scope.boundsInfo = {'northEast': {'lat': 40.774, 'lng': -74.125},'southWest': {'lat': 40.712, 'lng': -74.227}};
例
angular.module("demoapp", ["leaflet-directive"])
.controller("CustomizedMarkersController", ['$scope','leafletData', function ($scope, leafletData) {
$scope.boundsInfo = {'northEast': {'lat': 40.774, 'lng': -74.125},'southWest': {'lat': 40.712, 'lng': -74.227}};
$scope.markers = [];
leafletData.getMap().then(function (map) {
console.log(map.getBounds());
});
}]);
.angular-leaflet-map {
width: 640px;
height: 480px;
}
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script type="text/javascript" src="https://code.angularjs.org/1.2.2/angular.js"></script>
<script type="text/javascript" src="https://tombatossals.github.io/angular-leaflet-directive/dist/angular-leaflet-directive.js"></script>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<div ng-app="demoapp" ng-controller="CustomizedMarkersController">
<leaflet markers="markers" maxbounds="boundsInfo" bounds="boundsInfo" maxZoom="19" minZoom="10"></leaflet>
</div>
您的片段不能正常工作 – Manuel
是的,我同意。如果沒有在控制器中支持代碼,傳單指令將不起作用。我只是試圖說明我如何在生產中使用傳單指令。 –