1

I'm fairly new to Leaflet and just managed to use Leaflet marker-cluster with a JSONP WFS which provides my data from Geoserver. Now I would like to have a popup for my markers by mouse click. But I do not know where to insert the .bindpopup onEachFeature. Maybe I have to rewrite my code, but nothing what I've tried works.

At the end I will have more than 100,000 markers. Any ideas for a good performance?

var markers = L.markerClusterGroup();
var geoJsonLayer = new L.GeoJSON();

var geoJsonUrl ='localhost:8080/geoserver/test/ows'; 
var defaultParameters = {
    service: 'WFS',
    version: '1.0.0',
    request: 'GetFeature',
    typeName: 'test:bh',
    maxFeatures: 120000,
    outputFormat: 'text/javascript'
    };

var parameters = L.Util.extend(defaultParameters);
console.log(geoJsonUrl + L.Util.getParamString(parameters));

$.ajax({
    url: geoJsonUrl + L.Util.getParamString(parameters),
    dataType: 'jsonp',
    jsonpCallback: 'parseResponse',
    success: function (data) {          
        console.log(data);
        geoJsonLayer.addData(data);         
        markers.addLayer(geoJsonLayer);     
        map.addLayer(markers);
    }
});
0

you can add the geojson within the success callback

success: function(data) {
    var geoJsonLayer = L.geoJson(data, {
        onEachFeature: function(feature, layer) {
            feature.bindPopup('Hi!');
        } 
    });
    // the rest as before...
    markers.addLayer(geoJsonLayer);     
    map.addLayer(markers);
}
  • Sounds good. But unfortunately my entire layer disappears when I add these lines. – darkspider Jun 23 '15 at 17:19
  • any error in the console? – toms Jun 23 '15 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.