I'm using leaflet + the leaflet directive and I noticed last night that if I pan too far to the left or right it creates a new instance of the map which doesn't contain my geojson markers.
Is this a known issue or did I miss configure my code? (Couldn't find any issues online)
This one is sort of hard to explain so I made an album:
Does anyone know why this happens and/or how to fix it?
Also noteworthy here is that if I pan further to the left, and enter "Instance 3, 4 or 5" (etc...) I won't be able to see my markers until I pan back to "Instance 1".
Here's my relevant HTML & Controller code:
<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>
Controller code:
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());
});
}
} ]);
By default worldCopyJump
is set to false
. Setting it to true
should move your markers when you pan the map.
see: https://github.com/tombatossals/angular-leaflet-directive/blob/master/doc/defaults-attribute.md and