Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 传单.js setView()&;map.on(“zoomend”)循环调用_Angularjs_Leaflet - Fatal编程技术网

Angularjs 传单.js setView()&;map.on(“zoomend”)循环调用

Angularjs 传单.js setView()&;map.on(“zoomend”)循环调用,angularjs,leaflet,Angularjs,Leaflet,我使用angularjs和传单.js 在我的控制器中,我在传单地图缩放上设置了一个侦听器: map.on("zoomend", function () { refreshData(...); // use the zoom & bound to get data. }); refreshData()根据许多条件(面)刷新地图中显示的标记,并使用setView()重新调整地图。(refreshData()也可以由其他函数调用) 因此,当调用refreshData时,我想禁用map

我使用angularjs和传单.js

在我的控制器中,我在传单地图缩放上设置了一个侦听器:

map.on("zoomend", function () {
    refreshData(...); // use the zoom & bound to get data.
});
refreshData()根据许多条件(面)刷新地图中显示的标记,并使用setView()重新调整地图。(refreshData()也可以由其他函数调用)

因此,当调用refreshData时,我想禁用map.on(“zoomend”)侦听器,因为它会进行循环调用


如何做到这一点?

我将使用一个标志变量

map.on("zoomend", refreshData);

var refreshData = function(){
    map.off("zoomend");
    // lot of thinks...
    map.setView(new L.LatLng(lat,lon),zoomlevel);
    map.on("zoomend", refreshData);
}

感谢@pk。我想知道答案。 我必须添加一个超时,使其正常工作,因为map.on(“zoomend”,refreshData);在调用map.setView(新的L.LatLng(lat,lon),zoomlevel)之后调用;他们需要一些时间来完成:

var refreshData = function(){
    map.off("zoomend");
    // lot of thinks...
    map.setView(new L.LatLng(lat,lon),zoomlevel);
    $timeout(function () {
        map.on("zoomend", refreshData);
    },3000);
}
最好的方法是在setView上回调,但我找不到这样做的方法:

var refreshData = function(){
    map.off("zoomend");
    // lot of thinks...
    map.setView(
        new L.LatLng(latlon["lat"], latlon["lon"]),
        GeographieService.getZoomFromLocalisationtype("continents"), 
        {'reset' : true }
    ).then(function (data) {
        map.on("zoomend", refreshData);
    });
}

有什么想法吗?

谢谢你的帮助。这对我来说不起作用,因为我需要在缩放时调用refreshdata。我尝试了这样做,但没有起作用:var refreshdata=function(){map.on(“zoomend”,function(){});map.setView(new L.LatLng(lat,lon),zoomlevel);…}谢谢我从3小时以来一直在搜索。map.off()是我需要的
var refreshData = function(){
    map.off("zoomend");
    // lot of thinks...
    map.setView(
        new L.LatLng(latlon["lat"], latlon["lon"]),
        GeographieService.getZoomFromLocalisationtype("continents"), 
        {'reset' : true }
    ).then(function (data) {
        map.on("zoomend", refreshData);
    });
}