我正在使用传单+传单指令,昨晚我注意到,如果我向左或向右移动太远,它会创建一个新的地图实例,它不包含我的geojson标记。
这是已知的问题还是我错过了配置我的代码?(在网上找不到任何问题)
这张专辑很难解释,所以我制作了一张专辑:
有人知道为什么会发生这种情况和/或如何解决吗?
这里还值得注意的是,如果我向左移动,并输入“实例3、4或5”(等等……)我将无法看到我的标记,直到我回到“实例1”。
下面是我的相关HTML和Controller代码:
<div class="main" ng-controller="GeoJSONCenterController">
<div class="container-fluid" id="map-canvas">
<leaflet markers="markers" center="mapCenter" defaults="defaults" geojson="geojson"></leaflet>
</div>
</div>控制器代码:
app.controller("GeoJSONCenterController", [ '$scope', '$http', '$filter', 'leafletData', 'iconService', function($scope, $http, $filter, leafletData, iconService ) {
$scope.mapCenter = {
lat: 41.152194,
lng: 6.855469,
zoom: 3,
};
$scope.defaults = {
attribution: "",
minZoom: 3,
maxZoom: 18
};
$scope.icons = iconService.local_icons;
// Get the geojson data from the USGS
$http.get("https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson").success(function(data, status) {
addGeoJsonLayerWithClustering(data);
});
function addGeoJsonLayerWithClustering(data) {
var markers = L.markerClusterGroup();
var geoJsonLayer = L.geoJson(data, {
pointToLayer: function(feature, latlng) {
marker = new L.marker(latlng, {icon: L.icon($scope.icons.quake_icon)});
return marker;
},
onEachFeature: function (feature, layer) {
var date = $filter('date')(feature.properties.time, "short");
var popupContent = "<p><span class=" + "event-type" + ">" + feature.properties.type + ":</span> " + "<a href=" + feature.properties.url + " target=" + "_blank" + ">" + feature.properties.title + "</a>" + "<br><span class=" + "event-time" + "> Time: </span>" + date + "</span> " + "</p>";
layer.bindPopup(popupContent);
}
});
markers.addLayer(geoJsonLayer);
leafletData.getMap().then(function(map) {
map.addLayer(markers);
//map.fitBounds(markers.getBounds());
});
}
} ]);发布于 2017-08-18 23:16:02
默认情况下,worldCopyJump设置为false。将其设置为true时,应在平移地图时移动标记。
见:https://github.com/tombatossals/angular-leaflet-directive/blob/master/doc/defaults-attribute.md和
https://stackoverflow.com/questions/43823674
复制相似问题