0
votes

I have a map displaying data through a geoJson feed - e.g. http://catchingtherain.com/iwm/index.php#lat=51.56981465604131&lng=-1.7135238647460938&zoom=12

The feed is based on a bbox but limited server-side to 200 results (I have complete control over the geoJson as it's just a simple php script that transforms a solr response)

I want to display a message on a leaflet map when there are more than 200 results available e.g. "Displaying 200 of 437 results. Please zoom in to see the full results". I can provide these counts to Leaflet through some top-level metadata in the geoJson response, such as

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

My question is, how can I extract those two values in my Leaflet code, somewhere near

iwmMemorials = L.geoJson(null, {
    pointToLayer: function (feature, latlng) {
    ...

Sample feed - http://catchingtherain.com/iwm/data/iwm_memorials.php?bbox=-7.657470703124999,51.3546312303602,-0.472412109375,52.318553202553275

1

1 Answers

1
votes

Do it outside of Leaflet. I see you have a function that looks like:

$.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);
    }
});

Simply add a line like:

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