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

1 Answer 1

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);
}
2
  • Sounds good. But unfortunately my entire layer disappears when I add these lines.
    – darkspider
    Commented Jun 23, 2015 at 17:19
  • any error in the console?
    – toms
    Commented Jun 23, 2015 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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