Leaflet正在加载部分图块。以下是截图:
下面是我的代码,我尝试使用panTO()函数将标记置于中心位置:
$scope.plotMap = function(lat, lng) {
var latlng = new L.LatLng(lat, lng);
$scope.map = new L.Map('detailsmap', {
center: latlng,
zoom: 3}
);
var center = $scope.map.project(latlng);
center = new L.point(center.x - 150, center.y - 100);
var target = $scope.map.unproject(center);
$scope. map.panTo(target);
L.tileLayer(
'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
{
attribution: '© <a href="http://openstreetmap' +
'.org">OpenStreetMap</a> contributors',
}
).addTo($scope.map);
L.marker(latlng, {icon: new L.Icon.Default()}).addTo(
$scope.map);
};
答案 0 :(得分:2)
调用invalidateSize()函数解决了这个问题。以下是代码段:
$scope.plotMap = function(lat, lng) {
var latlng = new L.LatLng(lat, lng);
$scope.map = new L.Map('detailsmap', {
center: latlng,
zoom: 3}
);
var center = $scope.map.project(latlng);
center = new L.point(center.x - 150, center.y - 100);
var target = $scope.map.unproject(center);
$scope. map.panTo(target);
L.tileLayer(
'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
{
attribution: '© <a href="http://openstreetmap' +
'.org">OpenStreetMap</a> contributors',
}
).addTo($scope.map);
L.marker(latlng, {icon: new L.Icon.Default()}).addTo(
$scope.map);
};
$scope.dispMap = function() {
$scope.plotMap();
$scope.map.invalidateSize();
};