从 geoJson 中提取 feed 级元数据以用作 Leaflet 消息框

Extracting feed level metadata from geoJson to use as Leaflet message box

我有一张地图通过 geoJson 提要显示数据 - 例如http://catchingtherain.com/iwm/index.php#lat=51.56981465604131&lng=-1.7135238647460938&zoom=12

该提要基于 bbox,但将服务器端限制为 200 个结果(我可以完全控制 geoJson,因为它只是一个转换 solr 响应的简单 php 脚本)

当有超过 200 个可用结果时,我想在传单地图上显示一条消息,例如"Displaying 200 of 437 results. Please zoom in to see the full results"。我可以通过 geoJson 响应中的一些顶级元数据将这些计数提供给 Leaflet,例如

{
    type: "FeatureCollection",
    metadata: {
        count: 200,
        totalCount: 427
    },
    features: [ ...

我的问题是,如何在

附近的 Leaflet 代码中提取这两个值
iwmMemorials = L.geoJson(null, {
    pointToLayer: function (feature, latlng) {
    ...

提要示例 - http://catchingtherain.com/iwm/data/iwm_memorials.php?bbox=-7.657470703124999,51.3546312303602,-0.472412109375,52.318553202553275

在传单之外进行。我看到你有一个看起来像这样的函数:

$.getJSON(url, function (data) {
    iwmMemorials.clearLayers();
    iwmMemorials.addData(data);
    map.addLayer(iwmMemorials);
    if (refresh != 'true') {
      map.fitBounds(iwmMemorials.getBounds(), {paddingTopLeft: [0,15], paddingBottomRight: [80,0]});
      bbox = map.getBounds().toBBoxString();
      console.info('IWM memorials bounds: '+bbox);
    }
});

只需添加一行:

if (data.features.length > 200) { alert('Too much stuff'); }