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;
feature.properties.type
is obviously numeric and so testing for string values"1"
and"2"
does not work. You should use numeric values incase
statements.