gpt4 book ai didi

javascript - Angular 传单标记点击

转载 作者:行者123 更新时间:2023-12-03 11:36:20 24 4
gpt4 key购买 nike

我使用带 Angular 传单,并希望在消息弹出窗口中创建一个可单击的按钮。我知道我必须编译 HTML,但我无法让它在我的情况下工作,因为我没有找到带有 json 请求的示例。

非常欢迎任何提示!

$http.get(searchterm).then(function(articlesResponse) {

$scope.geonamesorte = articlesResponse.data;

var meineMarker = {};

for ( var i = 0; i < $scope.geonamesorte.length; i++) {
var ortObjektausListe = $scope.geonamesorte[i];

var myobjectname = ortObjektausListe.name.replace(/[^a-zA-Z0-9]/g,'_');
ortlat = parseFloat(ortObjektausListe.lat);
ortlng = parseFloat(ortObjektausListe.lng);

meineMarker[myobjectname+i] = {
lat: ortlat,
lng: ortlng,
message: "<span><a href='' ng-click='dosomething()''>info</a></span>",
focus: false,
draggable: false
};

}

// Marker on map
angular.extend($scope, {
markers: meineMarker,
defaults:{
tileLayer:"http://tile.stamen.com/toner-lite/{z}/{x}/{y}.png"
}
});

});

最佳答案

好的,在这里找到了解决方案:angular-leaflet-directive custom message html with angular directives in marker popup. How to?

但是稍微修改了一下:

    var myobjectname = 'meinort';

var meineMarker = {};
meineMarker[myobjectname] = {
lat: 0,
lng: 0,
name: 'testname',
message: "<span><a href='' ng-click='dosomething()'>info</a></span>",
focus: false,
draggable: false
};
<小时/>
  $scope.$on('leafletDirectiveMarker.click', function(e, args) {
// Args will contain the marker name and other relevant information
console.log(args);
var markerName = args.leafletEvent.target.options.name; //has to be set above
var $container = $(args.leafletEvent.target._popup._container).find('.leaflet-popup- content');
$container.empty();
var html = "<p> I am "+markerName +" " + args.leafletEvent.target._popup._content + "</p>",
linkFunction = $compile(angular.element(html)),
linkedDOM = linkFunction($scope);
$container.append(linkedDOM);
});

关于javascript - Angular 传单标记点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26493304/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com