[英]angular-leaflet-directive custom message html with angular directives in marker popup. How to?
[英]Angular-leaflet-directive Custom HTML popup
我正在尝试使用angular-leaflet-directive创建自定义弹出窗口。 我正在从leaflet.draw on:create事件打开弹出窗口。 这里:
map.on('draw:created', function(e) {
layer = e.layer;
drawnItems.addLayer(layer);
var newComment = "Enter Comment";
var newID = "ID";
var newGeoJsonFeat = layer.toGeoJSON();
newGeoJsonFeat.properties = {"comment":newComment, "id":newID};
console.log(newGeoJsonFeat);
onEachFeature(newGeoJsonFeat,layer);
layer.openPopup();
});
然后我使用@blackjid的逻辑,如下所示: https : //github.com/tombatossals/angular-leaflet-directive/issues/238绑定自定义弹出窗口
function onEachFeature(feature, layer) {
// Create get the view template
var popupContent = '<div ng-include="\'partials/popup_newfeat.html\'"></div>';
console.log("assigning popup");
// Bind the popup
// HACK: I have added the stream in the popup options
layer.bindPopup(popupContent,{
closeButton: false,
maxHeight: 300,
feature: feature
});
};
$scope.$on('leafletDirectiveMap.popupopen', function(event, leafletEvent){
// Create the popup view when is opened
var feature = leafletEvent.leafletEvent.popup.options.feature;
var newScope = $scope.$new();
newScope.stream = feature;
$compile(leafletEvent.leafletEvent.popup._contentNode)(newScope);
});
长话短说,除了弹出容器的大小无法正确调整以适应新内容之外,其他所有内容都可以正常工作。 高度似乎正确,但宽度已关闭。
我尝试使用:
.leaflet-popup-content {
width:auto !important;
}
这可能就足够了,但是由于某种原因,这会导致弹出锚点移动到弹出窗口的左下角。 单击地图顶部附近时,AutoPan也会损坏。
有谁知道我可以在哪里以及如何触发popup.update()? 我认为这就是需要发生的事情,但是我不知道在哪里实现。 我试过在layer.openPopup()之后调用它,如下所示:
onEachFeature(newGeoJsonFeat,layer);
layer.openPopup();
layer.getPopup().update();
});
但这似乎无济于事。 任何帮助是极大的赞赏!
您需要使用“ leafletEvent”。 尝试这个:
myApp.controller('YourController', ['$scope', 'leafletEvent', function($scope) {
// after all your crazy custom popup stuff ...
leafletData.getMap().then(function(map) {
layer.getPopup().update();
});
}]);
我最终将图像宽度存储在GeoJson的属性中,然后在bindPopup函数中将minWidth设置为该值。
layer.bindPopup(popupContent,{
closeButton: true,
closeOnClick: false,
minWidth: feature.properties.width,
autoPanPadding: L.point(20,20),
keepInView: false,
feature: feature
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.