Closed ghost closed 7 years ago
Nevermind, found the issue in my code.
I believe that is a known bug in ui-leaflet.
@zcsongor Honestly I don't remember for sure but I know it had something to do with switching from group to layer in addressPointsToMakers. Here's my code as it is now:
.directive('etMemberDensity', [function () {
return {
restrict: 'E',
templateUrl: 'app/portal/dashboardPanels/memberDensity/member-density.directive.html',
transclude: false,
bindToController: true,
controllerAs: 'ctrl',
controller: 'etMemberDensityController',
link: function (scope, element, attrs, controller) {
controller.initialize();
}
}
}])
.controller('etMemberDensityController', ['$timeout', 'leafletData', 'DashboardService', function ($timeout, leafletData, DashboardService) {
var ctrl = this;
// Properties
ctrl.mapData = {
watchOptions: {
markers: {
type: null,
individual: {
type: null
}
}
},
events: {
map: {
enable: ['moveend', 'popupopen'],
logic: 'emit'
},
marker: {
enable: [],
logic: 'emit'
}
},
layers: {
baselayers: {
osm: {
name: 'OpenStreetMap',
type: 'xyz',
url: 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
layerParams: {
showOnSelector: false
}
}
},
overlays: {
realworld: {
name: "Real world data",
type: "markercluster",
visible: true,
layerParams: {
showOnSelector: false
}
}
}
}
}
// Helpers
var addressPointsToMarkers = function (points) {
return points.map(function (ap) {
return {
layer: 'realworld',
lat: ap[0],
lng: ap[1]
};
});
};
var autoSetBounds = function (map) {
// Calculate and set the map bounds
leafletData.getMarkers().then(
function (markers) {
var bounds = null;
function getBoundsRecursive(obj) {
for (key in obj) {
if (obj[key].getLatLng) {
if (bounds) {
bounds.extend(obj[key].getLatLng());
} else {
bounds = L.latLngBounds(obj[key].getLatLng(), obj[key].getLatLng());
}
} else {
getBoundsRecursive(obj[key]);
}
}
};
getBoundsRecursive(markers);
map.fitBounds(bounds);
});
};
// Initialization
var initMap = function() {
leafletData.getMap().then(
function (map) {
map.attributionControl.setPrefix(false);
autoSetBounds(map);
});
};
ctrl.initialize = function () {
DashboardService.getMemberDensity().then(
function (results) {
leafletData.getDirectiveControls().then(function (controls) {
// Process after controls is actually populated
$timeout(function() {
// Create the markers from the received data
var markers = addressPointsToMarkers(results);
controls.markers.create(markers, ctrl.mapData.markers); // Performance hit appears to be here
ctrl.mapData.markers = markers;
// Setup the map
initMap();
});
});
});
};
}])
I have a ui-leaflet map with a couple markers on a page in my app. When I navigate away from the page and come back, the following error is shown in the console and the markers aren't drawn.
Here's the line in ui-leaflet.js
My ui-leaflet directive (used within custom directive)
My directive code
Any ideas what might be causing the error? If it helps, I'm using ui-router for site routing.