I use this function to add an interactive layer to my leaflet application. It works great in most browsers, but fails due to time-out error on certain networks and browsers. The solution I think is to add a bounding box filter to this function. Could anybody tell me where to find the information or how to do this?
var rootUrl = 'http://map.kecoviewer.com/geoserver/ows';
var defaultParameters = {
service: 'WFS',
version: '1.1.0',
request: 'GetFeature',
typeName: 'cresh:datazones_popup_mini',
maxFeatures: 6505,
outputFormat: 'text/javascript',
format_options: 'callback: getJson',
srsName:'EPSG:4326'
};
var parameters = L.Util.extend(defaultParameters);
$.ajax({
jsonp : false,
url: rootUrl + L.Util.getParamString(parameters),
dataType: 'jsonp',
jsonpCallback: 'getJson',
success: handleJson
});
var group = new L.featureGroup().addTo(map);
var geojsonlayer;
var featureLayer = new L.GeoJSON();
var defaultStyle = {weight: 0,opacity: 0,fillOpacity: 0};
var highlightStyle = {color: '#f7f90e',weight: 3,opacity: 1,fillOpacity: 0};
var currentlayer;
function handleJson(data) {
geojsonlayer=L.geoJson(data, {
onEachFeature: function(feature, layer) {
layer.setStyle(defaultStyle);
(function(layer, properties) {
layer.on("click", function (e) {
if (currentlayer) currentlayer.setStyle(defaultStyle);
layer.setStyle(highlightStyle);
window.open("http:\/\/map.kecoviewer.com\/birtviewer\/run?__report=report\/datazone_story_ig.rptdesign&Datazone="+properties.dz,"story")
currentlayer = layer;
});
})(layer, feature.properties);
}
}).addTo(group);
}
function getJson(data) {
console.log("callback function fired");
}
window.open
? Besides, your code is quite messed up at many places. – ghybs Nov 5 '15 at 12:34data
into anL.geoJson
layer? In the first case, you would have to see what options your remote service offers. It looks like you use amaxFeatures
option, it does not help? In the second case, you would have to split yourdata
into smaller chunks and add them to yourL.geoJson
layer by interval. – ghybs Nov 5 '15 at 15:44map.getBounds()
, maybe with a little bit of padding. Once you have that latLngBounds, you could try thetoBBoxString()
as value for your "bbox" parameter. Then on map move end event re-send your request and replace your geoJson layer by the new data. – ghybs Nov 5 '15 at 17:08