0

could you please help me on this ? It's not showing the Attribute in Bindpopup of a map in Leaflet with this Javascript: https://mappingforyou.eu/javascript/leaflet-wfst.src.js

 function onEachFeature(feature, layer) { 
     if (feature.properties && feature.properties.name) { 
       layer.bindPopup(feature.properties.name + '</br>' + feature.properties.name) ;
   } 
};

var wfstPoly = new L.WFST({
    url: 'https://mappingforyou.eu/geoserver/ows',
    typeNS: 'worldmap',
    typeName: 'tracks.raam.steps',
    crs: L.CRS.EPSG4326,
    geometryField: 'geom',
    forceMulti: true,
    schema: 'https://mappingforyou.eu/geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=opendata:sites',
    style: {
      color: 'blue',
      weight: 2
    },
        onEachFeature: onEachFeature                   
        } 
    }
    }).addTo(map);

Is it imaginable that L.WFST doesn't support Info popups (Bindpopup)? then, is it impossible to display them?

0

1 Answer 1

2

L.WFST layer fires a click event. Use that to create a popup. The code should look something like this:

var popup = new L.Popup();   

var wfstPoly = new L.WFST({
    url: 'https://mappingforyou.eu/geoserver/ows',
    typeNS: 'worldmap',
    typeName: 'tracks.raam.steps',
    crs: L.CRS.EPSG4326,
    geometryField: 'geom',
    forceMulti: true,
    schema: 'https://mappingforyou.eu/geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=opendata:sites',
    style: {
      color: 'blue',
      weight: 2
    }
}).addTo(map);

wfstPoly .on('click', function(e){
    if (e.layer.feature.properties && e.layer.feature.properties.name) { 
       popup
            .setLatLng(e.latlng)
           .setContent(e.layer.feature.properties.name + '</br>' + e.layer.feature.properties.name)
           .openOn(map);
     }
})

Take a look at this example.

Note: changed a bit

1
  • thank you for helping! It works. I'll just be removing some quotes in setcontent in your example for it to work
    – Vincent Dc
    Jun 20 at 12:17

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.