0

I'm succeeding in showing a marker:

var popup = new L.Popup();   

var wfstPoly = new L.WFS({
    url: 'http://localhost:8080/geoserver/ows',
    typeNS: 'worldmap',
    typeName: 'tracks.debra.steps',
    crs: L.CRS.EPSG4326,
    geometryField: 'geom',
    forceMulti: true,
},

         new L.Format.GeoJSON({
         pointToLayer: function(feature, latlng) {
            return L.marker(latlng, {
icon: L.ExtraMarkers.icon({
icon: 'fa-bed',
markerColor: 'blue',
//spin: true
prefix:'fa',
    shape: 'circle'
})})}
         
         
        })
).addTo(map);

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

but not on trying to sort markers by the "type" attribute. The icons are not showing..

var popup = new L.Popup();   

var wfstPoly = new L.WFS({
    url: 'http://localhost:8080/geoserver/ows',
    typeNS: 'worldmap',
    typeName: 'tracks.debra.steps',
    crs: L.CRS.EPSG4326,
    geometryField: 'geom',
    forceMulti: true,
},

         new L.Format.GeoJSON({
         pointToLayer: function(feature, latlng) {
         switch (feature.properties.type) {
         case '1': swix = L.marker(latlng,{icon: L.ExtraMarkers.icon({icon: 'fa-graduation-cap', markerColor: 'orange', shape: 'circle', prefix: 'fa'})}); return swix;
         case '2': swiy = L.marker(latlng,{icon: L.ExtraMarkers.icon({icon: 'fa-graduation-cap', markerColor: 'green', shape: 'circle', prefix: 'fa'})}); return swiy;

        }} //closes function and switch      
        }) //closes newfo

).addTo(map);

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

I then removed the "function" after pointtoLayer and introduced a default behaviour for all other contents of the type column :

       new L.Format.GeoJSON({
         pointToLayer(feature, latlng) {
         switch (feature.properties.type) {
         case "1": swix = L.marker(latlng,{icon: L.ExtraMarkers.icon({icon: 'fa-graduation-cap', markerColor: 'orange', shape: 'circle', prefix: 'fa'})}); return swix;
         case "2": swiy = L.marker(latlng,{icon: L.ExtraMarkers.icon({icon: 'fa-graduation-cap', markerColor: 'green', shape: 'circle', prefix: 'fa'})}); return swiy;
 default: swiz = L.marker(latlng,{icon: L.ExtraMarkers.icon({icon: 'fa-graduation-cap', markerColor: 'black', shape: 'circle', prefix: 'fa'})}); return swiz;

and all things turned to black. enter image description here

Data:enter image description here

4
  • Any errors in the browser debugger console?
    – TomazicM
    Jun 21 at 16:21
  • @TomazicM nothing except a strange *********Erreur d’analyse XML : mal formé Emplacement : mappingforyou.eu/italia/#9/45.6800/7.6379/base Numéro de ligne 1, Colonne 1************* I then removed the "function" to a simpler pointtolayer, as I newly stated in my question, added a "default" switch case, and all markers turned black according to default (question edited). I'm showing the "type" column screenshot with all data inside , of "varchar" kind
    – Vincent Dc
    Jun 21 at 16:38
  • Your property feature.properties.type is obviously numeric and so testing for string values "1" and "2" does not work. You should use numeric values in case statements.
    – TomazicM
    Jun 21 at 17:26
  • @TomazicM thanks. I tried again changing the column type in Qgis, it wasn't a varchar and obviously it wasn't readable, now it works.
    – Vincent Dc
    Jun 24 at 9:01

0

Browse other questions tagged or ask your own question.