Angularjs 动态更改“角度”中的传单贴图边界?
我用的是有角传单。我有一个菜单,用户点击一个选项。每次用户单击某个选项时,地图都会更新为两个新标记,并且应调整边界,以便这些标记都可见。标记会更新,但边界的工作方式似乎有所不同。用户第一次单击某个对象时,边界会更新,但此后不会每次更新。这是每次用户选择选项时调用的代码:Angularjs 动态更改“角度”中的传单贴图边界?,angularjs,angularjs-directive,leaflet,angular-leaflet-directive,Angularjs,Angularjs Directive,Leaflet,Angular Leaflet Directive,我用的是有角传单。我有一个菜单,用户点击一个选项。每次用户单击某个选项时,地图都会更新为两个新标记,并且应调整边界,以便这些标记都可见。标记会更新,但边界的工作方式似乎有所不同。用户第一次单击某个对象时,边界会更新,但此后不会每次更新。这是每次用户选择选项时调用的代码: var updateMap = function() { setDirections(); $scope.bounds = leafletBoundsHelpers.createBoun
var updateMap = function() {
setDirections();
$scope.bounds = leafletBoundsHelpers.createBoundsFromArray([
[$scope.thisPractice.end.k, $scope.thisPractice.end.D],
[$scope.thisPractice.start.k, $scope.thisPractice.start.D]
]);
$scope.markers = {
end: {
title: "Destination",
lat: $scope.thisPractice.end.k,
lng: $scope.thisPractice.end.D,
focus: true,
icon: local_icons.markerRed
},
start: {
title: "Start",
lat: $scope.thisPractice.start.k,
lng: $scope.thisPractice.start.D,
}
}
}
这是我的地图初始化代码:
// Initialize the map
angular.extend($scope, {
center: {},
bounds: {},
paths: {},
markers: {},
scrollWheelZoom: false,
layers: {
baselayers: {
googleRoadmap: {
name: 'Google Streets',
layerType: 'ROADMAP',
type: 'google'
}
}
}
});
这是我的地图出现的HTML:
<div id="map_canvas">
<leaflet id="leaflet_map" bounds="bounds" center="center" markers="markers" paths="paths" height="300px" width="100%" layers="layers"></leaflet>
</div>
如果angular指令以相同的方式实现fitbounds,那就太好了。您是否尝试过手动调用map.fitbounds()方法?还可以尝试删除中心属性。删除中心会引发错误,因为边界显然需要中心属性(即使为空)才能工作。fitBounds似乎确实解决了我的问题,这很好,但我希望我能在指令范围内完成这一切…@Pancakes你找到解决方案了吗?我有完全相同的问题。@distante是的,检查我在问题底部的编辑。传单库中有一个名为fitBounds()的函数,用于执行此任务。
var bounds = L.latLngBounds([$scope.thisPractice.end.k, $scope.thisPractice.end.D], [$scope.thisPractice.start.k, $scope.thisPractice.start.D])
leafletData.getMap().then(function(map) {
map.fitBounds(bounds);
});