This is what I came up with when I check how many loaded objects the 4000 is indicated, which means that it loads everything outside the frame too ....
var map = new L.Map('map', {center: new L.LatLng(54.0000, -125.0000), zoom: 5});
var googleLayer = new L.Google('ROADMAP');
map.addLayer(googleLayer);
function BoundingBox(){
var bounds = map.getBounds().getSouthWest().lng + "," + map.getBounds().getSouthWest().lat + "," + map.getBounds().getNorthEast().lng + "," + map.getBounds().getNorthEast().lat;
return bounds;
}
wellmaxzoom = 8;
var geoJsonUrl ="http://localhost:8080/geoserver/cite/ows? service=WFS&version=1.0.0&request=GetFeature&typeName=cite:bc_well_data_wgs&maxFeatures=4000&outputFormat=application/json";
var geojsonLayerWells = new L.GeoJSON();
function loadGeoJson(data) {
console.log(data);
geojsonLayerWells.clearLayers();
geojsonLayerWells.addData(data);
};
$.ajax({
url: geoJsonUrl + "&bbox=" + BoundingBox(),
dataType : 'json',
jsonpCallback: 'loadGeoJson',
success: loadGeoJson,
});
map.on('moveend', function(){
if(map.getZoom() > wellmaxzoom){
map.addLayer(geojsonLayerWells);
}
console.log(map.getZoom());
console.log(BoundingBox());
});
source
share