對於自己,我解決了這樣的問題 - 添加和顯示的彈出式窗口在必要時不使用的標準機制的角度(爲指定消息標記)。 您當然可以在加載數據時立即初始化彈出消息,但在我的項目中更容易實現按需。
//popup's store
$scope.popups = {};
$scope._setViewMarker = function(pId, showPopup){
var wp = $scope.waypoints;
wp[pId].icon.markerColor = 'red';
//set unselected markers color
for (var i in wp)
if(i != pId){
wp[i].icon.markerColor = 'blue';
};
// close other popups
for (var i in $scope.popups)
if(i != pId)
$scope.map.closePopup($scope.popups[i]);
// show or create poupap
if(showPopup)
if($scope.popups[pId]){
if(!$scope.popups[pId]._isOpen)
$scope.map.openPopup($scope.popups[pId]);
} else {
var ind = $scope.points.map(function(e) { return e._id; }).indexOf(pId);
var c = angular.element('<popup point="points['+ind+']" note-click="showDetailPoint(points['+ind+'])"></popup>');
var linkFn = $compile(c);
var element = linkFn($scope);
$scope.popups[pId] = L.popup({offset:[0, -30]}).setLatLng([wp[pId].lat, wp[pId].lng]).setContent(element[0]).openOn($scope.map);
$scope.popups[pId].pointId = pId;
};
};
$scope.$on('leafletDirectiveMarker.viewMap.click', function(e, args){
$scope._setViewMarker(args.modelName, true);
});
你可以做小提琴嗎? – cl3m
即使在http://tombatossals.github.io/angular-leaflet-directive/examples/0000-viewer.html#/markers/icons-example –
示例中,也可以觀察到這一點如果執行e.preventDefault() ; $ scope.selectedPoint之前? – kozer