2016-03-27 55 views
0

我试图用宣传单实时插件(https://github.com/perliedman/leaflet-realtime),他们说我们可以通过添加启动保留以前的更新文档中提到。如何保持以前的数据单张实时

var map = L.map('map'), 
    realtime = L.realtime({ 
     url: 'https://wanderdrone.appspot.com/', 
     crossOrigin: true, 
     type: 'json' 
    }, { 
     interval: 3 * 1000, start:false 
    }).addTo(map); 

任何人有更好的想法,如何做到这一点?

plnkr具有良好的演示:

http://plnkr.co/edit/NmtcUa?p=preview 

回答

0

如果设置start: false,自动更新将被禁用。这意味着你必须自己调用图层的update方法,提供你想要添加或更新的任何GeoJSON数据;您还可以使用remove方法删除添加的功能。如果您想使用服务器轮询以外的其他方法,则可以使用这些方法。

0

您可以使用我从plnkr复制,同时改变了一点点,因为L.realtime继承L.geoJson下面的代码。 L.geoJson有'layeradd'。

realtime.on('layeradd', function(e) { 
var coordPart = function(v, dirs) { 
     return dirs.charAt(v >= 0 ? 0 : 1) + 
      (Math.round(Math.abs(v) * 100)/100).toString(); 
    }, 
    popupContent = function(fId) { 
     var feature = e.features[fId], 
      c = feature.geometry.coordinates; 
     return 'Wander drone at ' + 
      coordPart(c[1], 'NS') + ', ' + coordPart(c[0], 'EW'); 
    }, 
    bindFeaturePopup = function(fId) { 
     realtime.getLayer(fId).bindPopup(popupContent(fId)); 
    }, 
    updateFeaturePopup = function(fId) { 
     realtime.getLayer(fId).getPopup().setContent(popupContent(fId)); 
    }; 

map.fitBounds(realtime.getBounds(), {maxZoom: 3}); 

Object.keys(e.enter).forEach(bindFeaturePopup); 
Object.keys(e.update).forEach(updateFeaturePopup); 
}); 
相关问题