Geolicious / qgis2leaf

A QGIS plugin to create a working leaflet based webmap from it
127 stars 30 forks source link

WFS layers duplicating feature data across popups #112

Closed tomchadwin closed 9 years ago

tomchadwin commented 10 years ago

Create a map with a WFS layer, and export it with the plugin - do not select "Encode to JSON". When I do this, all the popups contain the same data, duplicated from one feature, rather than each containing their own data.

Can anyone else replicate the problem?

riccardoklinger commented 10 years ago

the main problem is that all popups of one WFS lazer show the same content.

riccardoklinger commented 10 years ago

ATM it generates this outcome:

function pop_yorkshiredalesydnpamainairports(feature, layer) {
                                        var popupContent = '<table><tr><th scope="row">airports</th><td>' + Autolinker.link(String(feature.properties.airports)) + '</td></tr></table>';
                    layer.bindPopup(popupContent);

                }

            var yorkshiredalesydnpamainairportsURL='http://maps.nationalparks.gov.uk/geoserver/wfs?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=yorkshire_dales:ydnpa_main_airports&SRSNAME=EPSG:27700&outputFormat=text%2Fjavascript&format_options=callback%3AgetyorkshiredalesydnpamainairportsJson';
            yorkshiredalesydnpamainairportsURL=yorkshiredalesydnpamainairportsURL.replace(/SRSNAME\=EPSG\:\d+/, 'SRSNAME=EPSG:4326');
            var exp_yorkshiredalesydnpamainairportsJSON = L.geoJson(null, {
                                pointToLayer: function (feature, latlng) {  
                                return L.circleMarker(latlng, {
                                    radius: 4.0,
                                    fillColor: '#ed4488',
                                    color: '#000',
                                    weight: 1,
                                    opacity: 1.0,
                                    fillOpacity: 1.0
                                    })
                                }});
            layerOrder[layerOrder.length] = exp_yorkshiredalesydnpamainairportsJSON;
            var yorkshiredalesydnpamainairportsajax = $.ajax({
                    url : yorkshiredalesydnpamainairportsURL,
                    dataType : 'jsonp',
                    jsonpCallback : 'getyorkshiredalesydnpamainairportsJson',
                    contentType : 'application/json',
                    success : function (response) {
                        L.geoJson(response, {
                                onEachFeature : function (feature, layer) {
                                                        var popupContent = '<table><tr><th scope="row">airports</th><td>' + Autolinker.link(String(feature.properties.airports)) + '</td></tr></table>';
                    exp_yorkshiredalesydnpamainairportsJSON.bindPopup(popupContent);

                                    exp_yorkshiredalesydnpamainairportsJSON.addData(feature)
                                }
                            });
                        for (index = 0; index < layerOrder.length; index++) {
                            feature_group.removeLayer(layerOrder[index]);feature_group.addLayer(layerOrder[index]);
                        }
                    }
                });

                feature_group.addLayer(exp_yorkshiredalesydnpamainairportsJSON);
                layerOrder[layerOrder.length] = exp_yorkshiredalesydnpamainairportsJSON;
                for (index = 0; index < layerOrder.length; index++) {
                    feature_group.removeLayer(layerOrder[index]);feature_group.addLayer(layerOrder[index]);
                }

                        //add comment sign to hide this layer on the map in the initial view.
                        exp_yorkshiredalesydnpamainairportsJSON.addTo(map);
riccardoklinger commented 10 years ago

this should be:

            var yorkshiredalesydnpamainairportsURL='http://maps.nationalparks.gov.uk/geoserver/wfs?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=yorkshire_dales:ydnpa_main_airports&SRSNAME=EPSG:27700&outputFormat=text%2Fjavascript&format_options=callback%3AgetyorkshiredalesydnpamainairportsJson';
            yorkshiredalesydnpamainairportsURL=yorkshiredalesydnpamainairportsURL.replace(/SRSNAME\=EPSG\:\d+/, 'SRSNAME=EPSG:4326');
            var exp_yorkshiredalesydnpamainairportsJSON = null;
                var ajax = $.ajax({
    url : yorkshiredalesydnpamainairportsURL,
    dataType : 'jsonp',
    jsonpCallback : 'getyorkshiredalesydnpamainairportsJson',
    contentType : 'application/json',
    success : function (response) {

        exp_yorkshiredalesydnpamainairportsJSON = L.geoJson(response, {
            pointToLayer: function (feature, latlng) {  
                                return L.circleMarker(latlng, {
                                    radius: 4.0,
                                    fillColor: '#ed4488',
                                    color: '#000',
                                    weight: 1,
                                    opacity: 1.0,
                                    fillOpacity: 1.0
                                    })
                                },
            onEachFeature : function (feature, layer) {
                var popupContent = '<table><tr><th scope="row">airports</th><td>' + Autolinker.link(String(feature.properties.airports)) + '</td></tr></table>';
                layer.bindPopup(popupContent);
            }
        }).addTo(map);
        layerOrder[layerOrder.length] = exp_yorkshiredalesydnpamainairportsJSON;
    }
});

This works and create unique popoups but still throws an error and doesn't show layer control box in the upper right corner

riccardoklinger commented 10 years ago

instead of creating a null-variable by var exp_yorkshiredalesydnpamainairportsJSON = null; create an empty GeoJSON: var exp_yorkshiredalesydnpamainairportsJSON = L.geoJson(); This was the reason for the error with the Layercontrol.

riccardoklinger commented 10 years ago

one error remains with the above described solution: you can't switch off the layer.

riccardoklinger commented 9 years ago

this is don now, right @tomchadwin @mtravis

mtravis commented 9 years ago

I would say so. On 11 Nov 2014 09:26, "Riccardo Klinger" notifications@github.com wrote:

this is don now, right @tomchadwin https://github.com/tomchadwin @mtravis https://github.com/mtravis

— Reply to this email directly or view it on GitHub https://github.com/Geolicious/qgis2leaf/issues/112#issuecomment-62521942 .